This file contains 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 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 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 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 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 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 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 |
This file contains 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
ip-fwd-status() { find /sys/class/net -maxdepth 1 -type l ! -iname "*lo*" -printf "%P\n"|sort -uV|xargs -I@ -P1 sudo sysctl [email protected]; };export -f ip-fwd-status |
This file contains 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 | |
[[ -f ~/script.cmds ]] || { printf "\nMissing $HOME/script.cmds. Exiting\n";exit 1; } | |
dprompt() { [[ $HOME = $(pwd) ]] && { local DIR='~'; } || { local DIR=$(pwd); };printf "\e[01;32m$USER@${HOSTNAME}\e[0m:\e[01;34m${DIR}\e[0m$ ";};export -f dprompt | |
clear | |
declare -ag DCMDS=() | |
export DCMD_CNT=${#DCMDS[@]} | |
while IFS= read -er C;do DCMDS+=("${C%;$*}");done < <(cat script.cmds) | |
export DCMD_CNT=${#DCMDS[@]} | |
for D in "${DCMDS[@]}";do dprompt;echo "${D}"|pv -qL 10;bash -c "${D}";done |
This file contains 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
export PNID_REGEX=$(curl -fksSL https://raw.githubusercontent.com/systemd/systemd/main/src/udev/udev-builtin-net_id.c|grep -oPa '(?<=prefix = \x22)[^\x22]+'|sort -uV|paste -sd'|'|sed -r 's,l\|ww,[lw],g;s,^|$,\x27') |