From ef72cf5fe845ff4f156d62451474fc82f23aed0a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lallement Date: Thu, 15 Nov 2018 11:43:09 +0100 Subject: [PATCH] Code refactoring: * Moved *inheritance functions from config to functions * Moved code to extract snap from seed to snap_from_seed function --- live-build/auto/config | 42 +----------------------------------- live-build/functions | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/live-build/auto/config b/live-build/auto/config index c6893eec..fa21cdce 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -261,30 +261,6 @@ if [ "${SUBPROJECT:-}" = minimized ]; then OPTS="${OPTS:+$OPTS }--bootstrap-flavour=minimal --linux-packages=linux-image" fi -# cribbed from cdimage, perhaps this should be a small helper script in germinate? -add_inheritance () { - case " $inherit " in - *" $1 "*) - ;; - *) - inherit="${inherit:+$inherit }$1" - ;; - esac -} - -expand_inheritance () { - for seed in $(grep "^$1:" config/germinate-output/structure | cut -d: -f2); do - expand_inheritance "$seed" - done - add_inheritance "$1" -} - -inheritance () { - inherit= - expand_inheritance "$1" - echo "$inherit" -} - mkdir -p config/germinate-output case $PROJECT in kubuntu-active*) @@ -723,23 +699,7 @@ if [ "${IMAGEFORMAT:-}" != live-layered ]; then esac if [ -n "${BASE_SEED}" ]; then - SEEDS_EXPANDED=$(inheritance ${BASE_SEED}) - for seed in ${SEEDS_EXPANDED}; do - echo "snap: considering ${seed}" - file=config/germinate-output/${seed}.snaps - [ -e "${file}" ] || continue - # extract the first column (snap package name) from germinate's output - # translate the human-readable "foo (classic)" into a - # more machine readable "foo/classic" - seed_snaps=$(sed -rn '1,/-----/d;/-----/,$d; s/(.*) \|.*/\1/; s, \(classic\),/classic,; p' "${file}") - for snap in ${seed_snaps}; do - echo "snap: found ${snap}" - ALL_SNAPS="${ALL_SNAPS:+${ALL_SNAPS} }${snap}" - done - done - if [ -n "${ALL_SNAPS}" ] || [ -n "${HOOK_SNAPS}" ]; then - echo "${ALL_SNAPS}" > config/seeded-snaps - fi + snap_from_seed "${BASE_SEED}" config/seeded-snaps fi # grab a list of packags to remove for a "minimal" installation from the seed diff --git a/live-build/functions b/live-build/functions index fe6da6d9..c3fe2a35 100644 --- a/live-build/functions +++ b/live-build/functions @@ -373,6 +373,30 @@ release_ver() { distro-info --series="$LB_DISTRIBUTION" -r | awk '{ print $1 }' } +# cribbed from cdimage, perhaps this should be a small helper script in germinate? +add_inheritance () { + case " $inherit " in + *" $1 "*) + ;; + *) + inherit="${inherit:+$inherit }$1" + ;; + esac +} + +expand_inheritance () { + for seed in $(grep "^$1:" config/germinate-output/structure | cut -d: -f2); do + expand_inheritance "$seed" + done + add_inheritance "$1" +} + +inheritance () { + inherit= + expand_inheritance "$1" + echo "$inherit" +} + _snap_preseed() { # Download the snap/assertion and add to the preseed local CHROOT_ROOT=$1 @@ -502,6 +526,30 @@ snap_preseed() { _snap_preseed $CHROOT_ROOT $SNAP $CHANNEL } +snap_from_seed() { + local base_seed=$1 + local out=$2 + local all_snaps + local seeds_expanded + + seeds_expanded=$(inheritance ${base_seed}) + for seed in ${seeds_expanded}; do + echo "snap: considering ${seed}" + file=config/germinate-output/${seed}.snaps + [ -e "${file}" ] || continue + # extract the first column (snap package name) from germinate's output + # translate the human-readable "foo (classic)" into a + # more machine readable "foo/classic" + seed_snaps=$(sed -rn '1,/-----/d;/-----/,$d; s/(.*) \|.*/\1/; s, \(classic\),/classic,; p' "${file}") + for snap in ${seed_snaps}; do + echo "snap: found ${snap}" + all_snaps="${all_snaps:+${all_snaps} }${snap}" + done + done + if [ -n "${all_snaps}" ]; then + echo "${all_snaps}" > $out + fi +} add_task () {