Skip to content

Instantly share code, notes, and snippets.

View ThinGuy's full-sized avatar

craig bender ThinGuy

View GitHub Profile
@ThinGuy
ThinGuy / sudo-show.sh
Last active October 2, 2022 18:42
Illustrate sudo preserving the users's environment ($HOME is this case)
# Show value of $HOME when user does not preserve the environment
sudo bash -c 'echo $HOME'
# Show the value of $HOME when -E to preserve the sudo user's environment
sudo -E bash -c 'echo $HOME'
# Tip: If both are the same:
#
# - You ran this command directly as root (naughty!)
@ThinGuy
ThinGuy / sudo-env.sh
Last active October 20, 2022 23:39
Create bash arrays for the checked, removed, and preserved sudo environmental variables. Add to ~/.bash_rc
declare -ag SUDO_CHCK=($(sudo sudo -V|awk '/(safety|sanity):[\r]?$/,/remove:[\r]?$/{if (/^E|^Lo/) next;gsub(/\t|\r/,"");print}'|sort -uV))
declare -ag SUDO_REMV=($(sudo sudo -V|awk '/remove:[\r]?$/,/preserve:[\r]?$/{if (/^E|^Lo/) next;gsub(/\t|\r/,"");print}'|sort -uV))
declare -ag SUDO_KEEP=($(sudo sudo -V|awk '/preserve:[\r]?$/,/^Loc/{if (/^E|^Lo/) next;gsub(/\t|\r/,"");print}'|sort -uV))
@ThinGuy
ThinGuy / add-repo.sh
Last active October 20, 2022 23:41
Bash function to add a repo with new "signed-by" line in apt sources
add-repo() {
add-repo_usage() {
# Help Blue, Help Blue Bold, Help Blue Italic, Italic Text and Reset Text
local HB='\e[38;2;72;226;225m' HBB='\e[1;38;2;72;226;225m' HBI='\e[3;38;2;72;226;225m' IT='\e[3m' RT='\e[0m'
printf "\n\e[2G${HBB}${FUNCNAME%_*}${RT}: ${IT}Add a repo using the new \x22signed-by\x22 feature${RT}\n\n"
printf "\e[2G${HBB}Usage${RT}:\n\n"
printf "\e[5G${FUNCNAME%_*} [ options ]\n\n"
printf "\e[2G${HBB}Options${RT}:\n\n"
printf "\e[5G-n,--repo-name\e[22GRepo Name\n\n"
printf "\e[5G-u,--repo-url\e[22GRepo URL (in sources.list format)\n\n"
@ThinGuy
ThinGuy / ci-rerun.sh
Created September 25, 2022 20:56
Re-run cloud-init without reboot (run as root if UID 1000 did not get setup on Ubutnu)
#!/bin/bash
cloud-init clean --logs
cloud-init init --local
cloud-init init
cloud-init modules --mode=config
cloud-init modules --mode=final
@ThinGuy
ThinGuy / amt-check.sh
Created June 30, 2022 01:29
Check for AMT on NUC or other AMT-enabled PC
amt-check() {
local G=https://github.com/mjg59/mei-amt-check.git
if [[ ! -f /srv/$(basename ${G%.*})/mei-amt-check ]];then
sudo chown -R $(id -un 1000):$(id -gn 1000) /srv
git clone ${G} /srv/$(basename ${G%.*})
cd /srv/$(basename ${G%.*})
make
fi
[[ -x /srv/$(basename ${G%.*})/mei-amt-check ]] && { sudo /srv/$(basename ${G%.*})/mei-amt-check; }
};export -f amt-check
@ThinGuy
ThinGuy / lxd-maas-microcloud-2022.sh
Created June 29, 2022 19:26
Updated lxd-maas microcloud
#!/usr/bin/env bash
# vim: set et ts=2 sw=2 filetype=bash :
[[ $_ != $0 ]] || { printf "\n\e[2G\e[1mPlease source this script!\e[0m ( e.g. \"source ${BASH_SOURCE[0]}\" )\n\n"; sleep 1;exit; }
maas-microcloud-lxd() {
[[ -n ${FDEBUG} && ${FDEBUG} = true ]] && { set -x &>/dev/null; }
local DESC="${FUNCNAME}: Deploy a LXD Cluster via MAAS command line"
local CI_TZ='America/Los_Angeles'
local CI_LC='en_US.UTF-8'
local CI_TC=${CI_LC:3:2}
@ThinGuy
ThinGuy / get-lxd-migrate.sh
Created June 29, 2022 00:03
Download latest lxd-migrate
sudo wget -qO /usr/local/lxd-migrate --show-progress --progress=bar:force:noscroll $(curl -sSlL https://github.com/lxc/lxd/releases/latest|awk -F'"' '/href.*lxd-migrate/{print "https://github.com"$2}')
sudo chmod +x /usr/local/bin/lxd-migrate
@ThinGuy
ThinGuy / zfs-snapshots
Created June 24, 2022 22:56
Disable / Enable ZFS auto-snapshots
zfs-disable-snapshots() {
systemctl --user stop zsys-user-savestate.timer
systemctl --user disable zsys-user-savestate.timer
sudo mv /etc/apt/apt.conf.d/90_zsys_system_autosnapshot /etc/apt/apt.conf.d/90_zsys_system_autosnapshot.disabled
};export -f zfs-disable-snapshots
zfs-enable-snapshots() {
systemctl --user start zsys-user-savestate.timer
systemctl --user enable zsys-user-savestate.timer
@ThinGuy
ThinGuy / install-kasa.sh
Created June 24, 2022 22:49
Install python-kasa on Ubuntu
#!/bin/bash
declare -ag KASA_PKG_LIST=();
for i in python3.10-venv build-essential python3 python3-pip python3-poetry python3-cachecontrol python3-argcomplete python3-all-dev python3-wheel python3-setuptools python-all-dev python-setuptools python3.10-venv python3-virtualenv;do
[[ $(dpkg -l $i|awk '/'${i}'/{print $1}') = ii ]] && { true; } || { PKG_LIST+=("${i}"); };
done
[[ ${#KASA_PKG_LIST[@]} -ge 1 ]] && { sudo apt install ${KASA_PKG_LIST[@]} -yqf --auto-remove --purge -o Acquire::ForceIPv4=true; } || { true;printf "\n\nAll package dependencies already installed\x21\n\n"; }
python3 -m pip install --user --upgrade pip
python3 -m pip install --user virtualenv
python3 -m pip install --user python-kasa --pre
@ThinGuy
ThinGuy / mikrotik.beep.music.sh
Last active January 24, 2025 13:54
Add music to mikrotik routers
/system script add dont-require-permissions=no name="Super=Mario-Bros" owner=admin policy=read source=":beep frequency=660 length=100ms;\n:delay 150ms;\n:beep frequency=660 length=100ms;\n:delay 300ms;\n:beep frequency=660 length=100ms;\n:delay 300ms;\n:beep frequency=510 length=100ms;\n:delay 100ms;\n:beep frequency=660 length=100ms;\n:delay 300ms;\n:beep frequency=770 length=100ms;\n:delay 550ms;\n:beep frequency=380 length=100ms;"
/system script add dont-require-permissions=no name="Thunderstruck" owner=admin policy=read source=":local n11 63,66;\n:local n12 64,67;\n:local n21 71,69,68,69,68,66,68,64,66,63;\n:local n22 64,63;\n \n:local n11 (\$n11,\$n11);\n:local n12 (\$n12,\$n12);\n:local n1 (\$n11,\$n11,\$n12,\$n12);\n:local n2 (\$n21,\$n22,\$n22,\$n22);\n:local notes (\$n1,\$n1,\$n2,\$n2);\n \n:local ticks 2;\n:local speed 55ms;\n:local stacc 5ms;\n# Transposition \n:local transpose -48;\n# ============================== \n# Don't change this: \n:local frqtab 8372,8869,9397,9956,10548,11175,11839,12543