glacier-ng 4.0.0

This commit is contained in:
lw-everestlinux committed 2026-10-29 09:15:34 -04:00
commit 0cf4829fa5
159 files changed
+33717

No files matched your search

+307
View File
@@ -0,0 +1,307 @@
#!/bin/sh
# -f and -u from repositories (REPO_DESIGN.txt section 6, step 4):
# - every -f/-u refreshes every index first; any failure refuses;
# - -f NAME takes the first repo (by repos.conf order) serving NAME,
# at its highest version; a name nobody serves is refused;
# - missing dependencies are added (auto, marked in the summary); one
# installed too old is upgraded from its own repo, keeping its mark;
# one that can't be met is refused by the 2.3 check;
# - downloads go to <base>/cache/REPO (scope owner and modes), are
# hashed against the index (size capped), the manifest must say what
# the index says (name, version, REPO, deps, conflicts), and a base
# package needs no .sig of its own; files are deleted once committed;
# - -u replaces what an index has newer (backups, KEEP_OLD), -u NAME
# only those; -f of an installed other version needs -O, like -l;
# - gpkg -f/-u: user scope, never from base, system packages meet deps;
# - syspkg -R DIR -f installs into DIR, with DIR's own repos.conf.
# Runs INSIDE the Dockerfile.alpine_root image (its test key,
# glacier-test, is listed for base):
#
# docker run --rm -v "$PWD/tests/fetch_alpine.sh:/t.sh:ro" glacier-alpine_root sh /t.sh
FAILS=0
check() { d=$1; shift; if "$@"; then echo "PASS: $d"; else echo "FAIL: $d"; FAILS=$((FAILS+1)); fi; }
nocolor() { sed 's/\x1b\[[0-9;]*m//g'; }
R() {
OUT=$( ("$@"; echo "rc=$?") 2>&1 | nocolor)
RC=$(echo "$OUT" | sed -n 's/^rc=//p' | tail -1)
echo "$OUT" | sed '/^rc=/d; s/^/ /'
}
has() { echo "$OUT" | grep -qF -- "$1"; }
lacks() { ! has "$1"; }
empty() { [ -z "$(find "$@" -type f)" ]; }
rc() { [ "$RC" = "$1" ]; }
hr() { echo; echo "== $*"; }
export PATH=/app:$PATH
K=/etc/glacier/keys
CONF=/etc/glacier/repos.conf
TEST_SEC=/root/glacier-test.sec
XSEC=/root/extrakey.sec
B=/srv/base
E=/srv/extra
C=/srv/community
IDX=/glacier/sys/index/current
CACHE=/glacier/sys/cache
mkdir -p $B $E $C && chmod 755 /srv $B $E $C
gsign -G -p $K/extrakey.pub -s $XSEC -c extrakey >/dev/null
conf() { printf 'repos = (\n%s\n);\n' "$1" > $CONF; chmod 644 $CONF; }
BASE_E=' { name = "base"; url = "file:///srv/base"; keys = [ "glacier-test" ]; },'
EXTRA_E=' { name = "extra"; url = "file:///srv/extra"; keys = [ "extrakey" ]; },'
COMM_E=' { name = "community"; url = "file:///srv/community"; keys = [ "extrakey" ]; }'
conf "$BASE_E
$EXTRA_E
$COMM_E"
# mkpkg into a repo dir, without a sidecar signature: the index vouches.
pk() { d=$1; shift; /app/tests/mkpkg -o "$d" "$@" >/dev/null; }
publish() {
grepo -s $TEST_SEC -r base $B >/dev/null &&
grepo -s $XSEC -r extra $E >/dev/null &&
grepo -s $XSEC -r community $C >/dev/null
}
line() { grep -q "^$1\$" $IDX; }
yes_to() { sh -c "echo y | $*"; }
no_to() { sh -c "echo n | $*"; }
syspkg -n >/dev/null
pk $B core 1.0.0 base
pk $B core 1.1.0 base
pk $E lib 1.0.0 extra
pk $E lib 2.0.0 extra
pk $E -d lib:2.0.0 -d core:1.0.0 app 1.0.0 extra
pk $E dup 1.0.0 extra
pk $C dup 9.0.0 community
pk $C only 1.0.0 community
pk $E -d ghost:1.0.0 lonely 1.0.0 extra
pk $E -d lib:9.0.0 greedy 1.0.0 extra
pk $E -c app:0.0.0 rival 1.0.0 extra
publish
hr "refusals before anything is fetched"
R syspkg -f nosuch
check "a name no repository serves is refused" has "[x] nosuch is not in any repository."
check "...exit 1" rc 1
check "...after refreshing every index" has "[✓] All repositories synced successfully."
R syspkg -f
check "-f needs a name" has " -f PKG..."
R syspkg -f app -x lib
check "-f and -x are mutually exclusive" has "[x] -n, -l, -f, -u, -x and -y are mutually exclusive."
mv $E/repo.idx.sig /srv/sig.bak
R yes_to syspkg -f app
check "a failed refresh refuses -f" has "[x] Cannot fetch the index for extra."
check "...exit 1, nothing installed" sh -c "[ $RC = 1 ] && ! grep -q app $IDX"
mv /srv/sig.bak $E/repo.idx.sig
su nobody -s /bin/sh -c 'syspkg -f app' >/srv/np.out 2>&1
check "syspkg -f as non-root is refused" grep -qF "Cannot open system index: Permission denied" /srv/np.out
hr "an installed dependency too old is upgraded"
R yes_to syspkg -l $E/lib-1.0.0.gpkg
check "lib 1.0.0 installed locally" line "extra::lib::1.0.0::explicit"
R no_to syspkg -f app
check "the summary lists app" has " * extra::app 1.0.0"
check "...lib's upgrade, as a dependency" has " * extra::lib 1.0.0 -> 2.0.0 (dependency)"
check "...and core, the newest base has, as a dependency" has " * base::core 1.1.0 (dependency)"
check "declining installs nothing" sh -c "! grep -q app $IDX"
check "...the downloads stay in the cache" [ -f $CACHE/extra/app-1.0.0.gpkg -a -f $CACHE/base/core-1.1.0.gpkg ]
check "...cache dirs are root's, 0755" [ "$(stat -c '%u %a' $CACHE $CACHE/extra)" = "0 755
0 755" ]
check "...cached files are 0644" [ "$(stat -c %a $CACHE/extra/app-1.0.0.gpkg)" = 644 ]
check "...no temporary files" [ -z "$(find $CACHE -name '.*' -type f)" ]
printf 'garbage' > $CACHE/extra/app-1.0.0.gpkg
R yes_to syspkg -f app
check "-f app completes" has "[✓] Completed with no errors."
check "...a corrupt cached file is fetched again" rc 0
check "app is explicit" line "extra::app::1.0.0::explicit"
check "lib was upgraded and stays explicit" line "extra::lib::2.0.0::explicit"
check "core is recorded as a dependency" line "base::core::1.1.0::auto"
check "lib 1.0.0 was backed up (KEEP_OLD)" [ -f /glacier/sys/backup/extra/lib/lib-1.0.0.gpkg ]
check "base::core installed with no .sig of its own" [ ! -e $B/core-1.1.0.gpkg.sha256.sig -a -x /usr/bin/core ]
check "the cache is emptied once committed" empty $CACHE
check "staged from the repository" has "base::core-1.1.0: staged from file:///srv/base/core-1.1.0.gpkg."
hr "choosing a repository"
# A named package several repos serve is asked about (BUILD_DESIGN.txt
# 1f); Enter takes the first by priority.
R sh -c "printf '\ny\n' | syspkg -f dup"
check "a name two repos serve: asked" has "[i] dup is available from more than one repository:"
check "...in repos.conf order, each at its highest version" sh -c 'echo "$0" | grep -A2 "more than one" | tr "\n" "|" | grep -qF " 1) extra::dup 1.0.0| 2) community::dup 9.0.0|"' "$OUT"
check "...Enter takes the first, though community's is higher" line "extra::dup::1.0.0::explicit"
check "...community's 9.0.0 is not installed" sh -c "! grep -q community::dup $IDX"
R yes_to syspkg -f only
check "a name only a later repo serves comes from it, unasked" line "community::only::1.0.0::explicit"
check "...no question" lacks "more than one repository"
R sh -c "printf '\ny\n' | syspkg -f dup dup"
check "a name given twice is asked about and fetched once" sh -c "[ $(echo "$OUT" | grep -c 'extra::dup ') = 1 ] && [ $(echo "$OUT" | grep -c 'more than one') = 1 ]"
hr "dependencies that can't be met"
R yes_to syspkg -f lonely
check "a dependency no repo serves is refused" has "[x] extra::lonely requires ghost >= 1.0.0, which is not installed."
check "...exit 1, before the prompt" sh -c "[ $RC = 1 ]" && check "...no prompt" lacks "Proceed?"
R yes_to syspkg -f greedy
check "a dependency no repo has new enough is refused" has "[x] extra::greedy requires lib >= 9.0.0, which is not installed."
R yes_to syspkg -f rival
check "a conflict is refused" has "[x] extra::rival conflicts with extra::app."
check "...nothing installed" sh -c "! grep -q rival $IDX"
hr "what the index says must be what the package says"
# extrakey signs an index listing a package that claims to be base:
# a key trusted for extra must not be able to put anything into /usr.
forge() { # forge NAME VER FILE: put FILE in extra as NAME-VER.gpkg, re-sign
cp "$3" $E/$1-$2.gpkg
sha=$(sha256sum $E/$1-$2.gpkg | cut -c1-64); size=$(wc -c < $E/$1-$2.gpkg)
awk -v n="$1" -v s="$sha" -v z="$size" '
hit { sub(/SHA256 = "[^"]*"; SIZE = [0-9]*L;/, "SHA256 = \"sha256:" s "\"; SIZE = " z "L;"); hit = 0 }
index($0, "NAME = \"" n "\";") { hit = 1 } { print }' $E/repo.idx > /srv/idx.new
serial=$(sed -n 's/^SERIAL = \([0-9]*\)L;$/\1/p' $E/repo.idx)
sed "s/^SERIAL = .*/SERIAL = $((serial + 1))L;/" /srv/idx.new > $E/repo.idx
gsign -S -s $XSEC -m $E/repo.idx
}
mkdir -p /srv/evil
pk $E evil 1.0.0 extra
pk /srv/evil evil 1.0.0 base
pk $E plain 1.0.0 extra
pk /srv/evil -d core:1.0.0 plain 1.0.0 extra
publish
forge evil 1.0.0 /srv/evil/evil-1.0.0.gpkg
forge plain 1.0.0 /srv/evil/plain-1.0.0.gpkg
R yes_to syspkg -f evil
check "a package claiming base from extra's index is refused" has "[x] extra::evil 1.0.0 does not match its index."
check "...exit 1, nothing in /usr" sh -c "[ $RC = 1 ] && [ ! -e /usr/bin/evil ] && ! grep -q evil $IDX"
R yes_to syspkg -f plain
check "dependencies the index doesn't list are refused" has "[x] extra::plain 1.0.0 does not match its index."
# grepo would refuse the forged files: back to honest ones.
rm $E/evil-1.0.0.gpkg* $E/plain-1.0.0.gpkg*
pk $E -d lib:2.0.0 needslib 1.0.0 extra
publish
printf 'X' >> $E/needslib-1.0.0.gpkg
R yes_to syspkg -f needslib
check "a download bigger than the index says is refused" has "[x] extra::needslib 1.0.0 does not match its index."
pk $E -d lib:2.0.0 needslib 1.0.0 extra
publish
head -c 100 $E/needslib-1.0.0.gpkg > /srv/short && cp /srv/short $E/needslib-1.0.0.gpkg
R yes_to syspkg -f needslib
check "a truncated one too" has "[x] extra::needslib 1.0.0 does not match its index."
check "...nothing half-fetched is left in the cache" [ ! -e $CACHE/extra/needslib-1.0.0.gpkg -a -z "$(find $CACHE -name '.*' -type f)" ]
check "packages whose manifest contradicts the index are not kept" [ ! -e $CACHE/extra/evil-1.0.0.gpkg -a ! -e $CACHE/extra/plain-1.0.0.gpkg ]
check "...refused but genuine ones are, until installed" [ -f $CACHE/extra/rival-1.0.0.gpkg ]
pk $E -d lib:2.0.0 needslib 1.0.0 extra
publish
rm $E/needslib-1.0.0.gpkg
R yes_to syspkg -f needslib
check "a file the repository lacks cannot be fetched" has "[x] Cannot fetch extra::needslib 1.0.0."
pk $E -d lib:2.0.0 needslib 1.0.0 extra
publish
# A "package" that never ends: only SIZE bytes (+1) may ever be read.
pk $E endless 1.0.0 extra
publish
ln -sf /dev/zero $E/endless-1.0.0.gpkg
R sh -c 'echo y | timeout -s KILL 30 syspkg -f endless'
check "a download that never ends is cut off at the index's size" has "[x] extra::endless 1.0.0 does not match its index."
check "...promptly" [ "$RC" = 1 ]
check "...and nothing of it is left" [ -z "$(find $CACHE -name '*endless*')" ]
rm $E/endless-1.0.0.gpkg*
publish
hr "the cache directory"
chmod 777 $CACHE/community
R yes_to syspkg -f only
check "a loosened cache dir is refused" has "[x] Refusing $CACHE/community: not a directory owned by UID 0 with mode 755."
check "...exit 1" rc 1
chmod 755 $CACHE/community
mv $CACHE/community /srv/realcache && ln -s /srv/realcache $CACHE/community
R yes_to syspkg -f only
check "a symlinked cache dir is refused" has "[x] Refusing $CACHE/community: not a directory owned by UID 0 with mode 755."
rm $CACHE/community && mv /srv/realcache $CACHE/community
chmod 777 $CACHE
R yes_to syspkg -f only
check "a loosened cache is refused" has "[x] Refusing $CACHE: not a directory owned by UID 0 with mode 755."
chmod 755 $CACHE
hr "-f of an installed other version"
pk $E dup 1.1.0 extra
publish
R sh -c "printf '1\ny\n' | syspkg -f dup"
check "needs -O, like -l" has "[x] extra::dup 1.0.0 is already installed."
R sh -c "printf '1\ny\n' | syspkg -fO dup"
check "-fO replaces it" line "extra::dup::1.1.0::explicit"
hr "-u"
R yes_to syspkg -u
check "nothing newer: nothing to do" has "[✓] Nothing to do."
check "...exit 0" rc 0
pk $E lib 2.1.0 extra
pk $B core 1.2.0 base
publish
R no_to syspkg -u
check "-u lists lib" has " * extra::lib 2.0.0 -> 2.1.0"
check "...and core" has " * base::core 1.1.0 -> 1.2.0"
check "...not app, which has nothing newer" lacks "extra::app "
R yes_to syspkg -u lib
check "-u lib upgrades lib" line "extra::lib::2.1.0::explicit"
check "...and only lib" line "base::core::1.1.0::auto"
R yes_to syspkg -u
check "-u upgrades the rest" line "base::core::1.2.0::auto"
check "...keeping core's dependency mark" line "base::core::1.2.0::auto"
check "...the old core is backed up" [ -f /glacier/sys/backup/base/core/core-1.1.0.gpkg ]
pk $E -d newdep:1.0.0 app 1.1.0 extra
pk $E newdep 1.0.0 extra
publish
R yes_to syspkg -u app
check "an upgrade's new dependency is added" line "extra::newdep::1.0.0::auto"
check "...with the upgrade" line "extra::app::1.1.0::explicit"
R syspkg -u nosuch
check "-u of a name not installed is refused" has "[x] nosuch is not installed."
conf "$BASE_E
$EXTRA_E"
R syspkg -u only
check "-u of a package whose repo isn't configured is refused" has "[x] community::only is not in any configured repository."
R yes_to syspkg -u
check "...and plain -u leaves it alone" line "community::only::1.0.0::explicit"
conf "$BASE_E
$EXTRA_E
$COMM_E"
hr "gpkg -f / -u (user scope)"
adduser -D tester >/dev/null 2>&1
U=$(id -u tester)
gstore -n "$U" >/dev/null
UB=/glacier/usr/$U
pk $E -d core:1.0.0 userapp 1.0.0 extra
publish
R su tester -c 'gpkg -f core'
check "gpkg never fetches from base" has "[x] core is not in any repository."
R su tester -c 'echo y | gpkg -f userapp'
check "gpkg -f installs into the user's scope" grep -q "^extra::userapp::1.0.0::explicit\$" $UB/index/current
check "...core, installed in the system, meets its dependency" sh -c "! grep -q core $UB/index/current"
check "...the user's cache is theirs, 0700" [ "$(stat -c '%u %a' $UB/cache $UB/cache/extra)" = "$U 700
$U 700" ]
check "...and emptied" empty $UB/cache
check "...the user's indexes are theirs" [ "$(stat -c %u $UB/repos/extra.idx)" = "$U" ]
R su tester -c 'gpkg -f "%s%s%s%s%n"'
check "gpkg -f with %s%n as its operand" has "[x] %s%s%s%s%n is not in any repository."
R su tester -c 'gpkg -u "%s%s%s%s%n"'
check "gpkg -u with %s%n as its operand" has "[x] %s%s%s%s%n is not installed."
pk $E -d core:1.0.0 userapp 1.1.0 extra
publish
R su tester -c 'echo y | gpkg -u'
check "gpkg -u upgrades the user's package" grep -q "^extra::userapp::1.1.0::explicit\$" $UB/index/current
check "...the system's are untouched" line "extra::lib::2.1.0::explicit"
R su tester -c 'gpkg -f'
check "gpkg -f needs a name" has " -f PKG..."
hr "syspkg -R DIR -f"
mkdir -p /mnt/img
syspkg -R /mnt/img -n >/dev/null
# -R uses the image's own keyring, as a package would ship it.
mkdir -p /mnt/img/etc/glacier && cp -a /etc/glacier/repos.conf /etc/glacier/keys /mnt/img/etc/glacier/
R yes_to syspkg -R /mnt/img -f app
check "-R -f installs into the image" grep -q "^extra::app::1.1.0::explicit\$" /mnt/img/glacier/sys/index/current
check "...with its dependencies" grep -q "^extra::newdep::1.0.0::auto\$" /mnt/img/glacier/sys/index/current
check "...indexes and cache under the image" [ -f /mnt/img/glacier/sys/repos/extra.idx -a -d /mnt/img/glacier/sys/cache/extra ]
check "...the host's store is untouched" line "extra::app::1.1.0::explicit"
echo
echo "FAILURES: $FAILS"
[ $FAILS -eq 0 ]