Files
lotherk fd4c57b9c3 build: tests refuse to run beside a build
--check now passes when the caller is inside the lock (make test/cdtest ->
tools/test.sh) and still refuses when another build holds it.  test.sh,
mediacheck.sh, install-simple.sh and install-cgd.sh call it before they
touch the media or start a VM; a direct test beside a build stops with the
holder's pid.
2026-11-16 12:15:43 +00:00

298 lines
12 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
# install-cgd.sh -- install Makronix from the CD onto an encrypted disk, boot it.
#
# usage: install-cgd.sh [-f bios] [-d diskimage] [-p passphrase]
#
# Like install-simple.sh, but answers "yes" to "Encrypt the disk?" and types a
# passphrase where cgdconfig asks for one. When sysinst reboots, the disk is
# booted on its own: the boot loader loads cgdroot.kmod, the miniroot asks for
# the passphrase, root logs in, and the result is checked. Finally the disk
# image is read from the host to prove that the root file system is not
# readable there: a file name from the root file system must not be found.
#
# Exit status: 0 all checks passed, 1 anything else. The medium is the CD
# that `make iso' built (vmsh.sh start -I); nothing in the build is touched.
set -u
TOP=${TOP:-$(cd "$(dirname "$0")/.." && pwd)}
# Tests do not run beside a build (make test/cdtest hold the lock).
"$TOP/tools/build-lock.sh" --check || exit 1
# the version of the release, as newvers.sh reads it
VER=$(cat "$TOP/src/sys/conf/makronix-release")
V=$TOP/tools/vmsh.sh
# VMD=/another/dir runs beside another session's VM (vmsh.sh reads VMDIR)
VMD=${VMD:-$TOP/build/vmsession}
VMDIR=$VMD; export VMDIR
FW=bios
DISK=$VMD/disk-install-cgd.qcow2
PW=makronix-test-passphrase
UPW=mx-test-password-1 # the password of root and of the user, in the test
DAY=$(date +%Y-%m-%d)
# the second install CD, for the set that is not on the first (make iso)
CD2=$TOP/build/obj/releasedir/images/Makronix-$VER-amd64-cd2.iso
# the third, with the extra programs (firefox, thunderbird, qemu)
CD3=$TOP/build/obj/releasedir/images/Makronix-$VER-amd64-cd3.iso
CD4=$TOP/build/obj/releasedir/images/Makronix-$VER-amd64-cd4.iso
CD5=$TOP/build/obj/releasedir/images/Makronix-$VER-amd64-cd5.iso
usage()
{
echo "usage: ${0##*/} [-f bios] [-d diskimage] [-p passphrase]" >&2
exit 1
}
while getopts f:d:p: ch; do
case $ch in
f) FW=$OPTARG ;;
d) DISK=$OPTARG ;;
p) PW=$OPTARG ;;
*) usage ;;
esac
done
LOG1=$TOP/build/logs/install-cgd-$FW-install-$DAY.log
LOG2=$TOP/build/logs/install-cgd-$FW-boot-$DAY.log
asked=
nasked=0
nextcd=0
die()
{
echo "FAIL: $*"
$V show 14
cp "$VMD/console.log" "$TOP/build/logs/install-cgd-$FW-failed-$DAY.log" 2>/dev/null
$V stop >/dev/null
exit 1
}
step()
{
$V wait "$1" "$2" > /dev/null || die "waiting for '$1'"
sleep 1
}
key()
{
$V send "$1"
sleep 1
asked="$asked $1"
nasked=$((nasked + 1))
}
rm -f "$DISK"
$V stop > /dev/null 2>&1
if [ "$FW" = uefi ]; then
# a copy of CD 1 whose loader talks on com0 (tools/cd-com0.sh says why)
"$TOP/tools/cd-com0.sh" "$TOP"/build/obj/releasedir/images/Makronix-$VER-amd64.iso "$TOP/build/vm/cd1-com0.iso" || exit 1
$V start -i "$TOP/build/vm/cd1-com0.iso" -d "$DISK" -f "$FW" -s 20G -m 4G || exit 1
else
$V start -I -d "$DISK" -f "$FW" -s 20G -m 4G || exit 1
fi
# The media choose their console themselves (console=auto): the BIOS
# loader needs no key (modem lines are enough); for UEFI the test boots the copy
# above.
# The installer that runs from the CD asks for the terminal type; the one that
# runs from the RAM disk (the first CD) has it set already and shows the
# language menu at once.
step 'Terminal type|Installation messages in English' 900
case $($V since) in
*'Terminal type'*) $V send '\r' ;;
esac
step 'Installation messages in English' 60; key a # language
step 'Thank you for choosing Makronix' 30; $V send '\r' # welcome: OK
step 'Install Makronix to hard disk' 30; key a # main menu
step 'Shall we continue' 30; key b # yes
step 'Select the installation profile' 30; key b # Desktop (no sources)
step 'Encrypt the disk' 30; key b # yes
step 'Available disks' 30; key a # the disk
step 'ready to install Makronix on your hard disk' 120; key b # last chance
i=0
while [ $i -lt 1500 ]; do
# -no-reboot: qemu exits when sysinst reboots, perhaps before the line is printed
kill -0 "$(cat "$VMD/qemu.pid" 2>/dev/null)" 2>/dev/null || break
s=$($V since)
case $s in
*'rebooting...'*) break ;;
*'Reboot the computer'*) key d ;;
*'Finished configuring'*) key x ;;
*'Not now, continue'*) key x ;;
# extras.c asks once for the games group: yes (the default)
*'Install Makronix Games'*) key a ;;
# sysinst asks for the next CD with the menu "Next CD": first the second
# (the makronix set), then the third (the extra programs). The test counts
# the menus; it does not read the sentence above them, which `vmsh since'
# does not always have (measured 2026-11-07: the test hung at the prompt).
*'Next CD'*)
nextcd=$((nextcd + 1))
# CD 2, then the CDs with the packages: CD 3, and CD 4, ... when the
# packages need more than one
cd=$(eval echo "\$CD$((nextcd + 1))")
[ -r "$cd" ] || die "no CD for the next-CD prompt number $nextcd: $cd"
$V cd "$cd" || die "changing the CD"
sleep 5
key a ;;
# the questions of the simple mode's last step (setup.c)
*'Name of this computer'*)
$V send 'mxtest\r'; asked="$asked <hostname>"; nasked=$((nasked + 1)) ;;
# since 2026-11-09 the network, root and the user come from the entries
# of the configuration menu (configmenu.c, net.c, passwd -l)
*'Which network device'*)
key a; asked="$asked <netdev>"; nasked=$((nasked + 1)) ;;
*'Network media type'*|*'Your host name'*|*'Your DNS domain'*|*'Your name server'*)
$V send '\r'; asked="$asked <net-enter>"; nasked=$((nasked + 1)) ;;
*'Perform autoconfiguration'*|*'Are they OK'*|*'installed in /etc'*)
key a; asked="$asked <net-yes>"; nasked=$((nasked + 1)) ;;
*'continue the install process anyway'*)
key a ;;
*'problem in setting up the network'*)
key b ;;
*'choose the timezone'*)
key x ;; # the default (UTC) stays
*'Retype new password'*|*'New password'*)
$V send "$UPW\\r"; asked="$asked <pw>"; nasked=$((nasked + 1)) ;;
*'Username to add'*)
$V send 'tester\r'; asked="$asked <login>"; nasked=$((nasked + 1)) ;;
*'add this user to group wheel'*)
key a; asked="$asked <wheel>"; nasked=$((nasked + 1)) ;;
*'/bin/ksh'*)
key b; asked="$asked <shell>"; nasked=$((nasked + 1)) ;;
*'Hit enter to continue'*)
$V send '\r'; asked="$asked <enter>"; nasked=$((nasked + 1)) ;;
*"passphrase:"*)
$V send "$PW\\r"; asked="$asked <passphrase>"
nasked=$((nasked + 1)) ;;
*'Install from'*|*'Bootblocks selection'*|*'correct geometry'*|*'Select your distribution'*)
die "the simple mode asked something it should not: $(echo "$s" | tail -3)" ;;
esac
sleep 2
i=$((i + 1))
done
[ $i -lt 1500 ] || die "sysinst did not finish within the time limit"
cp "$VMD/console.log" "$LOG1"
sleep 3
$V stop > /dev/null
echo "prompts answered by the test (keys): $nasked --$asked"
# ---- second boot: the miniroot asks for the passphrase ----
$V start -d "$DISK" -f "$FW" || exit 1
step 'passphrase' 900
$V send "$PW\\r"
step 'login:' 300
$V send 'root\r'
step 'Password:' 30
$V send "$UPW\\r"
sleep 3
$V send 'echo READYX\r'
step '^READYX' 30
# The checks go into a file, line by line: one terminal line holds 1024
# bytes and the whole check is longer (measured 2026-11-07: the line was cut
# and "ENDCHK" never came). Only the output of the last send is kept.
$V send 'cat > /tmp/chk.sh <<"EOF"\r'
$V send 'echo CHK\r'
$V send 'id tester\r'
$V send 'hostname\r'
$V send 'grep -E "^(dtlogin|ntpd|dhcpcd|sshd|npf|mdnsd|dbus|cupsd)=" /etc/rc.conf\r'
$V send 'test -s /etc/npf.conf && echo NPF_CONF\r'
$V send 'echo NPF_RULES=$(/sbin/npfctl show 2>/dev/null | grep -c block)\r'
$V send 'echo ROOTSSH=$(grep -c "^PermitRootLogin yes" /etc/ssh/sshd_config)\r'
$V send 'echo NSS=$(grep -c "^hosts: files mdnsd dns" /etc/nsswitch.conf)\r'
$V send 'echo MDNSD=$(ps ax | grep -c "[m]dnsd")\r'
$V send 'i=0; while [ $i -lt 30 ]; do n=$(getent hosts $(hostname).local | wc -l); [ $n -ge 1 ] && break; sleep 2; i=$((i+1)); done; echo MDNS_NAME=$n\r'
$V send 'echo DBUS=$(ps ax | grep -c "[d]bus-daemon")\r'
$V send 'echo CUPSD=$(ps ax | grep -c "[c]upsd")\r'
$V send 'echo PULSE=$(/usr/pkg/bin/pulseaudio --version)\r'
$V send 'echo PKGCONF=$(grep -c "^PKG_PATH=" /etc/pkg_install.conf)\r'
$V send 'echo DAILYVULN=$(grep -c "^fetch_pkg_vulnerabilities=YES" /etc/daily.conf)\r'
$V send 'test -x /etc/rc.d/dtlogin && echo DT_RC\r'
$V send 'test -L /etc/localtime && echo TZLINK\r'
$V send 'echo DTL=$(ps ax | grep -c "[d]tlogin")\r'
$V send 'test -f /etc/mtree/set.makronix && echo SET_OK\r'
$V send 'test -x /usr/pkg/dt/bin/dtwm && echo CDE_OK\r'
$V send '/usr/sbin/pkg_info -K /usr/pkg/pkgdb | grep -E "^(firefox|thunderbird|qemu|pulseaudio|cups)-"\r'
$V send '/usr/pkg/bin/qemu-system-aarch64 --version | head -1\r'
$V send 'test -x /usr/pkg/lib/firefox/firefox && echo FF_OK\r'
$V send 'df / | tail -1\r'
$V send 'cgdconfig -l | head -3\r'
$V send 'EOF\r'
$V send 'sh /tmp/chk.sh; echo ENDCHK\r'
step '^ENDCHK' 150
out=$($V since)
cp "$VMD/console.log" "$LOG2"
$V stop > /dev/null
rc=0
# wanted NAME: is NAME a binary package the media carry (packages.list: repo, fetch,
# tools/cd3.sh)? Its checks run only then; otherwise one SKIP line says why.
wanted()
{
{ "$TOP/tools/pkglist.sh" repo -n; "$TOP/tools/pkglist.sh" fetch -n; } | grep -qx -- "$1" && return 0
echo "SKIP: $1 is not on the media (packages.list: repo, fetch)"
return 1
}
check()
{
if echo "$out" | grep -a -q "$1"; then
echo "PASS: $2"
else
echo "FAIL: $2"
rc=1
fi
}
echo "PASS: login: prompt reached after the passphrase"
check '(tester).*(wheel).*(operator)' "the user is in wheel and operator (and the other groups)"
check '^mxtest' "the host name is the one that was asked for"
check '^dtlogin=YES' "dtlogin is enabled in rc.conf"
check '^sshd=YES' "sshd is enabled in rc.conf"
check '^npf=YES' "the firewall (npf) is enabled in rc.conf"
check '^NPF_CONF' "/etc/npf.conf is in place"
check '^NPF_RULES=[1-9]' "the firewall is loaded and blocks (npfctl show)"
check '^ROOTSSH=1' "root may log in with the password (PermitRootLogin yes)"
check '^mdnsd=YES' "mdnsd is enabled in rc.conf"
check '^NSS=1' "nsswitch.conf asks mdnsd for hosts"
check '^MDNSD=[1-9]' "mdnsd is running"
check '^MDNS_NAME= *[1-9]' "the computer's own name.local resolves (getent hosts)"
{ wanted pulseaudio || wanted cups; } && check '^dbus=YES' "dbus is enabled in rc.conf"
{ wanted pulseaudio || wanted cups; } && check '^DBUS=[1-9]' "dbus-daemon is running"
wanted cups && check '^cupsd=YES' "cupsd is enabled in rc.conf"
wanted cups && check '^CUPSD=[1-9]' "cupsd is running"
wanted pulseaudio && check '^pulseaudio-' "pulseaudio is installed (pkg_info)"
wanted cups && check '^cups-' "cups is installed (pkg_info)"
wanted pulseaudio && check '^PULSE=pulseaudio' "pulseaudio runs (--version)"
check '^PKGCONF=1' "pkg_add has a repository (/etc/pkg_install.conf PKG_PATH)"
check '^DAILYVULN=1' "daily fetches the package vulnerabilities (/etc/daily.conf)"
check '(tester).*wsrc' "the user is in wsrc (may write /usr/src)"
check '^TZLINK' "/etc/localtime is set (the time zone question was answered)"
check '^DT_RC' "/etc/rc.d/dtlogin is in place"
check '^DTL=[1-9]' "dtlogin is running after the boot"
check '^SET_OK' "/etc/mtree/set.makronix exists (the makronix set was installed)"
check '^CDE_OK' "/usr/pkg/dt/bin/dtwm exists (CDE)"
wanted firefox && check '^firefox-154' "firefox is installed (pkg_info)"
wanted thunderbird && check '^thunderbird-154' "thunderbird is installed (pkg_info)"
wanted qemu && check '^qemu-11' "qemu is installed (pkg_info)"
wanted qemu && check '^QEMU emulator version' "qemu runs (qemu-system-aarch64 --version)"
wanted firefox && check '^FF_OK' "the firefox program is there"
check '/dev/cgd0a' "root is on cgd0a"
# ---- from the host: the root file system is not readable on the disk ----
RAW=$VMD/disk-install-cgd.raw
qemu-img convert -O raw "$DISK" "$RAW" || die "qemu-img convert"
if LC_ALL=C grep -a -q 'set.makronix' "$RAW"; then
echo "FAIL: a file name of the root file system is readable on the disk"
rc=1
else
echo "PASS: no file name of the root file system is readable on the disk"
fi
rm -f "$RAW"
echo "logs: ${LOG1#$TOP/} ${LOG2#$TOP/}"
exit $rc