2017-03-08 17:10:46 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Travis doesn't provide FreeBSD machines, so we just take a Linux one and run
|
|
|
|
# FreeBSD in qemu virtual machine. qemu is being ran in curses mode inside a
|
|
|
|
# screen session, because screen allows to easily send input and read output.
|
|
|
|
# The input is sent using `screen -S session-name -X stuff ...` and the output
|
|
|
|
# is read from the screen's log file. Note that for some reason you can't send
|
|
|
|
# long input lines on Travis (it works just fine when I do it on my machine...),
|
|
|
|
# but that limitation is not an issue, as we don't really need to send long
|
|
|
|
# lines of input anyway. Also, note that since we run qemu in curses mode, the
|
|
|
|
# output contains control characters intended for a terminal emulator telling
|
|
|
|
# how to position and color the text, so it might be a little tricky to read it
|
|
|
|
# sometimes. The only time when this script has to send input to and read the
|
|
|
|
# output from the screen session is during the initial setup when we setup the
|
|
|
|
# network, install and configure the ssh server, and update the system. After
|
|
|
|
# this initial setup, ssh is used to communicate with the FreeBSD running in the
|
|
|
|
# VM, which is a lot friendlier way of communication. Please note that Travis
|
|
|
|
# doesn't seem to allow KVM passthrough, so qemu has to emulate all the
|
|
|
|
# hardware, which makes it quite slow compared to the host machine. We cache
|
|
|
|
# the qemu image since it takes a long time to run the initial system and
|
2017-04-10 14:36:08 +08:00
|
|
|
# package updates, and we do incremental system and package updates on every
|
|
|
|
# change to the list of git tags (i.e. on every toxcore release, presumably).
|
2017-03-08 17:10:46 +08:00
|
|
|
|
2018-05-10 15:45:43 +08:00
|
|
|
sudo apt-get update
|
2017-07-31 10:18:28 +08:00
|
|
|
sudo apt-get install -y qemu
|
2017-03-08 17:10:46 +08:00
|
|
|
|
|
|
|
OLD_PWD="$PWD"
|
|
|
|
|
|
|
|
mkdir -p /opt/freebsd/cache
|
|
|
|
cd /opt/freebsd/cache
|
|
|
|
|
2017-07-31 10:18:28 +08:00
|
|
|
# Make sure to update DL_SHA512 when bumping the version
|
2018-07-08 22:22:32 +08:00
|
|
|
FREEBSD_VERSION="11.2"
|
2017-07-31 10:18:28 +08:00
|
|
|
IMAGE_NAME=FreeBSD-${FREEBSD_VERSION}-RELEASE-amd64.raw
|
2017-03-08 17:10:46 +08:00
|
|
|
|
|
|
|
# Sends keys to the VM as they are
|
|
|
|
send_keys()
|
|
|
|
{
|
|
|
|
screen -S $SCREEN_SESSION -X stuff "$1"
|
|
|
|
}
|
|
|
|
|
2017-07-31 10:18:28 +08:00
|
|
|
# Blocks until a specific text appears on VM's screen
|
2017-03-08 17:10:46 +08:00
|
|
|
wait_for()
|
|
|
|
{
|
2017-07-31 10:18:28 +08:00
|
|
|
while ! grep -q "$1" screenlog.0
|
2017-03-08 17:10:46 +08:00
|
|
|
do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Starts VM and waits until it's fully running (until a login prompt is shown)
|
|
|
|
start_vm()
|
|
|
|
{
|
|
|
|
rm -f screenlog.0
|
|
|
|
|
|
|
|
# Start emulator. 2000mb RAM should be enough, right? The build machine has over 7gb.
|
2017-07-31 10:18:28 +08:00
|
|
|
screen -L -S $SCREEN_SESSION -d -m \
|
|
|
|
qemu-system-x86_64 -curses -m 2000 -smp $NPROC \
|
2018-07-08 22:22:32 +08:00
|
|
|
-net user,hostfwd=tcp::${SSH_PORT}-:22 -net nic "$IMAGE_NAME"
|
2017-03-08 17:10:46 +08:00
|
|
|
|
|
|
|
# Wait for the boot screen options
|
|
|
|
wait_for "Autoboot in"
|
|
|
|
|
|
|
|
# Select the 1st option
|
|
|
|
send_keys '
|
|
|
|
'
|
|
|
|
|
|
|
|
# Wait for the system to boot and present the login prompt
|
|
|
|
wait_for "FreeBSD/amd64 ("
|
|
|
|
}
|
|
|
|
|
2017-04-10 14:36:08 +08:00
|
|
|
# Shuts VM down and waits until its process finishes
|
|
|
|
stop_vm()
|
|
|
|
{
|
|
|
|
# Turn it off
|
2018-07-08 22:22:32 +08:00
|
|
|
send_keys 'poweroff
|
|
|
|
'
|
2017-04-10 14:36:08 +08:00
|
|
|
|
|
|
|
# Wait for qemu process to terminate
|
|
|
|
while ps aux | grep qemu | grep -vq grep
|
|
|
|
do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-03-08 17:10:46 +08:00
|
|
|
# Let's see what's in the cache directory
|
|
|
|
ls -lh
|
|
|
|
|
|
|
|
cd "$OLD_PWD"
|