-
Notifications
You must be signed in to change notification settings - Fork 8
/
ubuntu-aws.sh
221 lines (173 loc) · 4.98 KB
/
ubuntu-aws.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# Home Directory for HifiUser
HIFIDIR="/home/hifi"
# Runtime Directory Location
RUNDIR="$HIFIDIR/run"
# Log Directory
LOGSDIR="$HIFIDIR/logs"
# Source Storage Dir
SRCDIR="/usr/local/src"
# Config File Name
CFGNAME="/etc/.chifi"
# Set as 0 until flagged 1
NEWHIFI=0
## Functions ##
function checkroot {
[ `whoami` = root ] || { echo "Please run as root"; exit 1; }
}
function killrunning {
pkill -9 -f "[d]omain-server" > /dev/null 2>&1
pkill -9 -f "[a]ssignment-client" > /dev/null 2>&1
}
function createuser {
if [[ $(grep -c "^hifi:" /etc/passwd) = "0" ]]; then
adduser --system --shell /bin/bash --disabled-password --group --home /home/hifi hifi
NEWHIFI=1
fi
}
function doapt {
[[ "$SILENT" -eq "0" ]] && { echo "Installing needed files for compile"; }
apt-get update -y
apt-get install -y screen git zlib1g-dev libssl-dev libstdc++6 freeglut3 freeglut3-dev mesa-common-dev libxrandr-dev \
libudev-dev libxslt1.1 libpulse0 libgstreamer0.10-0 libgstreamer-plugins-base0.10-0 libicu52 libxcomposite1 -y
}
function compilehifi {
if [[ -d "$SRCDIR" ]]; then
pushd $SRCDIR > /dev/null
if [[ ! -d "highfidelity" ]]; then
mkdir highfidelity
fi
cd highfidelity
if [[ ! -d "hifi" ]]; then
git clone https://github.com/highfidelity/hifi.git
NEWHIFI=1
fi
popd > /dev/null
pushd $SRCDIR/highfidelity/hifi > /dev/null
# Future todo - add a forcable call to the shell script to override this
if [[ $(git pull) =~ "Already up-to-date." ]]; then
[[ "$SILENT" -eq "0" ]] && { echo "Already up to date with last commit."; }
else
NEWHIFI=1
fi
if [ "$NEWHIFI" -eq "1" ]; then
[[ "$SILENT" -eq "0" ]] && { echo "Source needs compiling."; }
killrunning
# we are still assumed to be in hifi directory
if [[ -d "build" ]]; then
rm -rf build/*
else
mkdir build
fi
cd build
cmake ..
make domain-server
if [ $? -eq 0 ]; then
[[ "$SILENT" -eq "0" ]] && { echo "DS Build was successful!"; }
else
[[ "$SILENT" -eq "0" ]] && { echo "DS Build Failed!"; }
exit 1
fi
make assignment-client
if [ $? -eq 0 ]; then
[[ "$SILENT" -eq "0" ]] && { echo "AC Build was successful!"; }
else
[[ "$SILENT" -eq "0" ]] && { echo "AC Build Failed!"; }
exit 1
fi
fi
# ^ Ending the git pull check
# popd on hifi source dir
popd > /dev/null
fi
}
function setuphifidirs {
pushd $HIFIDIR > /dev/null
if [[ ! -d $RUNDIR ]]; then
[[ "$SILENT" -eq "0" ]] && { echo "Creating Runtime Directory"; }
mkdir $RUNDIR
fi
if [[ ! -d $LOGSDIR ]]; then
mkdir $LOGSDIR
fi
popd > /dev/null
}
function movehifi {
# least error checking here, we pretty much assume that if this is a new compile per the flag
# then you have all the proper folders and files already.
if [ "$NEWHIFI" -eq "1" ]; then
#killrunning
DSDIR="$SRCDIR/highfidelity/hifi/build/domain-server"
ACDIR="$SRCDIR/highfidelity/hifi/build/assignment-client"
cp $DSDIR/domain-server $RUNDIR 2>/dev/null
cp -uRL $DSDIR/resources $RUNDIR 2>/dev/null
cp $ACDIR/assignment-client $RUNDIR 2>/dev/null
changeowner
fi
}
function changeowner {
if [ -d "$HIFIDIR" ]; then
chown -R hifi:hifi $HIFIDIR
fi
}
#function checkifrunning {
# Not used now, but in the future will check if ds/ac is running then offer to restart if so
# For now we just auto restart.
#[[ $(pidof domain-server) -gt 0 ]] && { HIFIRUNNING=1; }
#}
function handlerunhifi {
[[ "$SILENT" -eq "0" ]] && { echo "Running your HiFi Stack as user hifi"; }
touch $CFGNAME
if [ "$NEWHIFI" -eq "1" ]; then
killrunning
export -f runashifi
su hifi -c "bash -c runashifi"
fi
exit 0
}
function runashifi {
HIFIDIR=/home/hifi
HIFIRUNDIR=$HIFIDIR/run
#HIFILOGDIR=$HIFIDIR/logs
cd $HIFIRUNDIR
screen -h 1024 -dmS hifi ./domain-server
screen -h 1024 -dmS hifi ./assignment-client -n 5
}
function handlerc {
if [[ $(grep -c "^. ~/.coalrc" ~/.bashrc) = "0" ]]; then
echo ". ~/.coalrc" >> ~/.bashrc
fi
cat <<EOF > ~/.coalrc
alias killhifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/centos7-kill-hifi.sh)'
alias compilehifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/ubuntu-aws.sh)'
alias runhifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/ubuntu-run-hifi.sh)'
EOF
}
# Right now we have no way to pass a parameter through the bash <(curl) so we always just run anyhow
#function checkauto {
# if [ ! -f $CFGNAME ]; then
# We have not been ran the first time yet
# exit 1
# fi
#}
# Steps to create the magic
# Catch if we are running silent or not
if [ ! -z $1 ]
then
if [ "$1" -eq "1" ]; then
SILENT=1
fi
else
SILENT=0
fi
#checkauto
checkroot
#if [ "$SILENT" -eq "0" ]; then
createuser
doapt
setuphifidirs
#fi
compilehifi
movehifi
handlerc
handlerunhifi