2018-11-04 19:34:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-11-23 16:40:17 +00:00
|
|
|
set -eu
|
|
|
|
|
2019-03-25 13:21:55 +00:00
|
|
|
: "${DEFAULT_DIST:=unstable}"
|
2018-12-28 06:44:54 +00:00
|
|
|
: "${cachedir:=./shared/cache}"
|
2018-11-23 16:44:59 +00:00
|
|
|
tmpdir="$(mktemp -d)"
|
2018-11-04 19:34:40 +00:00
|
|
|
|
2018-12-27 13:14:01 +00:00
|
|
|
cleanup() {
|
|
|
|
rv=$?
|
2019-03-25 13:21:55 +00:00
|
|
|
rm -f "$tmpdir/debian-$DEFAULT_DIST-overlay.qcow"
|
2020-11-26 22:45:08 +00:00
|
|
|
rm -f "$tmpdir/log"
|
2018-12-27 13:14:01 +00:00
|
|
|
[ -e "$tmpdir" ] && rmdir "$tmpdir"
|
2023-01-16 06:54:03 +00:00
|
|
|
if [ -e shared/output.txt ]; then
|
|
|
|
res="$(cat shared/exitstatus.txt)"
|
2018-12-30 16:13:46 +00:00
|
|
|
if [ "$res" != "0" ]; then
|
2018-12-27 13:14:01 +00:00
|
|
|
# this might possibly overwrite another non-zero rv
|
|
|
|
rv=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exit $rv
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup INT TERM EXIT
|
|
|
|
|
2022-11-05 13:59:57 +00:00
|
|
|
ARCH=$(dpkg --print-architecture)
|
|
|
|
case $ARCH in
|
|
|
|
i386)
|
|
|
|
MACHINE="accel=kvm:tcg"
|
|
|
|
CODE="/usr/share/OVMF/OVMF32_CODE_4M.secboot.fd"
|
|
|
|
QEMUARCH="i386"
|
|
|
|
;;
|
|
|
|
amd64)
|
|
|
|
MACHINE="accel=kvm:tcg"
|
|
|
|
CODE="/usr/share/OVMF/OVMF_CODE.fd"
|
|
|
|
QEMUARCH="x86_64"
|
|
|
|
;;
|
|
|
|
arm64)
|
|
|
|
MACHINE="type=virt,gic-version=host,accel=kvm"
|
2022-11-17 10:38:17 +00:00
|
|
|
CODE="/usr/share/AAVMF/AAVMF_CODE.fd"
|
2022-11-05 13:59:57 +00:00
|
|
|
QEMUARCH="aarch64"
|
|
|
|
;;
|
|
|
|
*) echo "qemu kvm not supported on $ARCH" >&2;;
|
|
|
|
esac
|
|
|
|
|
2023-01-16 06:54:03 +00:00
|
|
|
echo 1 > shared/exitstatus.txt
|
|
|
|
if [ -e shared/output.txt ]; then
|
|
|
|
rm shared/output.txt
|
|
|
|
fi
|
|
|
|
touch shared/output.txt
|
|
|
|
|
2019-03-25 13:21:55 +00:00
|
|
|
# the path to debian-$DEFAULT_DIST.qcow must be absolute or otherwise qemu will
|
|
|
|
# look for the path relative to debian-$DEFAULT_DIST-overlay.qcow
|
2022-12-23 10:55:42 +00:00
|
|
|
qemu-img create -f qcow2 -b "$(realpath "$cachedir")/debian-$DEFAULT_DIST.qcow" -F qcow2 "$tmpdir/debian-$DEFAULT_DIST-overlay.qcow"
|
2018-12-30 16:14:15 +00:00
|
|
|
# to connect to serial use:
|
|
|
|
# minicom -D 'unix#/tmp/ttyS0'
|
2022-10-16 13:31:05 +00:00
|
|
|
#
|
|
|
|
# or this (quit with ctrl+q):
|
|
|
|
# socat stdin,raw,echo=0,escape=0x11 unix-connect:/tmp/ttyS0
|
2020-11-26 22:45:08 +00:00
|
|
|
ret=0
|
2022-11-14 13:22:32 +00:00
|
|
|
timeout --foreground 40m qemu-system-"$QEMUARCH" \
|
2022-05-22 00:51:10 +00:00
|
|
|
-cpu host \
|
2020-01-03 14:52:25 +00:00
|
|
|
-no-user-config \
|
2022-11-05 13:59:57 +00:00
|
|
|
-M "$MACHINE" -m 4G -nographic \
|
2020-01-03 14:56:49 +00:00
|
|
|
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
|
2018-11-04 19:34:40 +00:00
|
|
|
-monitor unix:/tmp/monitor,server,nowait \
|
|
|
|
-serial unix:/tmp/ttyS0,server,nowait \
|
|
|
|
-serial unix:/tmp/ttyS1,server,nowait \
|
2020-01-03 14:56:25 +00:00
|
|
|
-net nic,model=virtio -net user \
|
2022-11-17 10:35:43 +00:00
|
|
|
-drive if=pflash,format=raw,unit=0,read-only=on,file="$CODE" \
|
2018-11-04 19:34:40 +00:00
|
|
|
-virtfs local,id=mmdebstrap,path="$(pwd)/shared",security_model=none,mount_tag=mmdebstrap \
|
2020-11-26 22:45:08 +00:00
|
|
|
-drive file="$tmpdir/debian-$DEFAULT_DIST-overlay.qcow",cache=unsafe,index=0,if=virtio \
|
|
|
|
>"$tmpdir/log" 2>&1 || ret=$?
|
|
|
|
if [ "$ret" -ne 0 ]; then
|
|
|
|
cat "$tmpdir/log"
|
|
|
|
exit $ret
|
|
|
|
fi
|