Created
March 20, 2024 03:30
-
-
Save ThinGuy/4a1f47cfa8760236c5db768d006f336c to your computer and use it in GitHub Desktop.
Updated MAAS debug image, adds password for the root user in case of a bad networking configuration that results in the node being deployed is unable to contact the MAAS server to get its metadata.
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-build-debug-image() { | |
local -a UBU_RELS=(bionic) | |
export IMG_PWD="Ubuntu1+" | |
# Create salted pw for images | |
printf "\e[2G - Salting the desired password of \x22${IMG_PWD}\x22 for use in debug-image\n" | |
export SALTED_PWD="$(echo 'Ubuntu1+'|mkpasswd --method=SHA-512 --rounds=4096 -s)" | |
# Dowload images | |
printf '%s\n' ${UBU_RELS[@]}|xargs -rn1 -P0 bash -c ' | |
IMG_URL=https://cloud-images.ubuntu.com/${0}/current/${0}-server-cloudimg-amd64-root.tar.xz; | |
printf "\e[2G - Fetching Ubuntu release ${0^} from ${IMG_URL}\n" | |
wget -qO ~/${IMG_URL##*/} --show-progress --inet4-only ${IMG_URL} | |
# Create directory for extraction | |
printf "\e[2G - Creating working directory for ${0} in ~/${0} \n" | |
mkdir -p ~/${0} | |
# Extract image | |
printf "\e[2G - Extracting ${0}\x27s squashfs to ~/${0} \n" | |
sudo tar -C ~/${0} -xpSf ~/${0}-server-cloudimg-amd64-root.tar.xz --numeric-owner --xattrs "--xattrs-include=*" | |
printf "\e[2G - Adding a password to the root user\x27s account\n" | |
sudo sed -i "s,^root:[^:]*,root:${SALTED_PWD}," ~/${0}/etc/shadow | |
printf "\e[2G - Allowing password-based authentication and root login with password over ssh\n" | |
sudo sed -r -i "s/^#?(PasswordAuthentication|PermitRootLogin)[^$]*/\1 yes/g" ~/${0}/etc/ssh/sshd_config | |
printf "\e[2G - Removing restrictions in root\x27s authorized_keys file\n" | |
sudo sed -r -i "s/^no-.*142\x22\x20//g" ~/${0}/root/.ssh/authorized_keys | |
printf "\e[2G - Re-squashing ${0}\x27s squashfs\n" | |
sudo mksquashfs ~/${0}/ ~/${0}-maas-debug.squashfs -xattrs -comp xz | |
ls -altr ~/${0}-maas-debug.squashfs | |
export NEW_SQUASHFS="~/${0}-maas-debug.squashfs" | |
printf "\e[2G - Finding existing ${0} image in MAAS\n" | |
export ORIG_SQUASHFS=$(find 2>/dev/null /var/snap/maas/common/maas/boot-resources/ -type f -regextype posix-extended -regex ".*/ga-[0-9]{2}.[0-9]{2}/${0}/stable/squashfs") | |
[[ -f ${ORIG_SQUASHFS} ]] && { printf "\e[2G - Moving existing ${0} image name from squashfs to sqaushfs.orig\n"; } | |
[[ -f ${ORIG_SQUASHFS} ]] && { sudo mv ${ORIG_SQUASHFS}{,.orig}; } | |
[[ -f ${NEW_SQUASHFS} ]] && { printf "\e[2G - Moving ${0}-maas-debug.squashfs to squashfs for ${0}\n"; } | |
[[ -f ${NEW_SQUASHFS} ]] && { sudo cp ${NEW_SQUASHFS} ${ORIG_SQUASHFS}; } | |
printf "\e[2G - Setting owner to root for squashfs for ${0}\n" | |
sudo chown root:root ${ORIG_SQUASHFS} | |
printf "\n\e[2G\e[1;32mImportant\e[0;1m: To move back non-debug image for ${0}, please run:\n" | |
echo mv $ORIG_SQUASHFS{.orig,};printf "\e[0m\n" | |
' | |
};export -f maas-build-debug-image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment