Skip to content

Instantly share code, notes, and snippets.

View ThinGuy's full-sized avatar

craig bender ThinGuy

View GitHub Profile
@ThinGuy
ThinGuy / msad-lxd.sh
Last active August 26, 2024 16:57
Script to create a SAMBA based Active Directory Controller in a LXD unprivileged container
#!/bin/bash
export UBUNTU_PRO_TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export DNS_DOMAIN="atx.orangebox.me"
export MSAD_DOMAIN="ORANGEBOX"
export DC_HOSTNAME="msadc"
export SSH_IMPORT_ID="lp:craig-bender, gh:thinguy"
export UBUNTU_REPO="us.archive.ubuntu.com"
export UBUNTU_RELEASE="lunar"
export MSADMIN_PW="Ubuntu1+"
@ThinGuy
ThinGuy / demo-msad.yaml
Last active February 11, 2024 02:22
Create a MSAD Controller using SAMBA in an unprivileged LXD container in about 100 seconds, Includes creating 70+ MSAD accounts.
config:
boot.autostart: "true"
security.nesting: "true"
security.privileged: "false"
user.network-config: |
version: 2
ethernets:
eth0:
dhcp4: false
dhcp6: false
@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.