97 lines
3.1 KiB
Bash
97 lines
3.1 KiB
Bash
#!/bin/bash
|
|
# Build/remove a harmless local ebuild through reviewed sys actions in a
|
|
# disposable installed VM. The fixture writes one text file under /usr/share.
|
|
set -uo pipefail
|
|
|
|
SYS="${SYS_BIN:-/tmp/sys-lanes}"
|
|
WORK="$(mktemp -d)"
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
report() {
|
|
printf 'CASE %s %s %s\n' "$1" "$2" "$3"
|
|
if [[ $2 == PASS ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); fi
|
|
}
|
|
|
|
run_root() {
|
|
sudo -n "$SYS" -y --legacy --action-file "$1"
|
|
}
|
|
|
|
failure() {
|
|
tail -c 240 "$1" | tr '\n' ' '
|
|
}
|
|
|
|
echo '===SYS-EBUILD-START==='
|
|
if [[ ! -x "$SYS" || ! -e /dev/mapper/cryptroot || $(id -u) -eq 0 ]]; then
|
|
report preflight FAIL 'requires an installed encrypted VM and normal user'
|
|
echo "===SYS-EBUILD-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
|
|
exit 1
|
|
fi
|
|
report preflight PASS 'installed encrypted VM, normal user'
|
|
|
|
python3 - "$WORK" <<'PY'
|
|
import hashlib
|
|
import json
|
|
import pathlib
|
|
import sys
|
|
|
|
work = pathlib.Path(sys.argv[1])
|
|
atom = 'app-misc/phoebus-lane-fixture'
|
|
ebuild = '''EAPI=8
|
|
DESCRIPTION="Phoebus package-lane acceptance fixture"
|
|
HOMEPAGE="https://phoebus.club"
|
|
SRC_URI=""
|
|
LICENSE="MIT"
|
|
SLOT="0"
|
|
KEYWORDS="amd64"
|
|
S="${WORKDIR}"
|
|
src_install() {
|
|
echo "Phoebus lane fixture" > "${T}/lane-fixture.txt"
|
|
insinto /usr/share/phoebus
|
|
doins "${T}/lane-fixture.txt"
|
|
}
|
|
'''
|
|
digest = hashlib.sha256(ebuild.encode()).hexdigest()
|
|
actions = {
|
|
'prepare': {'action': 'custom_ebuild_prepare', 'atom': atom,
|
|
'version': '1.0', 'rationale': 'disposable VM package-lane acceptance',
|
|
'ebuild': ebuild},
|
|
'install': {'action': 'custom_ebuild_install', 'atom': atom,
|
|
'version': '1.0', 'digest': digest},
|
|
'remove': {'action': 'custom_ebuild_remove', 'atom': atom},
|
|
}
|
|
for name, action in actions.items():
|
|
(work / f'{name}.json').write_text(json.dumps(action))
|
|
PY
|
|
|
|
if run_root "$WORK/prepare.json" >"$WORK/prepare.out" 2>&1 && \
|
|
sudo -n test -f /var/db/repos/phoebus/app-misc/phoebus-lane-fixture/phoebus-lane-fixture-1.0.ebuild; then
|
|
report ebuild-prepare PASS 'exact ebuild staged in Phoebus overlay'
|
|
else
|
|
report ebuild-prepare FAIL "$(failure "$WORK/prepare.out")"
|
|
fi
|
|
|
|
if run_root "$WORK/install.json" >"$WORK/install.out" 2>&1 && \
|
|
sudo -n test -d /var/db/pkg/app-misc/phoebus-lane-fixture-1.0 && \
|
|
sudo -n test -f /usr/share/phoebus/lane-fixture.txt; then
|
|
report ebuild-install PASS 'Portage VDB and installed file verified'
|
|
if grep -Eq '>>> (Emerging|Installing)|\[ebuild' "$WORK/install.out"; then
|
|
report ebuild-live-output PASS 'source build output reached sys terminal'
|
|
else
|
|
report ebuild-live-output FAIL 'source build output was hidden'
|
|
fi
|
|
else
|
|
report ebuild-install FAIL "$(failure "$WORK/install.out")"
|
|
fi
|
|
|
|
if run_root "$WORK/remove.json" >"$WORK/remove.out" 2>&1 && \
|
|
! sudo -n test -d /var/db/pkg/app-misc/phoebus-lane-fixture-1.0 && \
|
|
! sudo -n test -e /var/db/repos/phoebus/app-misc/phoebus-lane-fixture; then
|
|
report ebuild-remove PASS 'unmerged package and overlay recipe absent'
|
|
else
|
|
report ebuild-remove FAIL "$(failure "$WORK/remove.out")"
|
|
fi
|
|
|
|
echo "===SYS-EBUILD-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
|
|
[[ $FAIL -eq 0 ]]
|