# Functions in base.sh and apt.sh, run on their own with stand-ins for what # they call in the VM (fn.sh, below). # mirrored: each archive of a sources file gets a mirror list of the mirror # set, then that archive, the rest of the file as it was. mkdir pk/in cp mirrors pk/in/mirrors exec bash -c 'source fn.sh; layer_fn apt mirrored; dir=$PWD/pk; mirrored ubuntu.sources out.sources' exec sh -c 'sed "s|$WORK|WORK|g" out.sources' cmp stdout mirrored.sources cmp pk/mirrors-1 want-mirrors-1 cmp pk/mirrors-2 want-mirrors-2 cmp ubuntu.sources ubuntu.sources.orig # record: each package downloaded goes to out/.deb, with apt's entry # for that version with that SHA-256 (not another's) in out/Packages, and # each InRelease and package list apt has to out/.InRelease or # out/.Packages, its other lists left out. mkdir archives lists cp git.deb archives/git_1_arm64.deb cp inrelease lists/mirror_dists_resolute_InRelease cp packages lists/mirror_dists_resolute_main_binary-arm64_Packages cp packages lists/mirror_dists_resolute_main_i18n_Translation-en exec bash -c 'set -euo pipefail; source fn.sh; layer_fn apt record; dpkg_deb_stub; dir=$PWD/pk archives=$PWD/archives lists=$PWD/lists; record' exists pk/out/aaaa.deb ! exists archives/git_1_arm64.deb cmp pk/out/Packages want-packages cmp pk/out/1.InRelease inrelease cmp pk/out/2.Packages packages exec sh -c 'LC_ALL=C ls pk/out' cmp stdout want-out # One apt's lists don't have with that SHA-256 fails it. cp git.deb archives/git_1_arm64.deb env WRONG=1 ! exec bash -c 'set -euo pipefail; source fn.sh; layer_fn apt record; dpkg_deb_stub; dir=$PWD/pk archives=$PWD/archives lists=$PWD/lists; record' stderr 'apt''s lists have no git 1 \(arm64\)' env WRONG= # installed: only the packages that are installed, and no failure for # unknown ones. exec bash -c 'set -eo pipefail; source fn.sh; layer_fn base installed; dpkg_stub; installed snapd fwupd rsyslog nope' cmp stdout installed -- fn.sh -- # layer_fn SCRIPT NAME: define NAME from assets/layers/SCRIPT.sh (the scripts run # top to bottom when sourced). layer_fn() { eval "$(awk -v f="$2() " 'index($0, f) == 1 { on = 1 } on { print } on && /^}/ { exit }' "$DEVVM_REPO/assets/layers/$1.sh")"; } # dpkg-deb reads git.deb's fields; sha256sum gives aaaa; apt-cache has two # entries for the version, one with that SHA-256 (unless $WRONG). dpkg_deb_stub() { dpkg-deb() { case $3 in Package) echo git ;; Version) echo 1 ;; Architecture) echo arm64 ;; esac; } sha256sum() { echo "aaaa $1"; } apt-cache() { printf 'Package: git\nVersion: 1\nSHA256: bbbb\n\n' if [[ -z ${WRONG:-} ]]; then printf 'Package: git\nVersion: 1\nSHA256: aaaa\nDescription: git\n more\n\n'; fi } } # dpkg-query lists what it knows and fails for the rest, like the real one. dpkg_stub() { dpkg-query() { printf 'installed snapd\nnot-installed fwupd\nconfig-files rsyslog\n' echo "dpkg-query: no packages found matching nope" >&2; return 1 } } -- mirrors -- https://mirror.example/ubuntu-ports -- ubuntu.sources -- Types: deb URIs: http://ports.ubuntu.com/ubuntu-ports/ Suites: resolute resolute-updates resolute-backports Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: http://security.ubuntu.com/ubuntu/ Suites: resolute-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg -- ubuntu.sources.orig -- Types: deb URIs: http://ports.ubuntu.com/ubuntu-ports/ Suites: resolute resolute-updates resolute-backports Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: http://security.ubuntu.com/ubuntu/ Suites: resolute-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg -- mirrored.sources -- Types: deb URIs: mirror+file:WORK/pk/mirrors-1 Suites: resolute resolute-updates resolute-backports Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: mirror+file:WORK/pk/mirrors-2 Suites: resolute-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg -- want-mirrors-1 -- https://mirror.example/ubuntu-ports http://ports.ubuntu.com/ubuntu-ports/ -- want-mirrors-2 -- https://mirror.example/ubuntu-ports http://security.ubuntu.com/ubuntu/ -- git.deb -- not really a package -- want-packages -- Package: git Version: 1 SHA256: aaaa Description: git more -- inrelease -- an InRelease -- packages -- a package list -- want-out -- 1.InRelease 2.Packages Packages aaaa.deb -- installed -- snapd