the-custodian/docs/changes/2026-11-01-scanner-json-digest/native-r4/runtime_self_test.sh

41 lines
1.4 KiB
Bash

#!/bin/sh
# Disposable public tool fixture in tmpfs, before hosted-hook/deployment changes.
set +vx
set -eu
export PATH=/usr/bin:/bin
test "$(id -u)" = 1000
test "$(stat -f -c %t /dev/shm)" = 1021994
umask 077
area=$(mktemp -d /dev/shm/forge-r4-tools-XXXXXXXX)
inode=$(stat -c '%d:%i' "$area")
cleanup() {
code=$?
trap - EXIT HUP INT TERM
if test -d "$area" && test ! -L "$area" && test "$(stat -c '%d:%i' "$area")" = "$inode"; then
rm -f -- "$area/file" "$area/replacement" || code=71
rmdir "$area" || code=71
else code=71; fi
exit "$code"
}
trap cleanup EXIT
trap 'exit 72' HUP INT TERM
printf 'public numeric-mode fixture\n' > "$area/file"
chmod 775 "$area/file"
file_inode=$(stat -c '%d:%i' "$area/file")
exec 7< "$area/file"
test "$(stat -L -c '%d:%i' /proc/self/fd/7)" = "$file_inode"
chmod 755 /proc/self/fd/7
test "$(stat -L -c %a /proc/self/fd/7)" = 755
test "$(stat -c %a "$area/file")" = 755
test "$(sha256sum /proc/self/fd/7 | cut -d ' ' -f 1)" = "$(sha256sum "$area/file" | cut -d ' ' -f 1)"
exec 7<&-
cp "$area/file" "$area/replacement"
mv -T -- "$area/replacement" "$area/file"
test -f "$area/file" && test ! -L "$area/file"
reference=false
if chmod --reference=/dev/null --help >/dev/null 2>&1; then reference=true; fi
rm -f -- "$area/file"
rmdir "$area"
test ! -e "$area"
trap - EXIT HUP INT TERM
printf '{"numeric_modes":true,"descriptor_mode_restore":true,"atomic_rename":true,"temporary_test_removed":true,"reference_option_supported":%s}\n' "$reference"