Created
March 2, 2023 23:27
-
-
Save ThinGuy/d00ca0fbb760c1d5170a07ee7a442553 to your computer and use it in GitHub Desktop.
function to toggle on/off MAAS debug mode
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]} =~ /etc/maas ]] && { printf "\nRunning \x60sudo systemctl restart maas-regiond maas-rackd\x60...\n" 1>&2;sudo systemctl restart maas-regiond maas-rackd; } | |
[[ ${#DBG_FILES[@]} -ge 2 ]] && { echo;for D in ${DBG_FILES[@]};do echo;echo $(basename ${D});sudo cat ${D};echo;done; } | |
};export -f maas-debug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment