a6c2f625fc7abc252660d7144c232ee1fc743b21
[icn.git] / tools / vagrant / start_sushy.sh
1 #!/bin/bash
2 set -eu -o pipefail
3
4 listen_ip=$1
5
6 if [[ -f ${HOME}/.sushy/emulator.pid ]]; then
7     if ps -p $(cat ${HOME}/.sushy/emulator.pid); then
8         echo sushy-emulator is already started
9         exit 0
10     fi
11 fi
12
13 # Install prerequisites
14 if [[ $(which apt-get 2>/dev/null) ]]; then
15     DEBIAN_FRONTEND=noninteractive sudo apt-get install -y make apache2-utils libvirt-dev ovmf python3-pip
16 elif [[ $(which yum) ]]; then
17     # TODO OVMF doesn't include OVMF_CODE.fd
18     sudo yum install -y make httpd-tools libvirt-devel OVMF python3-pip
19 fi
20 sudo python3 -m pip install libvirt-python sushy-tools
21 # Add route to provisioning network - sushy-emulator needs to
22 # fetch ISOs over this during virtual media boot
23 dev=$(ip -o addr show to ${listen_ip} | awk '{print $2}')
24 sudo ip route add 172.22.0.0/24 dev ${dev}
25 # Configure sushy-emulator
26 mkdir -p ${HOME}/.sushy
27 openssl req -x509 -newkey rsa:4096 -keyout ${HOME}/.sushy/key.pem -out ${HOME}/.sushy/cert.pem -sha256 -days 365 -nodes -subj "/CN=${listen_ip}"
28 htpasswd -c -b -B ${HOME}/.sushy/htpasswd admin password
29 cat <<EOF >${HOME}/.sushy/emulator.conf
30 SUSHY_EMULATOR_LISTEN_IP = u'${listen_ip}'
31 SUSHY_EMULATOR_SSL_CERT = u'${HOME}/.sushy/cert.pem'
32 SUSHY_EMULATOR_SSL_KEY = u'${HOME}/.sushy/key.pem'
33 SUSHY_EMULATOR_AUTH_FILE = u'${HOME}/.sushy/htpasswd'
34 SUSHY_EMULATOR_VMEDIA_VERIFY_SSL = False
35 EOF
36 sushy-emulator --config ${HOME}/.sushy/emulator.conf 1>${HOME}/.sushy/emulator-stdout.log 2>${HOME}/.sushy/emulator-stderr.log &
37 echo $! >${HOME}/.sushy/emulator.pid