-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_final.sh
executable file
·47 lines (39 loc) · 1.11 KB
/
test_final.sh
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
45
46
47
#!/bin/bash
VARIANT=${1:-""}
SSHPORT=2222
SSH_ICPCADMIN_KEY="files/secrets/icpcadmin@contestmanager"
PIDFILE="tmp/qemu.pid"
SNAPSHOT="-snapshot"
ALIVE=0
BASEIMG=$(ls -tr output/$VARIANT*image-amd64.img | tail -n1)
echo "Booting $BASEIMG"
function launchssh() {
echo "Launching ssh session"
ssh -o BatchMode=yes -o IdentitiesOnly=yes -o ConnectTimeout=1 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null icpcadmin@localhost -i $SSH_ICPCADMIN_KEY -p$SSHPORT
}
function cleanup() {
echo "Forcing shutdown(poweroff)"
kill "$(cat $PIDFILE)"
rm -f $PIDFILE
}
set -x
qemu-system-x86_64 -smp 2 -m 4096 -hda $BASEIMG -global isa-fdc.driveA= --enable-kvm -net user,hostfwd=tcp::$SSHPORT-:22 -net nic --daemonize --pidfile $PIDFILE $SNAPSHOT -vnc :0 -vga qxl -spice port=5901,disable-ticketing -usbdevice tablet
set +x
CMD=1
while [ $CMD != 0 ]; do
echo "Select an action"
echo " 1. Launch SSH Session"
echo " 0. Halt VM"
read -p "Action(Default 1): " CMD
CMD=${CMD:-1}
case $CMD in
0) break ;;
1) launchssh ;;
*) launchssh ;;
esac
done
echo
echo
read -p "Press enter to halt"
cleanup
exit 0