Last active
August 15, 2018 00:52
-
-
Save ThinGuy/75fef676fc0253af770b6bba6cf953d7 to your computer and use it in GitHub Desktop.
MAAS: Insert a new boot parameter into all existing tags' kernel_opts
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-insert-boot-param() { | |
local DESC="\e[1m${FUNCNAME}\e[0m: Insert a boot paramter into a specific, or all existing tags.\n" | |
maas-insert-boot-param_usage() { | |
printf "\n${DESC}\n" | |
printf "\e[1mUsage\e[0m: ${FUNCNAME%%_*} -p <param> [-t <tag>]\n\n" | |
printf "\e[1mOptions\e[0m:\n" | |
printf "\e[2G -p, --param \e[20GRequired: boot parameter to add\n" | |
printf "\e[20GEx: apparmor=0\n" | |
printf "\e[20GTip: Enclose multiple params in single quotes\n\n" | |
printf "\e[2G -t, --tag \e[20GOptional: Add only to a specific tag\n" | |
printf "\e[2G -h, --help\e[20GThis message\n\n" | |
printf "\n\e[1m\e[2GExample #1\e[0m: Add boot parameter of \"net.ifnames=0\" to an existing tag\n" | |
printf "\e[14Gcalled \"virtual\"\n" | |
printf "\e[14Gmaas-insert-boot-param \\ \n" | |
printf "\e[14G-t virtual -p net.ifnames=0 \n\n" | |
printf "\n\e[1m\e[2GExample #2\e[0m: Add boot parameters of:\n" | |
printf "\e[14G\"nodemodeset console=tty0 console=ttyS0,115200n8\" to all tags\n" | |
printf "\e[14Gmaas-insert-boot-param \\ \n" | |
printf "\e[14G-p 'nodemodeset console=tty0 console=ttyS0,115200n8' \n\n" | |
} | |
ARGS=$(getopt -o p:t:h --long param:,tag:,help -n ${FUNCNAME} -- "$@") | |
eval set -- "$ARGS" | |
while true ; do | |
case "$1" in | |
-p|--param) local PARAM="${2}";shift 2;; | |
-t|--tag) local TAG="${2}";shift 2;; | |
-d|--desc) printf "${DESC}";return 2;; | |
-h|--help) ${FUNCNAME}_usage;return;; | |
--) shift;break;; | |
esac | |
done | |
if [[ -n ${TAG} ]];then | |
maas ${MAAS_PROFILE} tag read ${TAG}|jq -r '"\(.name) '"'"'\(.kernel_opts)'"'"'"'|xargs -n2 -P0 bash -c '[[ "$1" =~ ".*'"${PARAM}"'.*" ]] && echo "Tag \"${0}\" already has \"'"${PARAM}"'\" in kernel_opts. Skipping." || maas admin tag update $0 kernel_opts="'"${PARAM}"' $1"' | |
else | |
maas ${MAAS_PROFILE} tags read|jq -r '.[]|"\(.name) '"'"'\(.kernel_opts)'"'"'"'|xargs -n2 -P0 bash -c '[[ "$1" =~ ".*'"${PARAM}"'.*" ]] && echo "Tag \"${0}\" already has \"'"${PARAM}"'\" in kernel_opts. Skipping." || maas admin tag update $0 kernel_opts="'"${PARAM}"' $1"' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment