From 9f96dcb4dee690be46a6d1a09b0535692d32b7a6 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 27 Sep 2018 11:36:01 -0500 Subject: [PATCH 1/6] Add the server snap seed to the ubuntu-cpc project --- debian/changelog | 3 +++ live-build/auto/config | 3 +++ 2 files changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 33233a26..5f3288e3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,9 @@ livecd-rootfs (2.541) UNRELEASED; urgency=medium * Remove device nodes from Docker images. (LP: #1645468) + [ Robert C Jennings ] + * Add the server snap seed to the ubuntu-cpc project + -- Michael Hudson-Doyle Wed, 26 Sep 2018 12:43:23 +1200 livecd-rootfs (2.540) cosmic; urgency=medium diff --git a/live-build/auto/config b/live-build/auto/config index fd2ce64d..5ab67fac 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -696,6 +696,9 @@ case $PROJECT:${SUBPROJECT:-} in ubuntu:*|kubuntu*:*|lubuntu*:*|xubuntu*:*|ubuntu-mate*:*|ubuntustudio*:*|ubuntukylin*:*|ubuntu-budgie*:*) BASE_SEED='desktop' ;; + ubuntu-cpc:*) + BASE_SEED='server' + ;; ubuntu-server:live) BASE_SEED='server' # subiquity is seeded but in a separate squashfs via hooks; set HOOK_SNAPS and ALL_SNAPS. From 52e5a2b25b48f6b6f8d992b452fab42715f5bbc0 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 27 Sep 2018 11:36:53 -0500 Subject: [PATCH 2/6] Allow hooks to replace generic snap assertion The generic assertion will be put in place if there are preseeded snaps. A hook that wants to add its own model should be able to overwrite the generic assertion. This patch allows a hook to continue unchanged calling snap_prepare_assertions with a custom brand/model. The patch will replace the generic brand/model if a custom brand/model is specified. Prior to this patch the generic brand/model would remain in place. --- debian/changelog | 1 + live-build/functions | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/debian/changelog b/debian/changelog index 5f3288e3..41b3beda 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ livecd-rootfs (2.541) UNRELEASED; urgency=medium [ Robert C Jennings ] * Add the server snap seed to the ubuntu-cpc project + * Allow hooks to replace generic snap assertion -- Michael Hudson-Doyle Wed, 26 Sep 2018 12:43:23 +1200 diff --git a/live-build/functions b/live-build/functions index 4441f2b1..263f4c07 100644 --- a/live-build/functions +++ b/live-build/functions @@ -427,6 +427,22 @@ snap_prepare_assertions() { local brand="$(echo $CUSTOM_BRAND_MODEL | cut -d: -f 1)" local model="$(echo $CUSTOM_BRAND_MODEL | cut -d: -f 2)" + # Clear the assertions if a hook wants to prepare a new + # assertion that isn't the default generic:generic-classic + if [ -e "$model_assertion" ] ; then + existing_model=$(sed -n 's/^model: \(.*\)$/\1/p' $model_assertion) + existing_brand=$(sed -n 's/^brand-id: \(.*\)$/\1/p' $model_assertion) + if [ "$existing_model" == "generic-classic" ] && + [ "$existing_brand" == "generic" ] && + ( [ "$existing_model" != "$model" ] || + [ "$existing_brand" != "$brand" ] ); then + echo "snap_prepare_assertions: clearing $existing_brand:$existing_model for $brand:$model" + rm "$model_assertion" + rm "$account_key_assertion" + rm "$account_assertion" + fi + fi + if ! [ -e "$model_assertion" ] ; then snap known --remote model series=16 \ model=$model brand-id=$brand \ From 97b0bbeed364cb74eb984c78fb8b1407734c542a Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 27 Sep 2018 12:55:57 -0500 Subject: [PATCH 3/6] Add logging when snap assertions are not replaced --- live-build/functions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/live-build/functions b/live-build/functions index 263f4c07..2da0e2a0 100644 --- a/live-build/functions +++ b/live-build/functions @@ -440,6 +440,8 @@ snap_prepare_assertions() { rm "$model_assertion" rm "$account_key_assertion" rm "$account_assertion" + else + echo "snap_prepare_assertions: not replacing $existing_brand:$existing_model with $brand:$model" fi fi From 8d603cc87f857af24420e755fe19d6ec8c113423 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 27 Sep 2018 13:09:50 -0500 Subject: [PATCH 4/6] Simplify snap model assertion customization --- live-build/functions | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/live-build/functions b/live-build/functions index 2da0e2a0..e932c7b3 100644 --- a/live-build/functions +++ b/live-build/functions @@ -432,17 +432,10 @@ snap_prepare_assertions() { if [ -e "$model_assertion" ] ; then existing_model=$(sed -n 's/^model: \(.*\)$/\1/p' $model_assertion) existing_brand=$(sed -n 's/^brand-id: \(.*\)$/\1/p' $model_assertion) - if [ "$existing_model" == "generic-classic" ] && - [ "$existing_brand" == "generic" ] && - ( [ "$existing_model" != "$model" ] || - [ "$existing_brand" != "$brand" ] ); then - echo "snap_prepare_assertions: clearing $existing_brand:$existing_model for $brand:$model" - rm "$model_assertion" - rm "$account_key_assertion" - rm "$account_assertion" - else - echo "snap_prepare_assertions: not replacing $existing_brand:$existing_model with $brand:$model" - fi + echo "snap_prepare_assertions: replacing $existing_brand:$existing_model with $brand:$model" + rm "$model_assertion" + rm "$account_key_assertion" + rm "$account_assertion" fi if ! [ -e "$model_assertion" ] ; then @@ -486,13 +479,12 @@ snap_prepare() { } snap_preseed() { - # Preseed a snap in the image + # Preseed a snap in the image (snap_prepare must be called once prior) local CHROOT_ROOT=$1 local SNAP=$2 # Per Ubuntu policy, all seeded snaps (with the exception of the core # snap) must pull from stable/ubuntu-$(release_ver) as their channel. local CHANNEL=${3:-"stable/ubuntu-$(release_ver)"} - snap_prepare $CHROOT_ROOT _snap_preseed $CHROOT_ROOT $SNAP $CHANNEL } From 0e00214cc6124a8c0abc1d63d382e0beeb6ce988 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 27 Sep 2018 15:15:34 -0500 Subject: [PATCH 5/6] Ensure snap models have been added prior to snap preseeding --- live-build/functions | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/live-build/functions b/live-build/functions index e932c7b3..e6471b77 100644 --- a/live-build/functions +++ b/live-build/functions @@ -427,8 +427,7 @@ snap_prepare_assertions() { local brand="$(echo $CUSTOM_BRAND_MODEL | cut -d: -f 1)" local model="$(echo $CUSTOM_BRAND_MODEL | cut -d: -f 2)" - # Clear the assertions if a hook wants to prepare a new - # assertion that isn't the default generic:generic-classic + # Clear the assertions if they already exist if [ -e "$model_assertion" ] ; then existing_model=$(sed -n 's/^model: \(.*\)$/\1/p' $model_assertion) existing_brand=$(sed -n 's/^brand-id: \(.*\)$/\1/p' $model_assertion) @@ -452,7 +451,6 @@ snap_prepare_assertions() { > "$account_key_assertion" fi - if ! [ -e "$account_assertion" ] ; then local account=$(sed -n -e's/account-id: //p' < "$account_key_assertion") snap known --remote account account-id=$account \ @@ -486,5 +484,9 @@ snap_preseed() { # snap) must pull from stable/ubuntu-$(release_ver) as their channel. local CHANNEL=${3:-"stable/ubuntu-$(release_ver)"} + if [ ! -e "$CHROOT_ROOT/var/lib/snapd/seed/assertions/model" ]; then + echo "ERROR: Snap model assertion not present, snap_prepare must be called" + exit 1 + fi _snap_preseed $CHROOT_ROOT $SNAP $CHANNEL } From 5bbb8e6b3f21fa26b35106580b4f0f3d42b79668 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 27 Sep 2018 15:15:55 -0500 Subject: [PATCH 6/6] Improve snap model assertion code for readability --- live-build/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/live-build/functions b/live-build/functions index e6471b77..cf68ba16 100644 --- a/live-build/functions +++ b/live-build/functions @@ -429,8 +429,8 @@ snap_prepare_assertions() { # Clear the assertions if they already exist if [ -e "$model_assertion" ] ; then - existing_model=$(sed -n 's/^model: \(.*\)$/\1/p' $model_assertion) - existing_brand=$(sed -n 's/^brand-id: \(.*\)$/\1/p' $model_assertion) + existing_model=$(awk '/^model: / {print $2}' $model_assertion) + existing_brand=$(awk '/^brand-id: / {print $2}' $model_assertion) echo "snap_prepare_assertions: replacing $existing_brand:$existing_model with $brand:$model" rm "$model_assertion" rm "$account_key_assertion"