-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_voyager.sh
executable file
·151 lines (135 loc) · 3.24 KB
/
run_voyager.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
# Exit the script if any command fails
set -e
# Declare bools for flag statuses
PREPAREOFFLINE=false
OFFLINE=false
DESTROY=false
PAUSE=false
UNPAUSE=false
# parse the arguments.
COUNTER=0
ARGS=("$@")
while [ $COUNTER -lt $# ]
do
arg=${ARGS[$COUNTER]}
let COUNTER=COUNTER+1
nextArg=${ARGS[$COUNTER]}
if [[ $skipNext -eq 1 ]]; then
echo "Skipping"
skipNext=0
continue
fi
argKey=""
argVal=""
if [[ "$arg" =~ ^\- ]]; then
# if the format is: -key=value
if [[ "$argKey" =~ \= ]]; then
argVal=$(echo "$argKey" | cut -d'=' -f2)
argKey=$(echo "$argKey" | cut -d'=' -f1)
skipNext=0
# if the format is: -key value
elif [[ ! "$nextArg" =~ ^\- ]]; then
argKey="$arg"
argVal="$nextArg"
skipNext=1
# if the format is: -key (a boolean flag)
elif [[ "$nextArg" =~ ^\- ]] || [[ -z "$nextArg" ]]; then
argKey="$arg"
argVal=""
skipNext=0
fi
# if the format has not flag, just a value.
else
argKey=""
argVal="$arg"
skipNext=0
fi
case "$argKey" in
--prepare-offline)
PREPAREOFFLINE=true
shift
;;
--offline)
OFFLINE=true
shift
;;
--destroy)
DESTROY=true
shift
;;
--pause)
PAUSE=true
shift
;;
--unpause)
UNPAUSE=true
shift
;;
--)
shift
break
;;
*)
echo "Unexpected flag passed: ${1}"
exit 3
;;
esac
done
# Start the server using the offline deps
if [ ${OFFLINE} = true ]; then
pushd vagrant/voyager
# Check vagrant status, must say 'poweroff'
set +e
ISOFF=$(vagrant status | grep -o poweroff)
set -e
echo "ISOFF = ${ISOFF}"
if [ -z $ISOFF ]; then
echo "Voyager Machine is not prepared for offline use, see --prepare-offline flag for reference."
exit 1
fi
vagrant reload --provision
popd
pushd vagrant/rackhd
# Check vagrant status, must say 'poweroff'
set +e
ISOFF=$(vagrant status | grep -o poweroff)
set -e
if [ -z $ISOFF ]; then
echo "RackHD Machine is not prepared for offline use, see --prepare-offline flag for reference."
exit 1
fi
vagrant reload --provision
popd
exit 0
fi
function vagrant_do {
pushd vagrant/voyager
vagrant $1
popd
pushd vagrant/rackhd
vagrant $1
popd
}
if [ ${DESTROY} = true ]; then
vagrant_do 'destroy -f'
echo "Vagrant machines have been destroyed."
exit 0
fi
if [ ${UNPAUSE} = true ]; then
vagrant_do resume
else
# If offline is not specified, assume the user has internet connection and
# try to start normally
vagrant_do up
fi
if [ ${PAUSE} = true ]; then
vagrant_do 'suspend'
fi
# iff we're prepping for offline use, we should stop the vagrant VM's
if [ ${PREPAREOFFLINE} = true ]; then
vagrant_do halt
echo "Voyager has now been prepared for offline use."
echo "When you have connected to the target hardware and are ready to resume Voyager execution, re-run this script as:"
echo "./run_voyager.sh --offline"
fi