: nply/foundationpkgs

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
#!/bin/sh
# Exercise the documented build + staged installation without touching /usr.
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT HUP INT TERM
mkdir -p "$work/recipe" "$work/target/usr/bin" "$work/stage"
cat >"$work/recipe/APKBUILD" <<'RECIPE'
pkgname=staging-fixture
pkgver=1
pkgrel=0
arch=all
source=""
build() {
	printf '#!/bin/sh\nprintf "staged fixture works\\n"\n' >example
}
package() {
	mkdir -p "$pkgdir/usr/bin"
	install -m755 example "$pkgdir/usr/bin/example"
	# Simulate builder metadata that must never overwrite system parents.
	chmod 0750 "$pkgdir" "$pkgdir/usr" "$pkgdir/usr/bin"
}
RECIPE
sh "$root/scripts/build.sh" -f tar.gz -o "$work/dist" -s "$work/sysroot" "$work/recipe/APKBUILD" >"$work/build.log" 2>&1
archive=$(find "$work/dist" -name '*.tar.gz' -type f)
[ -f "$archive" ]
chmod 0700 "$work/target"
chmod 0751 "$work/target/usr"
chmod 0711 "$work/target/usr/bin"
metadata() {
	ls -ldn "$work/target" "$work/target/usr" "$work/target/usr/bin" | awk '{print $1, $3, $4, $NF}'
}
before=$(metadata)
tar -xzf "$archive" -C "$work/stage"
install -m755 "$work/stage/usr/bin/example" "$work/target/usr/bin/example"
[ "$("$work/target/usr/bin/example")" = 'staged fixture works' ]
[ "$before" = "$(metadata)" ]
echo 'PASS: targeted build and staged installation preserve existing parent ownership/modes'