This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a cloud-init script to deploy Sunbeam (aka Microstack) on multiple | |
# nodes using MAAS. | |
# | |
# WARNING: | |
# This cloud-init example uses pre-generated host ssh keys to make things easier on the administrator | |
# when working on differnet nodes across the cluster. | |
# !!!THEY ARE NOT REQUIRED!!! and can be removed. | |
# | |
# See: https://cloudinit.readthedocs.io/en/latest/reference/examples.html#configure-instance-s-ssh-keys | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################################# | |
### Display the IEC 60417-5009 power symbol (⏻) at the end of your Bash Primary | |
### Prompt String (PS1) when the host needs a reboot. Color changes from green | |
### to red, depending on how many hours the host has | |
### | |
### Ex. craigbender@hpz600:~ ⏻ | |
### | |
### PS1R - Red ⏻ - Host has needed a reboot for > 24 hours | |
### PS1Y - Yellow ⏻ - Host has needed a reboot for > 12 hours but < 24 hours | |
### PS1G - Green ⏻ - Host has needed a reboot < 12 hours |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare -ag SUPS=($(printf '\u2070 \u00b9 \u00b2 \u00b3 \u2074 \u2075 \u2076 \u2077 \u2078 \u2079 \u207f \u2071\n')) | |
declare -ag SUBS=($(printf '\u2080 \u00b9 \u00b2 \u00b3 \u2084 \u2085 \u2086 \u2087 \u2088 \u2089 \u2099 \u1D62\n')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install ethtool if needed | |
[[ $(command -v ethtool 2>/dev/null) ]] || { printf "\nInstalling ethtool. One moment...\n\n";sudo apt install ethtool -yqf; } | |
# Create an empty networkd dispatcher script with correct owner and permissions | |
sudo install -o0 -g0 -m0755 /dev/null /etc/networkd-dispatcher/routable.d/99-disable-eee.sh | |
cat <<'EOF' |sudo tee 1>/dev/null /etc/networkd-dispatcher/routable.d/99-disable-eee.sh | |
#!/bin/bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maas-debug() { | |
[[ -z ${1} || ${1,,} =~ '-h' ]] && { printf "\nUsage: ${FUNCNAME} <on|off> (-h,--help)\n\n" 1>&2;return 2; } | |
declare -ag DBG_FILES=($(sudo find 2>/dev/null /etc/maas /var/snap/maas/current/ -maxdepth 1 -type f -iname "r*d.conf")) | |
[[ ${#DBG_FILES[@]} -ge 2 ]] || { printf "\e[1;38;2;255;0;0mError\e[0m: Could not locate the regiond and rackd.conf files.\n\n" 1>&2;return 2; } | |
[[ ${1,,} = on && ${#DBG_FILES[@]} -ge 2 ]] && { printf "\nSetting debug mode to \e[1m on\e[0m\n" 1>&2;sudo sed -r -i '/^debug:/{h;s/:.*/: true/};${x;/^$/{s//debug: true/;H};x}' ${DBG_FILES[@]}; } | |
[[ ${1,,} = off && ${#DBG_FILES[@]} -ge 2 ]] && { printf "\nSetting debug mode to \e[1m off\e[0m\n" 1>&2;sudo sed -r -i '/^debug:/{h;s/:.*/: false/};${x;/^$/{s//debug: false/;H};x}' ${DBG_FILES[@]}; } | |
[[ ${#DBG_FILES[@]} -ge 2 && ${DBG_FILES[0]} =~ /var/snap/maas/current ]] && { printf "\nRunning \x60sudo snap restart maas\x60...\n" 1>&2;sudo snap restart maas 2>&1|sed -r 's/^/ /g'; } | |
[[ ${#DBG_FILES[@]} -ge 2 && ${DBG_FILES[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mtrv4() { | |
[[ -z ${1} || ${1} =~ -h ]] && { printf "Usage: ${FUNCNAME} <hostname|IP>\n" 1>&2;return 2; } | |
for i in $(ip -o -4 a|awk '{if ($2 != "lo") print $2}'|paste -sd' ');do mtr -4 -rw -c 5 -I ${i} ${1};done | |
};export -f mtrv4 | |
mtrv6() { | |
[[ -z ${1} || ${1} =~ -h ]] && { printf "Usage: ${FUNCNAME} <hostname|IP>\n" 1>&2;return 2; } | |
for i in $(ip -o -6 a|awk '{if ($2 != "lo") print $2}'|paste -sd' ');do mtr -6 -rw -c 5 -I ${i} ${1};done; | |
};export -f mtrv6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following are bash functions. Either source this file (i.e. source ~/.node-rename.sh) or copy and paste the stanza directly in your terminal | |
# If you're using normal postgresq | |
maas-rename-new-machines-prod-db() { | |
sudo -u postgres psql -F"|" --no-align -P pager=off -t maasdb -c "\ | |
SELECT sip.ip,node.hostname,node.system_id FROM maasserver_bmc bmc \ | |
LEFT OUTER JOIN maasserver_staticipaddress sip ON sip.id = bmc.ip_address_id \ | |
LEFT OUTER JOIN maasserver_node node ON bmc.id = node.bmc_id \ | |
WHERE bmc.ip_address_id IS NOT NULL and power_type LIKE 'ipmi%' ORDER BY sip.ip"|awk -F\| '{print $1"|"$3}'|\ | |
xargs -n1 -P0 bash -c 'IP=${0%%|*};ID=${0##*|};NEWNAME=$(printf "faux-node-%02d\n" ${IP##*.});maas '${MAAS_PROFILE}' machine update $ID hostname=$NEWNAME' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Side loading example | |
# The following will create N fake nodes whose | |
# hostnames will be "fnode-${POWER_DRIVER}${LAST_IP_OCTET} | |
# And MAC address will be made up on the fly. | |
# For this example, ipmi and manual power drivers are supported. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oscap-report() { | |
local REL=$(lsb_release -sr) SHOW=loc; | |
[[ $((${REL%%.*}%2)) && $((10#${REL##*.})) -eq 4 ]] && { true; } || { printf "\e[1;38;2;255;0;0mSorry\x21\e[0m OVAL Data is only available for LTS release\n\n";return 3; } | |
local OSCAP_REPORT="$HOME/oscap-eval-report__$(lsb_release -sd|awk '{gsub(/ /,"-");print tolower($0)}')-$(hostname -s).html" | |
OK() { printf "\e[74G\x20\e[0m[\x20\e[38;2;0;255;0mOK\e[0m\x20]\e[0m\n"; } | |
FAIL() { printf "\e[74G\e[0m\x20[\e[38;2;255;0;0mFAIL\e[0m]\n"; } | |
WARN() { printf "\e[74G\x20\e[0m[\e[38;2;255;200;0mWARN\e[0m]\n"; } | |
local -a PREREQS=(bzip2 html2text libopenscap8 w3m) | |
local -a PKGS=() | |
local OVAL_URL="https://security-metadata.canonical.com/oval/com.ubuntu.$(lsb_release -cs).usn.oval.xml.bz2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo -iu root psql -U postgres -h /var/snap/maas-test-db/common/postgres/sockets -d maasdb -c "ALTER ROLE maas WITH SUPERUSER" | |
sudo -iu root pg_dumpall -U maas -l maasdb -h /var/snap/maas-test-db/common/postgres/sockets -c|tee 1>/dev/null ~/dump.sql |