Skip to content

Instantly share code, notes, and snippets.

View ThinGuy's full-sized avatar

craig bender ThinGuy

View GitHub Profile
@ThinGuy
ThinGuy / maas-sunbeam-ci.yaml
Last active May 3, 2024 20:22
Automated Install of Project Sunbeam - Tested under MAAS 3.3.4 and 3.4.
# 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
#
@ThinGuy
ThinGuy / power-ps1.sh
Created May 5, 2023 22:16
Display a color-coded IEC 60417-5009 power symbol (⏻) in your Bash Primary Prompt String (PS1) when your host needs a reboot.
#############################################################################################
### 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
@ThinGuy
ThinGuy / supersub.sh
Last active April 29, 2023 19:44
Arrays for Super and Subscript numbers including i and n
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'))
@ThinGuy
ThinGuy / networkd-disable-eee.sh
Last active February 14, 2024 22:25
Disables Energy Efficient Ethernet (EEE) on all NICs that support it. For use with Netplan (via networkd-dispatcher)
#!/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
@ThinGuy
ThinGuy / maas-debug.sh
Created March 2, 2023 23:27
function to toggle on/off MAAS debug mode
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]
@ThinGuy
ThinGuy / mtr.sh
Last active February 11, 2024 02:24
Test all nics using mtr (my traceroute)
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
@ThinGuy
ThinGuy / node-rename.sh
Created December 3, 2022 01:31
Rename machines based on BMC Info
# 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'
@ThinGuy
ThinGuy / maas-fake-nodes.sh
Created December 3, 2022 01:10
Create fake nodes in MAAS
#!/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.
@ThinGuy
ThinGuy / oscap-report.sh
Last active November 4, 2022 15:54
Function to run OpenSCAP CVE Evaluation with options to view report in terminal
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"
@ThinGuy
ThinGuy / pg_dumpall_maas-test-db.sh
Created October 31, 2022 23:36
Run pg_dumpall against maas-test-db
#!/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