2 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Install an already built grml-debootstrap.deb in docker and use it to
5 # build a test VM image. Then run this VM image in qemu and check if it
11 echo "Usage: $0 setup"
14 echo "WARNING: $0 is potentially dangerous and may destroy the host system and/or any data."
18 if [ "${1:-}" == "--help" ] || [ "${1:-}" == "help" ]; then
22 if [ -z "${1:-}" ]; then
23 echo "$0: unknown parameters, see --help" >&2
29 if [ ! -d ./tests ]; then
30 echo "$0: Started from incorrect working directory" >&2
34 if [ "$1" == "setup" ]; then
35 [ -x ./tests/goss ] || curl -fsSL https://goss.rocks/install | GOSS_DST="$(pwd)/tests" sh
37 sudo apt-get -y install qemu-system-x86 kpartx python3-pexpect python3-serial
42 # Debian version to install using grml-debootstrap
43 RELEASE="${RELEASE:-bookworm}"
45 TARGET="${TARGET:-qemu.img}"
47 # debootstrap to use, default empty (let grml-debootstrap decide)
48 DEBOOTSTRAP="${DEBOOTSTRAP:-}"
50 if [ "$1" == "run" ]; then
51 # Debian version on which grml-debootstrap will *run*
52 HOST_RELEASE="${HOST_RELEASE:-bookworm}"
54 DEB_NAME=$(ls ./grml-debootstrap*.deb || true)
55 if [ -z "$DEB_NAME" ]; then
56 echo "$0: No grml-debootstrap*.deb found, aborting" >&2
60 # we need to run in privileged mode to be able to use loop devices
61 exec docker run --privileged --rm -i \
64 -e DEBOOTSTRAP="$DEBOOTSTRAP" \
66 debian:"$HOST_RELEASE" \
67 bash -c './tests/docker-install-deb.sh '"$DEB_NAME"' && ./tests/docker-build-vm.sh '"$(id -u)"' '"/code/$TARGET"' '"$RELEASE"
69 elif [ "$1" == "test" ]; then
70 # run tests from inside Debian system
71 exec ./tests/test-vm.sh "$PWD/$TARGET" "$RELEASE"
74 echo "$0: unknown parameters, see --help" >&2