Files
rk1/tests/test-offline-apt.sh

64 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
PROJECT_DIR=$(cd -- "$SCRIPT_DIR/.." && pwd -P)
DEPENDENCY_ARCHIVES="$PROJECT_DIR/work/apt/archives"
MEDIA_DEB="$PROJECT_DIR/media/out/rk1-media-stack_20260721.1741+rk1.1_arm64.deb"
[[ -d "$DEPENDENCY_ARCHIVES" ]] || { echo "Missing APT archives: $DEPENDENCY_ARCHIVES" >&2; exit 1; }
[[ -f "$MEDIA_DEB" ]] || { echo "Missing media package: $MEDIA_DEB" >&2; exit 1; }
TEST_TMP=$(mktemp -d "$PROJECT_DIR/work/rk1-offline-apt.XXXXXXXX")
trap 'rm -rf -- "$TEST_TMP"' EXIT
SEED_ARCHIVES="$TEST_TMP/opt/rk1-seed/debs"
mkdir -p "$SEED_ARCHIVES/partial" "$TEST_TMP/state"
# Hard links keep this acquisition regression test fast while presenting APT
# with the exact single-directory cache layout used in the finished image.
while IFS= read -r -d '' source_deb; do
ln -- "$source_deb" "$SEED_ARCHIVES/$(basename -- "$source_deb")"
done < <(find "$DEPENDENCY_ARCHIVES" -maxdepth 1 -type f -name '*.deb' -print0 | sort -z)
ln -- "$MEDIA_DEB" "$SEED_ARCHIVES/$(basename -- "$MEDIA_DEB")"
mapfile -d '' debs < <(find "$SEED_ARCHIVES" -maxdepth 1 -type f -name '*.deb' -print0 | sort -z)
[[ "${#debs[@]}" == 141 ]]
apt_options=(
-o APT::Architecture=arm64
-o Dir::State::status="$PROJECT_DIR/work/base-meta/status"
-o Dir::State::lists="$PROJECT_DIR/work/apt/lists"
-o Dir::State::extended_states="$TEST_TMP/state/extended_states"
-o Dir::Cache::archives="$SEED_ARCHIVES"
-o Dir::Cache::pkgcache="$TEST_TMP/pkgcache.bin"
-o Dir::Cache::srcpkgcache="$TEST_TMP/srcpkgcache.bin"
-o Dir::Etc::sourcelist="$PROJECT_DIR/work/base-meta/debian-build.sources"
-o Dir::Etc::sourceparts=-
-o Debug::NoLocking=true
-o APT::Sandbox::User=
-o APT::Keep-Downloaded-Packages=true
)
simulation_log="$TEST_TMP/simulation.log"
apt-get "${apt_options[@]}" --simulate --no-download --no-install-recommends \
install "${debs[@]}" >"$simulation_log"
grep -q '^0 upgraded, 141 newly installed, 0 to remove' "$simulation_log"
[[ "$(grep -c '^Inst ' "$simulation_log")" == 141 ]]
[[ "$(grep -c '^Conf ' "$simulation_log")" == 141 ]]
(
cd "$SEED_ARCHIVES"
sha256sum -- *.deb >"$TEST_TMP/debs.before.sha256"
)
acquisition_log="$TEST_TMP/acquisition.log"
apt-get "${apt_options[@]}" --download-only --no-download \
--no-install-recommends --yes install "${debs[@]}" >"$acquisition_log"
grep -q '^0 upgraded, 141 newly installed, 0 to remove' "$acquisition_log"
grep -Eq '^Download complete( and in download only mode)?$' "$acquisition_log"
! grep -q '^Need to get ' "$acquisition_log"
(
cd "$SEED_ARCHIVES"
sha256sum -- *.deb >"$TEST_TMP/debs.after.sha256"
)
cmp --silent "$TEST_TMP/debs.before.sha256" "$TEST_TMP/debs.after.sha256"
echo 'PASS: offline APT closure and real acquisition (141 packages, zero downloads)'