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

+174
View File
@@ -0,0 +1,174 @@
#!/bin/sh
# Install root / sysroot (ROADMAP 1.1, IMAGE_DESIGN section 3): building
# a system into T=/mnt/img through the library's *_at contexts.
# - the host's /usr, /glacier and /etc stay byte-identical (the
# non-negotiable assertion);
# - links in T say RUNTIME paths (/glacier/sys/store/...), and T boots:
# chroot T runs a linked binary through T's own loader;
# - stale-link pruning judges T's links against T's store, not the
# host's: links survive although the host lacks the package, and are
# pruned although the host has it;
# - -O's .displaced originals are keyed by runtime path and restored;
# - /etc config lands in T/etc; dependencies are checked against T;
# - user scope refuses an install root.
# syspkg --root is ROADMAP 1.2, so this drives the library over FFI.
# Runs INSIDE the Dockerfile.alpine_root image:
#
# ./run_docker.sh Dockerfile.alpine_root # builds glacier-alpine_root
# docker run --rm -v "$PWD/tests/sysroot_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; }
T=/mnt/img
S=/glacier/sys/store
# mkpkg NAME REPO [DEPS] -> /srv/NAME-1.0.0.gpkg; files come from
# /srv/src/NAME (already laid out as files/...)
mkpkg() {
w=$(mktemp -d); d=$w/$1-1.0.0
mkdir -p $d; cp -a /srv/src/$1 $d/files
deps=""; sep=""
for it in $3; do deps="$deps$sep{ PKG_NAME = \"${it%%:*}\"; PKG_VER = \"${it#*:}\"; }"; sep=", "; done
printf 'PKG_NAME = "%s";\nPKG_VER = "1.0.0";\nPKG_DESC = "t";\nPKG_MAINT = "t@e";\nPKG_COPYRIGHT = "MIT";\nPKG_REPO = "%s";\nPKG_DEPS = (%s);\nPKG_CONFS = ();\n' "$1" "$2" "$deps" > $d/manifest.gpm.cfg
tar czf /srv/$1-1.0.0.gpkg -C $w $1-1.0.0
rm -rf $w
}
mkdir -p /srv/src
# alpmusl: Alpine's own loader/libc, so T can run Alpine's busybox
mkdir -p /srv/src/alpmusl/usr/lib
cp /lib/ld-musl-x86_64.so.1 /srv/src/alpmusl/usr/lib/
ln -s ld-musl-x86_64.so.1 /srv/src/alpmusl/usr/lib/libc.musl-x86_64.so.1
# imgbase: a binary, a relative and an ABSOLUTE package symlink, config
mkdir -p /srv/src/imgbase/usr/bin /srv/src/imgbase/usr/lib /srv/src/imgbase/etc
cp /bin/busybox /srv/src/imgbase/usr/bin/busybox
echo lib > /srv/src/imgbase/usr/lib/libimg.so.1.0
ln -s libimg.so.1.0 /srv/src/imgbase/usr/lib/libimg.so.1
ln -s /usr/lib/libimg.so.1.0 /srv/src/imgbase/usr/lib/libimg-abs.so
echo "image config" > /srv/src/imgbase/etc/imgbase.conf
# imgextra: extra repo, depends on imgbase (which the HOST doesn't have)
mkdir -p /srv/src/imgextra/usr/bin; echo extra > /srv/src/imgextra/usr/bin/imgextra
# shared: installed on the host AND in the image
mkdir -p /srv/src/shared/usr/share/shared; echo shared > /srv/src/shared/usr/share/shared/data
# displacer: replaces a foreign file in T with -O
mkdir -p /srv/src/displacer/usr/bin; echo pkg > /srv/src/displacer/usr/bin/displaceme
mkpkg alpmusl base; mkpkg imgbase base; mkpkg imgextra extra "imgbase:1.0.0"
mkdir -p /srv/src/noop/usr/share/noop; echo noop > /srv/src/noop/usr/share/noop/data
mkpkg shared base; mkpkg displacer base; mkpkg noop extra
# Driver: img.lua ROOT ACTION ARGS. Prints the status as a number.
cat > /tmp/img.lua <<'EOF'
package.path = "/app/?.lua;" .. package.path
local ffi = require("ffi"); require("lib/glacier_cdef")
local istore = ffi.load("/app/lib/glacier/libglacier_istoreutils.so")
local txn = ffi.load("/app/lib/glacier/libglacier_transaction.so")
local root, action = arg[1], arg[2]
if action == "init" then
print(tonumber(istore.gl_init_sys_at(root, false)))
elseif action == "install" or action == "install-O" or action == "remove" then
local ctx = ffi.new("gl_context_t")
local st = txn.gl_init_stage_context_at(ctx, ffi.C.GL_SCOPE_SYS, 0, root)
if st ~= 0 then print("stage " .. tonumber(st)); os.exit(1) end
ctx.overwrite = action == "install-O" and 1 or 0
for i = 3, #arg do
local r
if action == "remove" then
local repo, name = arg[i]:match("^(.-)::(.*)$")
r = istore.gl_remove_pkg(ctx, name, repo)
else
r = istore.gl_install_pkg(ctx, arg[i])
end
if r ~= 0 then print("op " .. tonumber(r)); txn.gl_abort_transaction(ctx); os.exit(1) end
end
local c = txn.gl_commit_transaction(ctx)
if c ~= 0 then txn.gl_abort_transaction(ctx) end
print(tonumber(c))
elseif action == "usr-live" then
local ctx = ffi.new("gl_context_t")
print(tonumber(txn.gl_init_live_context_at(ctx, ffi.C.GL_SCOPE_USR, 1000, root)))
elseif action == "usr-stage" then
local ctx = ffi.new("gl_context_t")
print(tonumber(txn.gl_init_stage_context_at(ctx, ffi.C.GL_SCOPE_USR, 1000, root)))
elseif action == "sys-live" then
local ctx = ffi.new("gl_context_t")
print(tonumber(txn.gl_init_live_context_at(ctx, ffi.C.GL_SCOPE_SYS, 0, root)))
end
EOF
img() { luajit /tmp/img.lua "$@" 2>&1 | sed 's/\x1b\[[0-9;]*m//g' | tail -1; }
imgout() { luajit /tmp/img.lua "$@" 2>&1 | sed 's/\x1b\[[0-9;]*m//g'; }
# --- the host: its own glacier system, with `shared` installed
cd /app && ./syspkg -n >/dev/null 2>&1
printf 'sha256:%s\n' "$(sha256sum /srv/shared-1.0.0.gpkg | cut -d' ' -f1)" > /srv/shared-1.0.0.gpkg.sha256
gsign -S -s /root/glacier-test.sec -m /srv/shared-1.0.0.gpkg.sha256 >/dev/null
echo y | ./syspkg -l /srv/shared-1.0.0.gpkg >/dev/null 2>&1
check "host has shared installed" test -L /usr/share/shared/data
# uid 1000 gets a real base, so a user-scope refusal below can only come
# from the install root.
./gstore -n 1000 >/dev/null 2>&1
snap() {
find /usr /glacier /etc -xdev -printf '%p %y %m %U %G %s %T@ %l\n' 2>/dev/null | sort
find /usr /glacier /etc -xdev -type f -exec sha256sum {} + 2>/dev/null | sort
}
snap > /tmp/before
# --- the image
mkdir -p $T; chmod 755 $T
mkdir -p $T/usr/bin; echo foreign > $T/usr/bin/displaceme
echo "== build"
check "gl_init_sys_at T" test "$(img $T init)" = 0
check "T has the merged-/usr tree" test "$(readlink $T/bin)" = usr/bin
check "T has its system index" test -L $T/glacier/sys/index/current
check "install alpmusl + imgbase + shared into T" test "$(img $T install /srv/alpmusl-1.0.0.gpkg /srv/imgbase-1.0.0.gpkg /srv/shared-1.0.0.gpkg)" = 0
echo "== links say runtime paths"
check "T/usr/bin/busybox -> runtime store path" \
test "$(readlink $T/usr/bin/busybox)" = "$S/base/imgbase/imgbase-1.0.0/usr/bin/busybox"
check "the absolute package symlink is kept verbatim" \
test "$(readlink $T$S/base/imgbase/imgbase-1.0.0/usr/lib/libimg-abs.so)" = /usr/lib/libimg.so.1.0
check "no link anywhere in T mentions T" sh -c "! find $T -type l -exec readlink {} \; | grep -q '^$T'"
check "chroot T runs busybox through T's own loader" sh -c "chroot $T /usr/bin/busybox echo booted | grep -qx booted"
check "chroot T resolves the absolute package symlink" sh -c "chroot $T /usr/bin/busybox cat /usr/lib/libimg-abs.so | grep -qx lib"
echo "== /etc"
check "config copied into T/etc" sh -c "grep -qx 'image config' $T/etc/imgbase.conf"
check "not into the host's /etc" test ! -e /etc/imgbase.conf
echo "== dependencies are checked against T"
check "imgextra (needs imgbase, which only T has) installs" test "$(img $T install /srv/imgextra-1.0.0.gpkg)" = 0
check "imgextra linked in T's sys links" test -L $T/glacier/sys/links/bin/imgextra
OUT=$(imgout $T remove base::imgbase)
check "removing imgbase from T is refused for T's dependent" sh -c 'echo "$1" | grep -qxF "[x] Removing base::imgbase breaks extra::imgextra."' _ "$OUT"
check "imgbase still in T" test -d $T$S/base/imgbase
echo "== pruning judges T's links against T's store"
check "imgbase's links survived the second commit (host lacks imgbase)" test -L $T/usr/bin/busybox
check "remove shared from T" test "$(img $T remove base::shared)" = 0
check "T's shared link pruned (although the host has shared)" sh -c "! test -e $T/usr/share/shared/data -o -L $T/usr/share/shared/data"
echo "== -O: displaced originals keyed by runtime path"
check "install-O displacer into T" test "$(img $T install-O /srv/displacer-1.0.0.gpkg)" = 0
check "original kept under the runtime key" sh -c "grep -qx foreign $T$S/.displaced/usr/bin/displaceme"
check "no T-prefixed key" test ! -e "$T$S/.displaced$T"
check "an unrelated later commit to T" test "$(img $T install /srv/noop-1.0.0.gpkg)" = 0
check "the displacing link survived it (host lacks displacer)" \
test "$(readlink $T/usr/bin/displaceme)" = "$S/base/displacer/displacer-1.0.0/usr/bin/displaceme"
check "the original is still kept aside" sh -c "grep -qx foreign $T$S/.displaced/usr/bin/displaceme"
check "remove displacer from T" test "$(img $T remove base::displacer)" = 0
check "original restored in T" sh -c "grep -qx foreign $T/usr/bin/displaceme"
echo "== user scope refuses an install root"
check "live context: refused" test "$(img $T usr-live)" = -1
check "stage context: refused (GL_TXN_ERR_PERM)" test "$(img $T usr-stage)" = 3
check "relative install root refused" test "$(img mnt/img sys-live)" = -1
check "install root with .. refused" test "$(img /mnt/../etc sys-live)" = -1
check "/ is the running system" test "$(img / sys-live)" = 0
echo "== the host"
snap > /tmp/after
check "host /usr, /glacier and /etc are byte-identical" cmp -s /tmp/before /tmp/after
cmp -s /tmp/before /tmp/after || diff /tmp/before /tmp/after | head -20
echo
[ $FAILS -eq 0 ] && echo "ALL PASSED" || echo "$FAILS FAILED"
exit $FAILS