From 896b5962dbf6c52b8029acf72ebc856a09d82b2a Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Wed, 27 May 2020 17:10:24 +0100 Subject: [PATCH] snap_preseed: support channel specification with snap name snap_name[/classic]=track/risk/branch is now the supported snap name specification, which allows to specify the full default track and optional classic confinemnt. Supporting such specification in the seedtext allows one to specify a better default channel. For example, this will allow lxd to switch from latest/stable/ubuntu-20.04 to 4.0/stable/ubuntu-20.04 as 4.0 is the LTS track matching 20.04 support timeframe. LP: #1882374 (cherry picked from commit 7bae9201d20822d6875bcf5949e1fff839b8774c) (cherry picked from commit 2976a99f292c500f39aace25ad08de21b37d7b31) (cherry picked from commit d542e8e4a08467ef9b6237b9fcbd9166c8c99e8b) --- live-build/functions | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/live-build/functions b/live-build/functions index d86f27d6..2e505949 100644 --- a/live-build/functions +++ b/live-build/functions @@ -626,11 +626,31 @@ snap_prepare() { snap_preseed() { # Preseed a snap in the image (snap_prepare must be called once prior) local CHROOT_ROOT=$1 + # $2 can be in the form of snap_name/classic=track/risk/branch local SNAP=$2 + # strip CHANNEL specification + SNAP=${SNAP%=*} + # strip /classic confinement local SNAP_NAME=${SNAP%/*} - # 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)"} + # Seed from the specified channel (e.g. core18 latest/stable) + # Or Channel endcoded in the snap name (e.g. lxd=4.0/stable/ubuntu-20.04) + # Or Ubuntu policy default channel latest/stable/ubuntu-$(release_ver) + local CHANNEL=${3:-} + if [ -z "$CHANNEL" ]; then + case $2 in + *=*) + CHANNEL=${2#*=} + ;; + *) + CHANNEL="stable/ubuntu-$(release_ver)" + ;; + esac + fi + + # At this point: + # SNAP_NAME is just the snap name + # SNAP is either $SNAP_NAME or $SNAP_NAME/classic for classic confined + # CHANNEL is the channel if [ ! -e "$CHROOT_ROOT/var/lib/snapd/seed/assertions/model" ]; then echo "ERROR: Snap model assertion not present, snap_prepare must be called"