425 lines
25 KiB
Bash
425 lines
25 KiB
Bash
#!/bin/sh
|
|
# Source builds through syspkg/gpkg -f/-u (BUILD_DESIGN.txt; steps 3-4):
|
|
# - a recipe from a NAME-src repo is built in gsandbox and installed
|
|
# like a fetched package: summary and prompt BEFORE building, the
|
|
# patches applied, the manifest the build was handed, .glacier-src;
|
|
# - a name served by several repositories is asked about; Enter takes
|
|
# the first, a bad answer refuses;
|
|
# - TRAITS: recipe defaults, /etc/glacier/glacier.conf, per-package
|
|
# files (an unknown trait refused), the user's own files for gpkg;
|
|
# - -u stays on source, and rebuilds when the traits change;
|
|
# - syspkg builds as BUILD_USER (required), gpkg as the user;
|
|
# - PREFIX: a package is built for where its usr/ is linked
|
|
# (/glacier/sys/links, the user's links, /usr for base) and still
|
|
# packed as usr/; during the build PREFIX resolves to the layers;
|
|
# - kept packages: an installed source build's .gpkg is kept, and a
|
|
# later build uses it (and what it depends on) as a layer; kept
|
|
# only while that version is installed;
|
|
# - build output on the terminal (and in the log) unless -q/--quiet;
|
|
# - refusals: a source with the wrong hash, a failing build, a build
|
|
# that produces another package, a build dependency no binary repo
|
|
# has, an untrusted per-package file, -R.
|
|
# Needs what sandbox_alpine.sh needs, with /glacier off Docker's overlay:
|
|
#
|
|
# docker run --rm --security-opt seccomp=unconfined \
|
|
# --security-opt apparmor=unconfined --security-opt systempaths=unconfined \
|
|
# --tmpfs /glacier:exec,mode=755 \
|
|
# -v "$PWD/tests/build_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"; }
|
|
rc() { [ "$RC" = "$1" ]; }
|
|
hr() { echo; echo "== $*"; }
|
|
export PATH=/app:$PATH
|
|
|
|
K=/etc/glacier/keys
|
|
CONF=/etc/glacier/repos.conf
|
|
GCONF=/etc/glacier/glacier.conf
|
|
XSEC=/root/extrakey.sec
|
|
SSEC=/root/srckey.sec
|
|
E=/srv/extra
|
|
S=/srv/extra-src
|
|
SRC=/srv/sources
|
|
IDX=/glacier/sys/index/current
|
|
BUILD=/glacier/sys/build
|
|
BS=/srv/base-src
|
|
mkdir -p $E $S $SRC $BS && chmod 755 /srv $E $S $SRC $BS
|
|
|
|
gsign -G -p $K/extrakey.pub -s $XSEC -c extrakey >/dev/null
|
|
gsign -G -p $K/srckey.pub -s $SSEC -c srckey >/dev/null
|
|
rconf() { # BASE-KEYS
|
|
printf 'repos = (\n%s\n%s\n%s\n%s\n);\n' \
|
|
" { name = \"base\"; keys = [ $1 ]; }," \
|
|
' { name = "extra"; url = "file:///srv/extra"; keys = [ "extrakey" ]; },' \
|
|
' { name = "extra-src"; url = "file:///srv/extra-src"; keys = [ "srckey" ]; },' \
|
|
' { name = "base-src"; url = "file:///srv/base-src"; keys = [ "srckey" ]; }' > $CONF
|
|
chmod 644 $CONF
|
|
}
|
|
rconf '"glacier-test"'
|
|
adduser -S -D -H -s /sbin/nologin gbuild
|
|
gconf() { printf 'KEEP_OLD = 1;\n%s\n' "$1" > $GCONF; chmod 644 $GCONF; }
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "gbuild";'
|
|
|
|
# The binary repo: a toolchain (Alpine's build-base, busybox for /bin/sh)
|
|
# and a runtime dependency.
|
|
/app/tests/mkroot -o $E -r build-base -r busybox -p busybox toolchain 1.0.0 extra >/dev/null
|
|
/app/tests/mkpkg -o $E hidep 1.0.0 extra >/dev/null
|
|
/app/tests/mkpkg -o $E loudlib 1.0.0 extra >/dev/null
|
|
/app/tests/mkpkg -o $E both 9.0.0 extra >/dev/null
|
|
/app/tests/mkpkg -o $E twin 1.0.0 extra >/dev/null
|
|
|
|
# A source tarball: hello prints "hello", "HELLO" with LOUD=1.
|
|
mksrc() { # NAME VER [MAKEFILE-EXTRA]
|
|
d=/tmp/src/$1-$2
|
|
rm -rf $d && mkdir -p $d
|
|
printf '#include <stdio.h>\nint main(void) {\n#ifdef LOUD\n\tputs("HELLO");\n#else\n\tputs("hello");\n#endif\n\treturn 0;\n}\n' > $d/hello.c
|
|
printf 'CFLAGS += $(if $(LOUD),-DLOUD)\n%s: hello.c\n\t$(CC) $(CFLAGS) -o %s hello.c\ninstall:\n\tinstall -D -m 755 %s $(DESTDIR)$(PREFIX)/bin/%s\n%s\n' \
|
|
"$1" "$1" "$1" "$1" "${3:-}" > $d/Makefile
|
|
tar czf $SRC/$1-$2.tar.gz -C /tmp/src $1-$2
|
|
sha256sum $SRC/$1-$2.tar.gz | cut -c1-64
|
|
}
|
|
# A recipe bundle in the -src repo: NAME VER SHA [EXTRA-FIELDS] [BUILD-FILE]
|
|
mkrecipe() {
|
|
t=/tmp/rcp/$1-$2
|
|
rm -rf $t && mkdir -p $t/patches
|
|
printf 'NAME = "%s"; VER = "%s"; REPO = "extra"; DESC = "test \\"%s\\""; MAINT = "m@x"; COPYRIGHT = "MIT";\nSOURCES = ( { URL = "file://%s/%s-%s.tar.gz"; SHA256 = "sha256:%s"; } );\nBUILD = "make";\nTRAITS = ( { NAME = "loud"; DEFAULT = false; ON = [ "LOUD=1" ]; } );\n%s\n' \
|
|
"$1" "$2" "$1" "$SRC" "$1" "$2" "$3" "${4:-}" > $t/recipe
|
|
[ -n "${5:-}" ] && printf '%s\n' "$5" > $t/build
|
|
rmdir $t/patches 2>/dev/null
|
|
tar czf $S/$1-$2.grcp -C /tmp/rcp $1-$2
|
|
}
|
|
publish() {
|
|
grepo -s $XSEC -r extra $E | grep -v Wrote; grepo -s $SSEC -r extra-src $S | grep -v Wrote
|
|
grepo -s $SSEC -r base-src $BS | grep -v Wrote
|
|
}
|
|
|
|
# hello 1.0.0, patched to greet glacier, depending on hidep.
|
|
H=$(mksrc hello 1.0.0)
|
|
t=/tmp/rcp/hello-1.0.0
|
|
rm -rf $t && mkdir -p $t/patches
|
|
printf 'NAME = "hello"; VER = "1.0.0"; REPO = "extra"; DESC = "say \\"hi\\""; MAINT = "m@x"; COPYRIGHT = "MIT";\nSOURCES = ( { URL = "file://%s/hello-1.0.0.tar.gz"; SHA256 = "sha256:%s"; } );\nPATCHES = [ "01-glacier.patch" ];\nBUILD = "make";\nTRAITS = ( { NAME = "loud"; DEFAULT = false; ON = [ "LOUD=1" ]; } );\nDEPS = ( { NAME = "hidep"; VER = "1.0.0"; }, { NAME = "loudlib"; VER = "1.0.0"; IF = "loud"; } );\n' "$SRC" "$H" > $t/recipe
|
|
cat > $t/patches/01-glacier.patch <<'EOF'
|
|
--- a/hello.c
|
|
+++ b/hello.c
|
|
@@ -5,3 +5,3 @@
|
|
#else
|
|
- puts("hello");
|
|
+ puts("hello, glacier");
|
|
#endif
|
|
EOF
|
|
tar czf $S/hello-1.0.0.grcp -C /tmp/rcp hello-1.0.0
|
|
mkrecipe both 1.0.0 "$(mksrc both 1.0.0)"
|
|
mkrecipe badhash 1.0.0 "$(printf '%064d' 0)"
|
|
mksrc badhash 1.0.0 >/dev/null
|
|
mkrecipe broken 1.0.0 "$(mksrc broken 1.0.0 'broken: ; false')" '' 'compile() { make broken; }'
|
|
mkrecipe evil 1.0.0 "$(mksrc evil 1.0.0)" '' 'package() {
|
|
mkdir -p /tmp/p/evil-1.0.0/files/usr/bin
|
|
echo x > /tmp/p/evil-1.0.0/files/usr/bin/evil
|
|
printf "PKG_NAME = \"evil\"; PKG_VER = \"1.0.0\"; PKG_REPO = \"base\"; PKG_DEPS = (); PKG_CONFS = ();\n" > /tmp/p/evil-1.0.0/manifest.gpm.cfg
|
|
tar czf /.glacier/out/evil-1.0.0.gpkg -C /tmp/p evil-1.0.0
|
|
exit 0
|
|
}'
|
|
mkrecipe core 1.0.0 "$(mksrc core 1.0.0)" '' 'package() {
|
|
make install PREFIX="$PREFIX" DESTDIR="$DESTDIR"
|
|
mkdir -p "$DESTDIR$PREFIX/share" && echo "$PREFIX" > "$DESTDIR$PREFIX/share/core.prefix"
|
|
}'
|
|
sed -i 's/REPO = "extra"/REPO = "base"/' /tmp/rcp/core-1.0.0/recipe
|
|
tar czf $BS/core-1.0.0.grcp -C /tmp/rcp core-1.0.0 && rm $S/core-1.0.0.grcp
|
|
# where: a script with its data file's path compiled in. Its prepare
|
|
# fails unless PREFIX leads to the layers during the build.
|
|
mkrecipe where 1.0.0 "$(mksrc where 1.0.0)" 'BUILD = "hooks";' 'prepare() { [ -x "$PREFIX/bin/make" ]; }
|
|
package() {
|
|
mkdir -p "$DESTDIR$PREFIX/bin" "$DESTDIR$PREFIX/share/where"
|
|
echo here > "$DESTDIR$PREFIX/share/where/data"
|
|
printf "#!/bin/sh\ncat %s/share/where/data\n" "$PREFIX" > "$DESTDIR$PREFIX/bin/where"
|
|
chmod 755 "$DESTDIR$PREFIX/bin/where"
|
|
}'
|
|
sed -i 's/^BUILD = "make";$//' /tmp/rcp/where-1.0.0/recipe && tar czf $S/where-1.0.0.grcp -C /tmp/rcp where-1.0.0
|
|
mkrecipe split 1.0.0 "$(mksrc split 1.0.0)" '' 'package() {
|
|
make install PREFIX="$PREFIX" DESTDIR="$DESTDIR"
|
|
mkdir -p "$DESTDIR/usr/share" && echo x > "$DESTDIR/usr/share/split"
|
|
}'
|
|
# srclib: only a recipe, depending on hidep. srcapp needs both in its
|
|
# layers to build.
|
|
mkrecipe srclib 1.0.0 "$(mksrc srclib 1.0.0)" 'DEPS = ( { NAME = "hidep"; VER = "1.0.0"; } );' 'package() {
|
|
make install PREFIX="$PREFIX" DESTDIR="$DESTDIR"
|
|
mkdir -p "$DESTDIR$PREFIX/share/srclib" && echo yes > "$DESTDIR$PREFIX/share/srclib/marker"
|
|
}'
|
|
mkrecipe srcapp 1.0.0 "$(mksrc srcapp 1.0.0)" 'DEPS = ( { NAME = "srclib"; VER = "1.0.0"; } );' 'prepare() { [ -f /usr/share/srclib/marker ] && [ -x /usr/bin/hidep ]; }'
|
|
mkrecipe twin 1.0.0 "$(mksrc twin 1.0.0)"
|
|
mkrecipe needy 1.0.0 "$(mksrc needy 1.0.0)" 'BUILD_DEPS = ( { NAME = "nothere"; VER = "1.0.0"; } );'
|
|
publish
|
|
|
|
syspkg -n >/dev/null
|
|
yes_to() { sh -c "printf '$1' | $2"; }
|
|
|
|
hr "syspkg -f of a recipe"
|
|
R yes_to 'y\n' 'syspkg -f hello'
|
|
check "built and installed" has "[✓] Completed with no errors."
|
|
check "...exit 0" rc 0
|
|
check "the summary marks the build, its traits off by default" has " * extra-src::hello 1.0.0 [-loud] (build)"
|
|
check "...and the binary dependency" has " * extra::hidep 1.0.0 (dependency)"
|
|
check "...the prompt came before the build" sh -c 'echo "$0" | grep -n "Proceed\|Building extra-src" | head -1 | grep -q Proceed' "$OUT"
|
|
check "the build is announced" has "[i] Building extra-src::hello 1.0.0 [-loud]..."
|
|
check "...and done" has "[✓] Built extra-src::hello 1.0.0."
|
|
check "installed as extra::hello" grep -q "^extra::hello::1.0.0::explicit$" $IDX
|
|
check "...with its dependency, auto" grep -q "^extra::hidep::1.0.0::auto$" $IDX
|
|
check "...not the one only loud needs" sh -c "! grep -q loudlib $IDX"
|
|
check "...the patch applied" [ "$(/glacier/sys/links/bin/hello)" = "hello, glacier" ]
|
|
V=/glacier/sys/store/extra/hello/hello-1.0.0
|
|
check "...recorded as built from extra-src" [ "$(cat $V/.glacier-src)" = extra-src ]
|
|
check "...its manifest has PKG_TRAITS" grep -qF 'PKG_TRAITS = [ "-loud" ];' $V/.glacier-manifest
|
|
check "...and the recipe's DESC, quoted" grep -qF 'PKG_DESC = "say \"hi\"";' $V/.glacier-manifest
|
|
check "the layer belongs to BUILD_USER" [ "$(stat -c %U $BUILD/layers/toolchain-1.0.0-*)" = gbuild ]
|
|
check "...which owns layers/, 0700" [ "$(stat -c '%U %a' $BUILD/layers)" = "gbuild 700" ]
|
|
check "the build's in/work/out dirs are gone" [ -z "$(ls $BUILD | grep -E '^(in|work|out)-')" ]
|
|
check "the log is kept" grep -q "==> Done" $BUILD/logs/hello-1.0.0.log
|
|
check "...and the build's output was on the terminal" has "==> Applying 01-glacier.patch"
|
|
check "...the sources cached by hash" [ -f $BUILD/sources/$H ]
|
|
check "the cached bundle is deleted" [ ! -e /glacier/sys/cache/extra-src/hello-1.0.0.grcp ]
|
|
check "the store copy is root's, as any install" [ "$(stat -c %u /glacier/sys/store/extra/hello/hello-1.0.0/usr/bin/hello)" = 0 ]
|
|
|
|
hr "declining builds nothing"
|
|
rm $BUILD/logs/hello-1.0.0.log
|
|
R yes_to 'n\n' 'syspkg -f -O hello'
|
|
check "nothing built" sh -c "[ ! -e $BUILD/logs/hello-1.0.0.log ]"
|
|
check "...nothing said about building" lacks "Building"
|
|
|
|
hr "traits"
|
|
mkdir -p /etc/glacier/config
|
|
printf 'TRAITS = [ "lod" ];\n' > /etc/glacier/config/hello.conf
|
|
R yes_to 'y\n' 'syspkg -u hello'
|
|
check "an unknown trait in a per-package file is refused" has "[x] /etc/glacier/config/hello.conf: hello has no trait lod."
|
|
check "...exit 1, before the prompt" sh -c "[ $RC = 1 ]" && check "...no prompt" lacks "Proceed?"
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "gbuild"; TRAITS = [ "loud", "x11" ];'
|
|
printf 'TRAITS = [ "-loud" ];\n' > /etc/glacier/config/hello.conf
|
|
R yes_to 'y\n' 'syspkg -u'
|
|
check "the per-package file beats glacier.conf: nothing to rebuild" has "Nothing to do."
|
|
rm /etc/glacier/config/hello.conf
|
|
R yes_to 'y\n' 'syspkg -u'
|
|
check "glacier.conf turns loud on (x11, unknown to the recipe, ignored): a rebuild" has " * extra-src::hello 1.0.0 (traits) [+loud] (build)"
|
|
check "...installed" rc 0
|
|
check "...built with LOUD" [ "$(/glacier/sys/links/bin/hello)" = "HELLO" ]
|
|
check "...with the dependency loud needs" grep -q "^extra::loudlib::1.0.0::auto$" $IDX
|
|
check "...in its manifest" grep -qF '{ PKG_NAME = "loudlib"; PKG_VER = "1.0.0"; }' $V/.glacier-manifest
|
|
check "...still marked as built from source" [ "$(cat $V/.glacier-src)" = extra-src ]
|
|
check "...PKG_TRAITS updated" grep -qF 'PKG_TRAITS = [ "loud" ];' $V/.glacier-manifest
|
|
R yes_to 'y\n' 'syspkg -u'
|
|
check "unchanged traits: nothing to do" has "Nothing to do."
|
|
printf 'TRAITS = [ "-loud" ];\n' > /etc/glacier/config/hello.conf
|
|
chmod 666 /etc/glacier/config/hello.conf
|
|
R yes_to 'y\n' 'syspkg -u'
|
|
check "a world-writable per-package file is refused" has "[x] Refusing /etc/glacier/config/hello.conf: /etc/glacier/config/hello.conf is not root-owned, or is group/world-writable."
|
|
rm /etc/glacier/config/hello.conf
|
|
printf 'TRAITS = [ "loud" ]; COLOR = "red";\n' > /etc/glacier/config/hello.conf
|
|
R yes_to 'y\n' 'syspkg -u'
|
|
check "a per-package file with an unknown key is malformed" has "[x] Malformed /etc/glacier/config/hello.conf."
|
|
rm /etc/glacier/config/hello.conf
|
|
|
|
hr "-u stays on source"
|
|
H11=$(mksrc hello 1.1.0)
|
|
sed "s/1\.0\.0/1.1.0/g; s/$H/$H11/" /tmp/rcp/hello-1.0.0/recipe > /tmp/r.new
|
|
rm -rf /tmp/rcp/hello-1.1.0 && cp -a /tmp/rcp/hello-1.0.0 /tmp/rcp/hello-1.1.0 && mv /tmp/r.new /tmp/rcp/hello-1.1.0/recipe
|
|
sed -i 's/VER = "1.1.0"; }/VER = "1.0.0"; }/g; s/VER = "1.1.0"; IF/VER = "1.0.0"; IF/' /tmp/rcp/hello-1.1.0/recipe
|
|
tar czf $S/hello-1.1.0.grcp -C /tmp/rcp hello-1.1.0
|
|
/app/tests/mkpkg -o $E hello 2.0.0 extra >/dev/null
|
|
publish
|
|
R yes_to 'y\n' 'syspkg -u hello'
|
|
check "a newer recipe is built, not extra's binary 2.0.0" has " * extra-src::hello 1.0.0 -> 1.1.0 [+loud] (build)"
|
|
check "...installed" grep -q "^extra::hello::1.1.0::explicit$" $IDX
|
|
check "...the old version backed up" [ -f /glacier/sys/backup/extra/hello/hello-1.0.0.gpkg ]
|
|
check "...its new package kept for builds" [ -f $BUILD/packages/extra@hello-1.1.0.gpkg ]
|
|
check "...the old one's deleted" [ ! -e $BUILD/packages/extra@hello-1.0.0.gpkg ]
|
|
check "...still on source" [ "$(cat /glacier/sys/store/extra/hello/hello-1.1.0/.glacier-src)" = extra-src ]
|
|
|
|
hr "PREFIX"
|
|
R yes_to 'y\n' 'syspkg -f where'
|
|
check "built for /glacier/sys/links: finds its data through the links" [ "$(/glacier/sys/links/bin/where)" = here ]
|
|
check "...the path compiled in" grep -q "^cat /glacier/sys/links/share/where/data$" /glacier/sys/links/bin/where
|
|
check "...packed as usr/, as any package" [ -f /glacier/sys/store/extra/where/where-1.0.0/usr/share/where/data ]
|
|
check "...nothing else at the top" [ "$(ls /glacier/sys/store/extra/where/where-1.0.0)" = usr ]
|
|
R yes_to 'y\n' 'syspkg -f split'
|
|
check "a build installing into PREFIX and /usr both fails" has "[x] Building extra-src::split 1.0.0 failed."
|
|
check "...the log says why" grep -q "split installed into both /glacier/sys/links and /usr" $BUILD/logs/split-1.0.0.log
|
|
|
|
hr "kept packages"
|
|
P=$BUILD/packages
|
|
check "a source build's package is kept, root's 0644" [ "$(stat -c '%u %a' $P/extra@where-1.0.0.gpkg)" = "0 644" ]
|
|
check "...byte for byte what was installed" sh -c "tar xzOf $P/extra@where-1.0.0.gpkg where-1.0.0/files/usr/bin/where | cmp -s - /glacier/sys/store/extra/where/where-1.0.0/usr/bin/where"
|
|
check "...not a failed one" [ ! -e $P/extra@split-1.0.0.gpkg ]
|
|
R yes_to 'y\n' 'syspkg -q -f srclib'
|
|
check "srclib (no binary anywhere) built and installed" rc 0
|
|
check "...-q: no build output on the terminal" lacks "==> "
|
|
check "...but the build is still announced" has "[✓] Built extra-src::srclib 1.0.0."
|
|
check "...and logged" grep -q "==> Done" $BUILD/logs/srclib-1.0.0.log
|
|
R yes_to 'y\n' 'syspkg --quiet -f srcapp'
|
|
check "--quiet too" lacks "==> "
|
|
check "a build needing an installed source build: built" has "[✓] Built extra-src::srcapp 1.0.0."
|
|
check "...installed" grep -q "^extra::srcapp::1.0.0::explicit$" $IDX
|
|
check "...the kept package was its layer" sh -c "ls $BUILD/layers | grep -q '^srclib-1.0.0-'"
|
|
printf 'TRAITS = [ "-loud" ];\n' > /etc/glacier/config/srcapp.conf
|
|
R yes_to 'y\n' 'syspkg -u srcapp'
|
|
check "-u rebuilds it (traits changed)" has " * extra-src::srcapp 1.0.0 (traits) [-loud] (build)"
|
|
check "...exit 0" rc 0
|
|
mv $P/extra@srclib-1.0.0.gpkg /root/kept.bak
|
|
rm /etc/glacier/config/srcapp.conf
|
|
R yes_to 'y\n' 'syspkg -u srcapp'
|
|
mv /root/kept.bak $P/extra@srclib-1.0.0.gpkg
|
|
check "without its kept package, srclib can't be a layer" has "[x] extra-src::srcapp 1.0.0 needs srclib 1.0.0 or later to build, and no binary repository has it."
|
|
R yes_to 'y\n' 'syspkg -x srcapp'
|
|
check "removing srcapp deletes its kept package" [ ! -e $P/extra@srcapp-1.0.0.gpkg ]
|
|
check "...not srclib's, still installed" [ -f $P/extra@srclib-1.0.0.gpkg ]
|
|
R yes_to 'y\n' 'syspkg -x srclib'
|
|
check "removing srclib deletes its own" [ ! -e $P/extra@srclib-1.0.0.gpkg ]
|
|
check "...others stay" [ -f $P/extra@where-1.0.0.gpkg ]
|
|
R yes_to '2\ny\n' 'syspkg -f twin'
|
|
check "twin built from source: kept" [ -f $P/extra@twin-1.0.0.gpkg ]
|
|
R yes_to '1\ny\n' 'syspkg -f -O twin'
|
|
check "the same version reinstalled from the binary repo" [ "$(/glacier/sys/links/bin/twin)" = "twin 1.0.0 says hi" ]
|
|
check "...no longer kept" [ ! -e $P/extra@twin-1.0.0.gpkg ]
|
|
|
|
hr "the repository question"
|
|
R yes_to '\ny\n' 'syspkg -f both'
|
|
check "both repos serving a name: asked" has "[i] both is available from more than one repository:"
|
|
check "...the binary first (repos.conf order)" has " 1) extra::both 9.0.0"
|
|
check "...then the recipe" has " 2) extra-src::both 1.0.0 [+loud] (build)"
|
|
check "...Enter takes the first" grep -q "^extra::both::9.0.0::explicit$" $IDX
|
|
check "...not marked as built" [ ! -e /glacier/sys/store/extra/both/both-9.0.0/.glacier-src ]
|
|
check "...nor kept" [ ! -e $BUILD/packages/extra@both-9.0.0.gpkg ]
|
|
R yes_to '2\ny\n' 'syspkg -f -O both'
|
|
check "2 builds the recipe (replacing the binary under -O)" grep -q "^extra::both::1.0.0::explicit$" $IDX
|
|
check "...marked as built" [ "$(cat /glacier/sys/store/extra/both/both-1.0.0/.glacier-src)" = extra-src ]
|
|
check "...and kept" [ -f $BUILD/packages/extra@both-1.0.0.gpkg ]
|
|
R yes_to '3\n' 'syspkg -f -O both'
|
|
check "an answer out of range is refused" has "[x] Invalid selection."
|
|
check "...exit 1" rc 1
|
|
R yes_to 'x\n' 'syspkg -f -O both'
|
|
check "a non-number is refused" has "[x] Invalid selection."
|
|
R sh -c 'syspkg -f -O both < /dev/null'
|
|
check "end of input is refused" has "[x] Invalid selection."
|
|
|
|
hr "refused builds"
|
|
R yes_to 'y\n' 'syspkg -f badhash'
|
|
check "a source with the wrong hash" has "[x] A source of extra-src::badhash 1.0.0 does not match its hash."
|
|
check "...exit 1, nothing installed" sh -c "[ $RC = 1 ] && ! grep -q badhash $IDX"
|
|
R yes_to 'y\n' 'syspkg -f broken'
|
|
check "a failing build" has "[x] Building extra-src::broken 1.0.0 failed. Log: $BUILD/logs/broken-1.0.0.log"
|
|
check "...exit 1, nothing installed" sh -c "[ $RC = 1 ] && ! grep -q broken $IDX"
|
|
check "...the log says why" grep -q "Error\|error" $BUILD/logs/broken-1.0.0.log
|
|
check "...its dirs removed" [ -z "$(ls $BUILD | grep -E '^(in|work|out)-')" ]
|
|
R yes_to 'y\n' 'syspkg -f evil'
|
|
check "a build that produces another package" has "[x] extra-src::evil 1.0.0: the build produced another package."
|
|
check "...nothing installed" sh -c "! grep -q evil $IDX && [ ! -e /usr/bin/evil ]"
|
|
# An index entry that disagrees with its bundle's recipe (signed all
|
|
# the same): the recipe has a dependency the index left out.
|
|
mkrecipe liar 1.0.0 "$(mksrc liar 1.0.0)" 'DEPS = ( { NAME = "hidep"; VER = "1.0.0"; } );'
|
|
publish
|
|
SER=$(sed -n 's/^SERIAL = \([0-9]*\)L;$/\1/p' $S/repo.idx)
|
|
awk -v s=$((SER + 1)) '/^SERIAL/ { print "SERIAL = " s "L;"; next } /NAME = "liar"/ { liar = 1 } liar && /DEPS = / { sub(/DEPS = \(.*\);/, "DEPS = ();"); liar = 0 } { print }' $S/repo.idx > /tmp/idx && mv /tmp/idx $S/repo.idx
|
|
gsign -S -s $SSEC -m $S/repo.idx >/dev/null
|
|
R yes_to 'y\n' 'syspkg -f liar'
|
|
check "a recipe that disagrees with its index entry" has "[x] extra-src::liar 1.0.0 does not match its index."
|
|
check "...nothing installed" sh -c "! grep -q liar $IDX"
|
|
chmod 666 /app/lib/build-driver.sh
|
|
R yes_to '2\ny\n' 'syspkg -f -O hello'
|
|
chmod 644 /app/lib/build-driver.sh
|
|
check "a world-writable build driver is refused" has "[x] Refusing /app/lib/build-driver.sh: /app/lib/build-driver.sh is not root-owned, or is group/world-writable."
|
|
check "...before the prompt" lacks "Proceed?"
|
|
R yes_to 'y\n' 'syspkg -f needy'
|
|
check "a build dependency no binary repo has" has "[x] extra-src::needy 1.0.0 needs nothere 1.0.0 or later to build, and no binary repository has it."
|
|
check "...refused before the prompt" lacks "Proceed?"
|
|
gconf 'BUILD_ROOT = [ "toolchain" ];'
|
|
R yes_to '2\ny\n' 'syspkg -f -O hello'
|
|
check "BUILD_USER unset: refused" has "[x] BUILD_USER is not set in /etc/glacier/glacier.conf."
|
|
check "...before the prompt" lacks "Proceed?"
|
|
gconf 'BUILD_USER = "gbuild";'
|
|
R yes_to '2\ny\n' 'syspkg -f -O hello'
|
|
check "BUILD_ROOT unset: refused" has "[x] BUILD_ROOT is not set in /etc/glacier/glacier.conf."
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "root";'
|
|
R yes_to '2\ny\n' 'syspkg -f -O hello'
|
|
check "BUILD_USER = root: refused" has "[x] BUILD_USER in /etc/glacier/glacier.conf must not be root."
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "nosuchuser";'
|
|
R yes_to '2\ny\n' 'syspkg -f -O hello'
|
|
check "BUILD_USER not a user: refused" has "[x] BUILD_USER nosuchuser in /etc/glacier/glacier.conf is not a user."
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "gbuild"; JOBS = 0;'
|
|
R yes_to '2\ny\n' 'syspkg -f -O hello'
|
|
check "JOBS = 0: glacier.conf is malformed" has "[x] Malformed /etc/glacier/glacier.conf."
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "gbuild";'
|
|
mkdir -p /mnt/t && syspkg -R /mnt/t -n >/dev/null
|
|
cp -a /etc/glacier/repos.conf /etc/glacier/keys /mnt/t/etc/glacier/ 2>/dev/null || { mkdir -p /mnt/t/etc/glacier && cp -a /etc/glacier/repos.conf /etc/glacier/keys /mnt/t/etc/glacier/; }
|
|
R yes_to '2\ny\n' 'syspkg -R /mnt/t -f both'
|
|
check "building under -R is refused" has "[x] Building from source under -R is not supported."
|
|
|
|
hr "base-src and the machine key"
|
|
R yes_to 'y\n' 'syspkg -f core'
|
|
check "a base build without the machine key trusted for base is refused" has '[x] base-src::core 1.0.0 [-loud] (build) needs the key "local" trusted for base.'
|
|
check "...before the prompt" lacks "Proceed?"
|
|
check "...having made the machine key" has "[i] Made the machine key /etc/glacier/keys/local.pub."
|
|
check "...its public half 0644" [ "$(stat -c '%u %a' /etc/glacier/keys/local.pub)" = "0 644" ]
|
|
check "...its secret half root's 0600" [ "$(stat -c '%u %a' /glacier/sys/keys/local.sec)" = "0 600" ]
|
|
R yes_to 'y\n' 'syspkg -f core'
|
|
check "...made once" lacks "Made the machine key"
|
|
rconf '"glacier-test", "local"'
|
|
R yes_to 'y\n' 'syspkg -f core'
|
|
check "listed for base: built and installed" grep -q "^base::core::1.0.0::explicit$" $IDX
|
|
check "...linked into /usr, as base is" [ "$(/usr/bin/core)" = hello ]
|
|
check "...marked as built from base-src" [ "$(cat /glacier/sys/store/base/core/core-1.0.0/.glacier-src)" = base-src ]
|
|
check "...built for /usr" [ "$(cat /usr/share/core.prefix)" = /usr ]
|
|
mv /glacier/sys/keys/local.sec /root/local.sec.bak
|
|
printf 'TRAITS = [ "loud" ];\n' > /etc/glacier/config/core.conf
|
|
R yes_to 'y\n' 'syspkg -u core'
|
|
rm /etc/glacier/config/core.conf
|
|
rconf '"glacier-test"'
|
|
mv /root/local.sec.bak /glacier/sys/keys/local.sec
|
|
check "a missing secret half is refused" has "[x] /etc/glacier/keys/local.pub and /glacier/sys/keys/local.sec must both exist, or neither."
|
|
|
|
hr "gpkg: the user's own build"
|
|
U=/glacier/usr/1000
|
|
su glacier -c 'doas /app/gstore -n' >/dev/null 2>&1
|
|
check "gstore -n makes the user's config dir" [ "$(stat -c '%U %a' $U/config)" = "glacier 700" ]
|
|
gconf 'BUILD_ROOT = [ "toolchain" ]; BUILD_USER = "gbuild"; TRAITS = [ "loud" ];'
|
|
R su glacier -c "printf '2\ny\n' | /app/gpkg -f both"
|
|
check "gpkg builds it" has "[✓] Built extra-src::both 1.0.0."
|
|
check "...the system's TRAITS apply" has "[i] Building extra-src::both 1.0.0 [+loud]..."
|
|
check "...installed for the user" grep -q "^extra::both::1.0.0::explicit$" $U/index/current
|
|
check "...the layers are the user's" [ "$(stat -c %U $U/build/layers/toolchain-1.0.0-*)" = glacier ]
|
|
check "...the log too" [ "$(stat -c '%U %a' $U/build/logs/both-1.0.0.log)" = "glacier 600" ]
|
|
check "...it runs" [ "$(su glacier -c "$U/links/bin/both")" = HELLO ]
|
|
check "...kept in the user's base, 0600" [ "$(stat -c '%U %a' $U/build/packages/extra@both-1.0.0.gpkg)" = "glacier 600" ]
|
|
R su glacier -c "printf 'y\n' | /app/gpkg -f where"
|
|
check "gpkg shows the build's output" has "==> Packing where-1.0.0.gpkg"
|
|
R su glacier -c "printf 'y\n' | /app/gpkg -fqO where"
|
|
check "gpkg -q (in a bundle) hides it" lacks "==> "
|
|
check "...and rebuilds" has "[✓] Built extra-src::where 1.0.0."
|
|
R su glacier -c "printf 'y\n' | /app/gpkg --quiet -fO where"
|
|
check "gpkg --quiet too" sh -c '! echo "$0" | grep -q "==> " && echo "$0" | grep -q "Built extra-src::where"' "$OUT"
|
|
R syspkg -h
|
|
check "syspkg -h lists -q" has "{-q --quiet} Hide build output"
|
|
R su glacier -c "/app/gpkg -h"
|
|
check "gpkg -h lists -q" has "{-q --quiet} Hide build output"
|
|
check "gpkg builds for the user's links" [ "$(su glacier -c "$U/links/bin/where")" = here ]
|
|
check "...the path compiled in" grep -q "^cat $U/links/share/where/data$" $U/links/bin/where
|
|
su glacier -c "printf 'TRAITS = [ \"-loud\" ];\n' > $U/config/both.conf"
|
|
R su glacier -c "printf 'y\n' | /app/gpkg -u"
|
|
check "the user's per-package file wins: rebuilt without loud" has " * extra-src::both 1.0.0 (traits) [-loud] (build)"
|
|
check "...installed" [ "$(su glacier -c "$U/links/bin/both")" = hello ]
|
|
su glacier -c "printf 'TRAITS = [ \"loud\" ];\n' > $U/config/glacier.conf; rm $U/config/both.conf"
|
|
R su glacier -c "printf 'y\n' | /app/gpkg -u"
|
|
check "...the user's glacier.conf too" has "[+loud] (build)"
|
|
R su glacier -c "printf 'y\n' | /app/gpkg -f core"
|
|
check "gpkg never builds from base-src" has "[x] core is not in any repository."
|
|
su glacier -c "printf 'BUILD_USER = \"x\";\n' > $U/config/glacier.conf"
|
|
R su glacier -c "printf 'y\n' | /app/gpkg -u"
|
|
check "BUILD_USER in a user's glacier.conf is malformed" has "[x] Malformed $U/config/glacier.conf."
|
|
|
|
echo
|
|
if [ $FAILS -eq 0 ]; then echo "ALL PASSED"; else echo "$FAILS FAILED"; fi
|
|
[ $FAILS -eq 0 ]
|