From 1f4fda04dd7bb5463f239a8706386ed76aff9b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Wed, 12 Jun 2019 18:34:00 +0200 Subject: [PATCH] [util-iso.sh] add snap support --- lib/util-iso.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/lib/util-iso.sh b/lib/util-iso.sh index cd35959..8b5aa43 100644 --- a/lib/util-iso.sh +++ b/lib/util-iso.sh @@ -239,6 +239,65 @@ reset_pac_conf(){ -i "$1/etc/pacman.conf" } +# Snap support +# Adapted from: +# * https://blackboxsw.github.io/seed-snaps-using-maas.html +function seed_snaps() { + local SEED_DIR="/var/lib/snapd/seed" + local SEED_CHANNEL="${SEED_BRANCH}" + local SEED_SNAPS="${STRICT_SNAPS} ${CLASSIC_SNAPS}" + + if [ -n "${STRICT_SNAPS}" ] || [ -n "${CLASSIC_SNAPS}" ]; then + # Preseeded snaps should be downloaded from a versioned channel + rm -rfv "${SEED_DIR}" + mkdir -p "${SEED_DIR}/snaps" + mkdir -p "${SEED_DIR}/assertions" + + # Download the published snaps and their related assert files + # Runs inside the container + for SEED_SNAP in ${SEED_SNAPS}; do + if [ "${SEED_SNAP}" == "core" ] || [ "${SEED_SNAP}" == "core16" ] || [ "${SEED_SNAP}" == "core18" ]; then + snap download --channel=stable "${SEED_SNAP}" + else + snap download --channel="${SEED_CHANNEL}" "${SEED_SNAP}" + fi + done + + # Move snaps and seertions to the correct place + # Runs outside the container. + mv -v ${R}/*.snap ${R}/${SEED_DIR}/snaps/ + mv -v ${R}/*.assert ${R}/${SEED_DIR}/assertions/ + + # Create model and account assertions + # Runs inside the container. + snap known --remote model series=16 model=generic-classic brand-id=generic > ${R}/${SEED_DIR}/assertions/generic-classic.model + ACCOUNT_KEY=$(grep "^sign-key-sha3-384" ${R}/${SEED_DIR}/assertions/generic-classic.model | cut -d':' -f2 | sed 's/ //g') + snap known --remote account-key public-key-sha3-384=${ACCOUNT_KEY} > ${R}/${SEED_DIR}/assertions/generic.account-key + snap known --remote account account-id=generic > ${R}/${SEED_DIR}/assertions/generic.account + + # Create the seed.yaml: the manifest of snaps to install + # Runs outside the container + echo "snaps:" > ${R}/${SEED_DIR}/seed.yaml + for ASSERT_FILE in ${R}/${SEED_DIR}/assertions/*.assert; do + SNAP_NAME=$(grep "^snap-name" ${ASSERT_FILE} | cut -d':' -f2 | sed 's/ //g') + SNAP_REVISION=$(grep "^snap-revision" ${ASSERT_FILE} | cut -d':' -f2 | sed 's/ //g') + if [ "${SNAP_NAME}" == "core" ] || [ "${SNAP}" == "core16" ] || [ "${SNAP}" == "core18" ]; then + SNAP_CHANNEL="stable" + else + SNAP_CHANNEL="${SEED_CHANNEL}" + fi + + # Classic snaps require a "classic: true" attribute in the seed file + if [[ $CLASSIC_SNAPS =~ $SNAP_NAME ]]; then + printf " - name: %s\n channel: %s\n classic: true\n file: %s_%s.snap\n" ${SNAP_NAME} ${SNAP_CHANNEL} ${SNAP_NAME} ${SNAP_REVISION} >> ${R}/${SEED_DIR}/seed.yaml + else + printf " - name: %s\n channel: %s\n file: %s_%s.snap\n" ${SNAP_NAME} ${SNAP_CHANNEL} ${SNAP_NAME} ${SNAP_REVISION} >> ${R}/${SEED_DIR}/seed.yaml + fi + done + cat ${R}/${SEED_DIR}/seed.yaml + fi +} + # Base installation (rootfs) make_image_root() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then