Files
makronix/tools/install-simple.sh
T

349 lines
14 KiB
Bash
Executable File

#!/bin/sh
# install-simple.sh -- install Makronix from the CD in the simple mode, boot it.
#
# usage: install-simple.sh [-f bios] [-d diskimage]
#
# Drives sysinst on the serial console through tools/vmsh.sh: language, the
# installer, the installation mode (Simple), the disk, the last chance; then it
# answers whatever sysinst still asks, one prompt at a time, by looking at what
# the console printed since the last key. When sysinst reboots, the disk is
# booted on its own, root logs in, and the result is checked.
#
# It sends the same keys a person would, in the same order, and prints every
# prompt it answered: the list is the evidence of how many questions the
# simple mode still asks. The logs of both phases are kept in build/logs/.
#
# 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)}
V=$TOP/tools/vmsh.sh
VMD=$TOP/build/vmsession
FW=bios
DISK=$VMD/disk-install-simple.qcow2
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-0.99.9-amd64-cd2.iso
# the third, with the extra programs (firefox, thunderbird, qemu)
CD3=$TOP/build/obj/releasedir/images/Makronix-0.99.9-amd64-cd3.iso
CD4=$TOP/build/obj/releasedir/images/Makronix-0.99.9-amd64-cd4.iso
CD5=$TOP/build/obj/releasedir/images/Makronix-0.99.9-amd64-cd5.iso
SRCDVD=no
USBGZ= # -U: the install image of make usb (.img.gz)
BOOTONLY=no # -B: stop at the disk menu and check it (a smoke test of the medium)
TAG=simple
UPW=mx-test-password-1 # the password of root and of the user, in the test
# for a machine that is kept (the build VM): MX_VMOPTS="-s 64G -m 10G -c 8 -p 2222",
# MX_HOST names it; the later options of vmsh.sh start win over the earlier
VMOPTS=${MX_VMOPTS:-}
HOST=${MX_HOST:-mxtest}
usage()
{
echo "usage: ${0##*/} [-B] [-S | -U image.img[.gz]] [-f bios|uefi] [-d diskimage]" >&2
echo " -B boot only: go to the disk menu, check it, stop" >&2
echo " -U install from the USB stick image (make usb, raw or .gz), attached as a USB stick" >&2
echo " -S install from the DVD that carries the source sets (make isosrc)" >&2
echo " and check that they were installed" >&2
exit 1
}
while getopts BSU:f:d: ch; do
case $ch in
S) SRCDVD=yes; TAG=src ;;
B) BOOTONLY=yes ;;
U) USBGZ=$OPTARG; TAG=usb ;;
f) FW=$OPTARG ;;
d) DISK=$OPTARG ;;
*) usage ;;
esac
done
LOG1=$TOP/build/logs/install-$TAG-$FW-install-$DAY.log
LOG2=$TOP/build/logs/install-$TAG-$FW-boot-$DAY.log
asked=
nasked=0
nextcd=0
die()
{
echo "FAIL: $*"
$V show 14
cp "$VMD/console.log" "$TOP/build/logs/install-simple-$FW-failed-$DAY.log" 2>/dev/null
$V stop >/dev/null
exit 1
}
# wait for a screen, then give it a moment to finish drawing
step()
{
$V wait "$1" "$2" > /dev/null || die "waiting for '$1'"
sleep 1
}
# A menu key: the letter selects, RETURN activates (sysinst's menus).
key()
{
$V send "$1"
sleep 1
$V send '\r'
asked="$asked $1"
nasked=$((nasked + 1))
}
rm -f "$DISK"
$V stop > /dev/null 2>&1
if [ $SRCDVD = yes ]; then
DVD=$TOP/build/obj/releasedir/images/Makronix-0.99.9-amd64-dvd.iso
$V start -i "$DVD" -d "$DISK" -f "$FW" -s 30G $VMOPTS || exit 1
elif [ -n "$USBGZ" ]; then
# the stick is a raw image; vmsh.sh -U attaches it with snapshot=on, so
# the file stays as it was unpacked
case $USBGZ in
*.gz) STICK=$TOP/build/vm/usb-stick.img
gzip -dc "$USBGZ" > "$STICK" || exit 1 ;;
*) STICK=$USBGZ ;; # raw: used as it is
esac
$V start -U "$STICK" -d "$DISK" -f "$FW" -s 20G $VMOPTS || exit 1
elif [ "$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-0.99.9-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 $VMOPTS || exit 1
else
$V start -I -d "$DISK" -f "$FW" -s 20G $VMOPTS || exit 1
fi
# The media choose their console themselves (console=auto, patch 0008). The
# UEFI loader takes a serial port only if a key is pressed on it within seven
# seconds (sys/arch/i386/stand/efiboot/eficons.c); a person at a terminal does
# that, the test does it here: Enter once a second until the loader has spoken.
# The BIOS loader needs no key (modem lines are enough).
if [ "$FW" = uefi ]; then
i=0
while [ $i -lt 600 ] && ! grep -a -q 'Makronix' "$VMD/console.log" 2>/dev/null; do
sleep 1
# the key goes in through the (virtual) keyboard: the loader looks at the
# console input, and a key on the serial line did not count (screen dump,
# 2026-11-08: the installer came up on VGA)
echo "sendkey ret" | socat - "UNIX-CONNECT:$VMD/mon" > /dev/null 2>&1
i=$((i + 1))
done
fi
# ---- the fixed part: language, installer, mode, disk, last chance ----
# 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' 400
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 mode' 30; key a # Simple
step 'Encrypt the disk' 30; key a # no
step 'Available disks' 30
if [ $BOOTONLY = yes ]; then
# The disk menu lists the machine's disks. The target (wd0) must be there;
# the medium the installer runs from must not be, a CD never, a USB stick
# neither (sysinst offered the stick once, 2026-11-08: disks.c
# is_root_wedge_parent).
s=$($V since)
echo "$s" | tail -8
fail=0
case $s in *': wd0'*|*'a: wd0'*) echo "PASS: the target disk wd0 is offered" ;; *) echo "FAIL: wd0 is not offered"; fail=1 ;; esac
case $s in *': sd0'*) echo "FAIL: the stick (sd0) is offered as a target"; fail=1 ;; *) echo "PASS: no sd0 among the targets" ;; esac
case $s in *': cd0'*) echo "FAIL: the CD (cd0) is offered as a target"; fail=1 ;; *) echo "PASS: no cd0 among the targets" ;; esac
$V stop > /dev/null
exit $fail
fi
key a # the disk
step 'ready to install Makronix on your hard disk' 120; key b # last chance
# ---- the rest: answer what is asked, until sysinst reboots ----
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 ;;
# 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 "$HOST\\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)) ;;
*'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"
grep -a -c 'Sets selected' "$LOG1" > /dev/null && grep -a -o 'Sets selected [0-9]*' "$LOG1" | head -1
# ---- second boot: the installed disk on its own ----
$V start -d "$DISK" -f "$FW" $VMOPTS || exit 1
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 'gpt show wd0 | grep -c "GPT part"\r'
$V send 'df / | tail -1\r'
$V send 'test -d /usr/src/sys && test -f /usr/src/build.sh && echo SRC_OK\r'
$V send 'test -d /usr/xsrc/external && echo XSRC_OK\r'
$V send 'test -f /usr/msrc/PINS && test -f /usr/msrc/pkgsrc/Makefile && echo MXSRC_OK\r'
$V send 'echo DISTFILES=$(find /usr/msrc/distfiles -type f | wc -l)\r'
$V send 'cat /usr/msrc/PINS\r'
$V send 'echo PKGS\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 '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
check()
{
if echo "$out" | grep -a -q "$1"; then
echo "PASS: $2"
else
echo "FAIL: $2"
rc=1
fi
}
echo "PASS: login: prompt reached on the installed disk"
check '(tester).*(wheel).*(operator)' "the user is in wheel and operator (and the other groups)"
check "^$HOST" "the host name is the one that was asked for"
check '^dtlogin=YES' "dtlogin is enabled in rc.conf"
check '^ntpd=YES' "ntpd 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)"
check '^dbus=YES' "dbus is enabled in rc.conf"
check '^DBUS=[1-9]' "dbus-daemon is running"
check '^cupsd=YES' "cupsd is enabled in rc.conf"
check '^CUPSD=[1-9]' "cupsd is running"
check '^pulseaudio-' "pulseaudio is installed (pkg_info)"
check '^cups-' "cups is installed (pkg_info)"
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 '^dhcpcd=YES' "dhcpcd is enabled in rc.conf"
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)"
check '^firefox-154' "firefox is installed (pkg_info)"
check '^thunderbird-154' "thunderbird is installed (pkg_info)"
check '^qemu-11' "qemu is installed (pkg_info)"
check '^QEMU emulator version' "qemu runs (qemu-system-aarch64 --version)"
check '^FF_OK' "the firefox program is there"
check '^2$' "the GPT carries two partitions (root and swap)"
check '/dev/dk0' "root is on a wedge of the new GPT"
if [ $SRCDVD = yes ] || [ -n "${USBGZ:-}" ]; then # the DVD and the stick (patch 0018)
check '^SRC_OK' "/usr/src is there (src, gnusrc, syssrc, sharesrc)"
check '^XSRC_OK' "/usr/xsrc is there (xsrc)"
check '^MXSRC_OK' "/usr/msrc has PINS and pkgsrc (msrc)"
want=$(cut -d' ' -f2 "$TOP/distfiles.lst" | sort -u | wc -l | tr -d ' ')
check "DISTFILES= *$want\$" "all $want Makronix distfiles are in /usr/msrc/distfiles"
check "overlay-base $(cat "$TOP/overlay/BASE")" "PINS on the disk names the overlay base of this tree"
else
if echo "$out" | grep -a -q '^SRC_OK'; then
echo "FAIL: the CD installed source sets, it does not carry them"
rc=1
else
echo "PASS: no source sets from the CD (it does not carry them)"
fi
fi
echo "logs: ${LOG1#$TOP/} ${LOG2#$TOP/}"
exit $rc