Skip to content

Instantly share code, notes, and snippets.

@smoser
Last active August 3, 2023 11:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoser/8a34b1713badb643dee3a25e5cf134b8 to your computer and use it in GitHub Desktop.
Save smoser/8a34b1713badb643dee3a25e5cf134b8 to your computer and use it in GitHub Desktop.
make-maas-proposed-images make images for maas with proposed enabled

Make Proposed MAAS Images

Just run this script to build maas images with proposed enabled.

Run as root to avoid all sudo prompts.

By default it builds images for all supported LTS and the development release.

For information on how to add this to MAAS see maas documentation

Related Info

  • Gist doc on enabling proposed during deployment.
#!/bin/bash
PUB_D="$HOME/proposed-streams"
GIT_D="_TEMP_D_/maas-images"
GIT_REPO="https://git.launchpad.net/maas-images"
GIT_BRANCH="master"
BUILD_OUTPUT_D=""
set -o pipefail
fail() { echo "$@"; exit 1; }
cleanup() {
[ -d "$TEMP_D" ] && rm -Rf "${TEMP_D}"
[ -d "$BUILD_OUTPUT_D" ] && rm -Rf "${BUILD_OUTPUT_D}"
}
vrun() { echo "$(date -R):" "$@" 1>&2; "$@"; }
TEMP_D=$(mktemp -d)
trap cleanup EXIT
GIT_D=$(echo "${GIT_D}" | sed "s|_TEMP_D_|$TEMP_D|")
PATH=$GIT_D/bin:$PATH
pkgs=""
command -v git >/dev/null 2>&1 || pkgs="${pkgs:+${pkgs} }git"
command -v ubuntu-distro-info >/dev/null 2>&1 ||
pkgs="${pkgs:+${pkgs} }distro-info"
if [ -n "$pkgs" ]; then
vrun sudo sh -c '
apt-get update --quiet &&
sudo apt-get install --assume-yes --no-install-recommends "$@"' \
-- $pkgs ||
fail "unable to install $pkgs"
fi
# get all supported lts, and latest devel.
# ubuntu-distro-info --supported --fullname shows:
# Ubuntu 16.04 LTS "Xenial Xerus"
# Ubuntu 17.04 "Zesty Zapus"
# ...
releases=$(
ubuntu-distro-info --supported --fullname |
awk '$0 ~ /LTS/ { gsub("\"", ""); printf("%s|", tolower($(NF-1))); }'
)
releases=${releases%|}
[ "${releases#*${devel}}" = "${releases}" ] ||
releases="${releases}|${devel}"
release_filter="release~($releases)"
if [ -e "$GIT_D" ]; then
( cd "$GIT_D" && vrun git pull ) ||
fail "failed to pull in $GIT_D"
else
vrun git clone "--branch=${GIT_BRANCH}" "${GIT_REPO}" "$GIT_D" ||
fail "failed to git clone lp:maas-images into $GIT_D"
fi
vrun "${GIT_D}/system-setup" || fail "failed running system-setup"
cd "${TEMP_D}"
BUILD_OUTPUT_D="$(dirname "$PUB_D")/$(basename "$PUB_D").${0##*/}.$$"
rm -Rf "${BUILD_OUTPUT_D}"
cmd=(
meph2-cloudimg-sync
-vvv
"--conf=${GIT_D}/conf/meph-v3.yaml"
--max=1
--target=force
--disable-di
--proposed
--arches=amd64
--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
"${BUILD_OUTPUT_D}"
"${release_filter}" )
vrun "${cmd[@]}" ||
fail "failed building images"
if [ -e "$PUB_D.old" ]; then
vrun rm -rf "${PUB_D}.old" ||
fail "failed cleaning out ${PUB_D}.old"
fi
mv "${PUB_D}" "${PUB_D}.old" ||
{ mv "$PUB_D.old" "$PUB_D"; fail "failed moving $PUB_D to $PUB_D.old"; }
mv "${BUILD_OUTPUT_D}" "${PUB_D}" || {
rm -Rf "${PUB_D}";
mv "${PUB_D}.old" "${PUB_D}";
fail "failed moving new dir ${BUILD_OUTPUT_D} into place at ${PUB_D}"
}
vrun rm -Rf "${PUB_D}.old"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment