summaryrefslogtreecommitdiff
path: root/.travis/cmake-freebsd-env.sh
blob: 7d6989405b8f0701d743f4d0f1983c458fb60248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# Common variables and functions

NPROC=$(nproc)

SCREEN_SESSION=freebsd
SSH_PORT=10022

FREEBSD_VERSION="12.1"
IMAGE_NAME=FreeBSD-${FREEBSD_VERSION}-RELEASE-amd64.raw
# https://download.freebsd.org/ftp/releases/VM-IMAGES/12.1-RELEASE/amd64/Latest/
IMAGE_SHA512="a65da6260f5f894fc86fbe1f27dad7800906da7cffaa5077f82682ab74b6dd46c4ce87158c14b726d74ca3c6d611bea3bb336164da3f1cb990550310b110da22"

RUN() {
  ssh -t -o ConnectionAttempts=120 -o ConnectTimeout=2 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p $SSH_PORT "$@"
}

start_vm() {
  screen -d -m qemu-system-x86_64 -curses -m 2048 -smp $NPROC -net user,hostfwd=tcp::${SSH_PORT}-:22 -net nic "$IMAGE_NAME"

  # Wait for ssh to start listening on the port
  while ! echo "exit" | nc localhost ${SSH_PORT} | grep 'OpenSSH'; do
    sleep 5
  done

  # Test that ssh works
  RUN uname -a
  RUN last
}

stop_vm()
{
  # Turn it off
  # We use this contraption because for some reason `shutdown -h now` and
  # `poweroff` result in FreeBSD not shutting down on Travis (they work on my
  # machine though)
  RUN "shutdown -p +5sec && sleep 30" || true

  # Wait for the qemu process to terminate
  while pgrep qemu; do
    sleep 5
  done
}