-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-vm
executable file
·134 lines (112 loc) · 3.56 KB
/
build-vm
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# vi: fdm=marker
# Constants {{{1
################################################################
export W4MVM_KEYBOARD=qwerty
export W4MVM_SHOW=no
export W4MVM_VERSION=dev
export W4MVM_NAME=
export W4MVM_TOOLS=all
HALT=no
WAIT=no
# Print help {{{1
################################################################
function print_help {
echo "Usage: build-vm [options]"
echo
echo "Builds the W4M virtual machine."
echo
echo "Options:"
echo " -a, --azerty Set AZERTY keyboard. The default keyboard is QWERTY."
echo " -H, --halt Halt the machine after building it."
echo " -h, --help Print this help message."
echo " -n, --name Set the name of the virtual machine. If unset, Vagrant will set a semi-random name itself."
echo " -p, --prod Builds a production machine, using official released versions of tools. By default the branch used for developing is used to extract tool code."
echo " -s, --show Show VM screen. By default it is hidden."
echo " -w, --wait Wait for Galaxy to be up."
}
# Read args {{{1
################################################################
function read_args {
local args="$*" # save arguments for debugging purpose
# Read options
while true ; do
case $1 in
-a|--azerty) W4MVM_KEYBOARD=azerty ;;
-H|--halt) HALT=yes ;;
-h|--help) print_help ; exit 0 ;;
-n|--name) W4MVM_NAME="$2" ; shift ;;
-p|--prod) W4MVM_VERSION=prod ;;
-s|--show) W4MVM_SHOW=yes ;;
-t|--tool) W4MVM_TOOLS="$2" ; shift ;;
-w|--wait) WAIT=yes ;;
-) error "Illegal option $1." ;;
--) error "Illegal option $1." ;;
--*) error "Illegal option $1." ;;
-?) error "Unknown option $1." ;;
-[^-]*) split_opt=$(echo $1 | sed 's/^-//' | sed 's/\([a-zA-Z]\)/ -\1/g') ; set -- $1$split_opt "${@:2}" ;;
*) break
esac
shift
done
shift $((OPTIND - 1))
}
# Wait for Galaxy {{{1
################################################################
function wait_for_galaxy {
echo
echo "****************************************************************"
echo "Wait for Galaxy to be up and running"
echo
wget=$(which wget)
if [[ $? -ne 0 ]] ; then
echo "You need to install wget in order to wait for Galaxy readiness." >&2
exit 1
fi
# Wait for Galaxy
wait_time=10
n=1
while true ; do
# Wait some time
echo
echo Wait $wait_time seconds...
sleep $wait_time
# Ping Galaxy
echo
echo "Ping Galaxy (try number $n)..."
if wget --tries=1 -O galaxy_page.html http://localhost:8080 ; then
echo
echo "Galaxy has started."
rm galaxy_page.html
break
fi
# Increment count
n=$((n+1))
done
}
# MAIN {{{1
################################################################
read_args "$@"
# Remove machine of the same name if it exists
echo
echo "****************************************************************"
echo "Destroy existing machine ${W4MVM_NAME}"
echo
vagrant destroy -f ${W4MVM_NAME} || exit 1
[[ -z $(VBoxManage list vms | grep '^"'${W4MVM_NAME}'"') ]] || VBoxManage unregistervm --delete ${W4MVM_NAME} || exit 1
# Build and start machine
echo
echo "****************************************************************"
echo "Build and start machine ${W4MVM_NAME}"
echo
vagrant up ${W4MVM_NAME} || exit 1
# Wait for Galaxy
[[ $WAIT == yes || $HALT == yes ]] && wait_for_galaxy
# Halt machine
if [[ $HALT == yes ]] ; then
echo
echo "****************************************************************"
echo "Halt machine ${W4MVM_NAME}"
echo
vagrant halt ${W4MVM_NAME} || exit 1
fi