Verify bare unit commands through init PATH lookup and cargo run. Assisted-by: SurmAgent:unknown [read] [edit] [bash]
51 lines
1.9 KiB
Nu
51 lines
1.9 KiB
Nu
#!/usr/bin/env nu
|
|
# Verify the packaged host's toolchain and namespace builder outside the Nix sandbox.
|
|
def main [host: path = 'result/bin/sausage'] {
|
|
let host = ($host | path expand)
|
|
let temporary = (^mktemp -d -t sausage-packaged.XXXXXX | str trim)
|
|
let world = ($temporary | path join world)
|
|
print $'Fresh world: ($world)'
|
|
let initialized = (^$host init $world | complete)
|
|
print --no-newline $initialized.stdout
|
|
print --stderr --no-newline $initialized.stderr
|
|
if $initialized.exit_code != 0 { error make {msg: 'packaged host init failed'} }
|
|
let script = r#'set -e
|
|
/bin/printf 'coreutils OK\n'
|
|
printf 'same\n' > /same
|
|
cmp /same /same
|
|
diff /same /same
|
|
ps | grep -q PID
|
|
sh -c 'echo sh OK'
|
|
bash -c 'echo bash OK'
|
|
qjs -e 'console.log("qjs source OK")'
|
|
rm /etc/systemd/system/multi-user.target.wants/web.service
|
|
mkdir -p /run/systemd/requests /run/systemd/replies /run/systemd/state
|
|
set -m
|
|
init > /init.stdout 2> /init.stderr &
|
|
supervisor=$!
|
|
set +m
|
|
systemd-run --unit alias --wait -p Type=oneshot touch /init-PATH-ok
|
|
test -f /init-PATH-ok
|
|
echo 'init PATH OK'
|
|
/bin/kill "$supervisor"
|
|
wait "$supervisor" || true
|
|
mkdir -p /src/projects
|
|
cd /src/projects
|
|
cargo new packaged-probe --vcs none
|
|
printf 'fn main() { println!("packaged builder OK"); }\n' > packaged-probe/src/main.rs
|
|
cd packaged-probe
|
|
cargo run --release
|
|
'#
|
|
let result = (^$host sh $world -c $script | complete)
|
|
print --no-newline $result.stdout
|
|
print --stderr --no-newline $result.stderr
|
|
if $result.exit_code != 0 { error make {msg: 'packaged builder failed'} }
|
|
for expected in ['coreutils OK' 'sh OK' 'bash OK' 'qjs source OK' 'init PATH OK' 'packaged builder OK'] {
|
|
if not ($result.stdout | lines | any {|line| $line == $expected }) {
|
|
error make {msg: $'packaged check did not print: ($expected)'}
|
|
}
|
|
}
|
|
rm --recursive --force $temporary
|
|
print 'Packaged builder check passed.'
|
|
}
|