6 if [ -z "${TRAVIS:-}" ] ; then
7 echo "Running outside of Travis."
9 if [ "$#" -ne 1 ] ; then
10 echo "Usage: $(basename "$0") ./grml-debootstrap*.deb" >&2
13 GRML_DEBOOTSTRAP_DEB="$1"
14 if [ "$(dirname "$(realpath "$GRML_DEBOOTSTRAP_DEB")")" != "$(pwd)" ] ; then
15 echo "Error: the grml-debootstrap*.deb needs to be inside $(pwd) to be shared with docker container." >&2
21 RELEASE="${RELEASE:-stretch}"
24 TARGET="${TARGET:-qemu.img}"
27 if [ -n "${QEMU_PID:-}" ] ; then
28 # shellcheck disable=SC2009
29 ps --pid="${QEMU_PID}" -o pid= | grep -q '.' && kill "${QEMU_PID:-}"
32 if [ -f "${TARGET:-}" ] ; then
33 sudo kpartx -dv "$(realpath "${TARGET}")"
36 if [ -n "${LOOP_DISK:-}" ] ; then
37 if sudo dmsetup ls | grep -q "${LOOP_DISK}"; then
38 sudo kpartx -d "/dev/${LOOP_DISK}"
43 loopmount="$(sudo losetup -a | grep "$(realpath "${TARGET}")" | cut -f1 -d: || true)"
45 if [ -n "${loopmount:-}" ] ; then
46 sudo losetup -d "${loopmount}"
49 [ -n "${1:-}" ] && EXIT_CODE="$1" || EXIT_CODE=1
52 trap bailout 1 2 3 6 14 15
54 # run shellcheck tests
55 docker run koalaman/shellcheck:stable --version
56 docker run --rm -v "$(pwd)":/code koalaman/shellcheck:stable -e SC2181 /code/chroot-script /code/grml-debootstrap
58 # build Debian package
59 if [ -z "${TRAVIS:-}" ] ; then
60 echo "Not running under Travis, installing local grml-debootstrap package ${GRML_DEBOOTSTRAP_DEB}."
62 if ! [ "${TRAVIS_DEBIAN_DISTRIBUTION:-}" = "unstable" ] ; then
63 echo "TRAVIS_DEBIAN_DISTRIBUTION is $TRAVIS_DEBIAN_DISTRIBUTION and not unstable, skipping VM build tests."
66 wget -O- https://travis.debian.net/script.sh | sh -
67 # copy only the binary from the TRAVIS_DEBIAN_INCREMENT_VERSION_NUMBER=true build
68 cp ../grml-debootstrap_*travis*deb .
71 # we need to run in privileged mode to be able to use loop devices
72 docker run --privileged -v "$(pwd)":/code --rm -i -t debian:stretch /code/travis/build-vm.sh
74 [ -x ./goss ] || curl -fsSL https://goss.rocks/install | GOSS_DST="$(pwd)" sh
76 # Ubuntu trusty (14.04LTS) doesn't have realpath in coreutils yet
77 if ! command -v realpath &>/dev/null ; then
78 REALPATH_PACKAGE=realpath
82 sudo apt-get -y install qemu-system-x86 kpartx python-pexpect python-serial ${REALPATH_PACKAGE:-}
84 # run tests from inside Debian system
85 DEVINFO=$(sudo kpartx -asv "${TARGET}")
86 LOOP_PART="${DEVINFO##add map }"
87 LOOP_PART="${LOOP_PART// */}"
88 LOOP_DISK="${LOOP_PART%p*}"
89 IMG_FILE="/dev/mapper/$LOOP_PART"
91 MNTPOINT="$(mktemp -d)"
92 sudo mount "$IMG_FILE" "${MNTPOINT}"
94 sudo cp ./goss "${MNTPOINT}"/usr/local/bin/goss
95 sudo cp ./travis/goss.yaml "${MNTPOINT}"/root/goss.yaml
97 sudo umount "${MNTPOINT}"
98 sudo kpartx -dv "$(realpath "${TARGET}")"
99 if sudo dmsetup ls | grep -q "${LOOP_DISK}"; then
100 sudo kpartx -d "/dev/${LOOP_DISK}"
105 sudo chown "$(id -un)" qemu.img
108 qemu-system-x86_64 -hda qemu.img -display none -vnc :0 \
109 -device virtio-serial-pci \
110 -chardev pipe,id=ch0,path=./serial0 \
111 -device virtserialport,chardev=ch0,name=serial0 \
112 -serial pty &>qemu.log &
117 while [ "$timeout" -gt 0 ] ; do
119 if grep -q 'char device redirected to ' qemu.log ; then
124 echo "No serial console from Qemu found yet [$timeout retries left]"
129 if [ "$success" = "1" ] ; then
130 serial_port=$(awk '/char device redirected/ {print $5}' qemu.log)
132 echo "Error: Failed to identify serial console port." >&2
138 while [ "$timeout" -gt 0 ] ; do
140 if [ -c "$serial_port" ] ; then
145 echo "No block device for serial console found yet [$timeout retries left]"
150 if [ "$success" = "0" ] ; then
151 echo "Error: can't access serial console block device." >&2
155 sudo chown "$(id -un)" "$serial_port"
156 ./travis/serial-console-connection --port "$serial_port" --hostname "$RELEASE" --pipefile "serial0" --vmoutput "vm-output.txt"
161 if grep -q '^failure_exit' vm-output.txt ; then
162 echo "We noticed failing tests."
165 echo "All tests passed."
168 echo "Finished serial console connection [timeout=${timeout}]."