forked from nbq/hifi-compile-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
centos7-recompile-hifi.sh
262 lines (215 loc) · 6.78 KB
/
centos7-recompile-hifi.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
# Home Directory for HifiUser
HIFIDIR="/usr/local/hifi"
# Last Compile Backup Directory
LASTCOMPILE="$HIFIDIR/last-compile"
# Runtime Directory Location
RUNDIR="$HIFIDIR/run"
# Log Directory
LOGSDIR="$HIFIDIR/logs"
# Source Storage Dir
SRCDIR="/usr/local/src"
## Functions ##
function checkroot {
[ `whoami` = root ] || { echo "Please run as root"; exit 1; }
}
function writecommands {
# Always rewrite just incase something changed
cat <<EOF > /etc/profile.d/coal.sh
alias compilehifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/centos7-compile-hifi.sh)'
alias recompilehifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/centos7-recompile-hifi.sh)'
alias runhifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/centos7-run-hifi.sh)'
alias killhifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/centos7-kill-hifi.sh)'
EOF
}
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 {
if [[ $NEWHIFI -eq 1 || HIFIRUNNING -eq 1 ]]; then
echo "Running your HiFi Stack as user hifi"
echo "To update your install later, just type 'compilehifi' to begin this safe process again - NO DATA IS LOST"
export -f runashifi
su hifi -c "bash -c runashifi"
exit 0
fi
}
function runashifi {
# Everything here is run as the user hifi
TIMESTAMP=$(date '+%F')
HIFIDIR=/usr/local/hifi
HIFIRUNDIR=$HIFIDIR/run
HIFILOGDIR=$HIFIDIR/logs
cd $HIFIRUNDIR
./domain-server &>> $HIFILOGDIR/domain-$TIMESTAMP.log&
./assignment-client -n 3 &>> $HIFILOGDIR/assignment-$TIMESTAMP.log&
}
function doyum {
echo "Updating Your OS - If you see Kernel listed you should restart when done and after type 'runhifi' to restart HighFidelity."
yum update -y
echo "Installing EPEL Repo."
yum install epel-release -y > /dev/null 2>&1
echo "Installing compile tools."
yum groupinstall "development tools" -y > /dev/null 2>&1
echo "Installing base needed tools."
yum install openssl-devel git wget sudo libXmu-* libXi-devel libXrandr libXrandr-devel qt5-qt* -y > /dev/null 2>&1
}
function killrunning {
echo "Killing Running Processess"
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
useradd -s /bin/bash -r -m -d $HIFIDIR hifi
NEWHIFI=1
fi
}
function removeuser {
userdel -r hifi > /dev/null 2>&1
}
function changeowner {
if [ -d "$HIFIDIR" ]; then
chown -R hifi:hifi $HIFIDIR
fi
}
function setuphifidirs {
if [[ ! -d $HIFIDIR ]]; then
echo "Creating $HIFIDIR"
mkdir $HIFIDIR
NEWHIFI=1
fi
# check if this is a new compile, otherwise move handle that process
if [[ $NEWHIFI -eq 1 ]]; then
pushd $HIFIDIR > /dev/null
if [[ ! -d "$LASTCOMPILE" ]]; then
echo "Creating Last-Compile Backup Directory"
mkdir $LASTCOMPILE
fi
if [[ ! -d "$RUNDIR" ]]; then
echo "Creating Runtime Directory"
mkdir $RUNDIR
fi
if [[ -a "$RUNDIR/assignment-client" && -a "$RUNDIR/domain-server" && -d "$RUNDIR/resources" ]]; then
echo "Removing Old Last-Compile Backup"
rm -rf $LASTCOMPILE/*
echo "Backing Up AC"
mv "$RUNDIR/assignment-client" $LASTCOMPILE
echo "Backing Up DS"
mv "$RUNDIR/domain-server" $LASTCOMPILE
echo "Making a Copy Of The Resources Folder"
cp -R "$RUNDIR/resources" $LASTCOMPILE
fi
if [[ ! -d $LOGSDIR ]]; then
mkdir $LOGSDIR
fi
popd > /dev/null
fi
}
function handlecmake {
if [[ ! -f "cmake-3.0.2.tar.gz" ]]; then
wget http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz
tar -xzvf cmake-3.0.2.tar.gz
cd cmake-3.0.2/
./configure --prefix=/usr
gmake && gmake install
cd ..
fi
}
function compilehifi {
# NOTE - This currently assumes /usr/local/src and does not move forward if the source dir does not exist - todo: fix
if [[ -d "$SRCDIR" ]]; then
pushd $SRCDIR > /dev/null
# handle install and compile of cmake
if [[ ! -f "/usr/bin/cmake" ]]; then
handlecmake
fi
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 src
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
echo "Already up to date with last commit."
else
NEWHIFI=1
fi
if [[ $NEWHIFI -eq 1 ]]; then
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 -DGET_LIBOVR=1 ..
make domain-server > $LOGSDIR/last_compile.log
if [ $? -eq 0 ]; then
echo "DS Build was successful!" >> $LOGSDIR/last_compile.log
else
echo "DS Build Failed!" >> $LOGSDIR/last_compile.log
exit 1
fi
make assignment-client >> $LOGSDIR/last_compile.log
if [ $? -eq 0 ]; then
echo "AC Build was successful!" >> $LOGSDIR/last_compile.log
else
echo "AC Build Failed!" >> $LOGSDIR/last_compile.log
exit 1
fi
setwebperm
fi
# ^ Ending the git pull check
# popd on hifi source dir
popd > /dev/null
fi
}
function setwebperm {
chown -R hifi:hifi $SRCDIR/highfidelity/hifi/domain-server/resources/web
}
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
setwebperm
DSDIR="$SRCDIR/highfidelity/hifi/build/domain-server"
ACDIR="$SRCDIR/highfidelity/hifi/build/assignment-client"
cp $DSDIR/domain-server $RUNDIR
cp -R $DSDIR/resources $RUNDIR
cp $ACDIR/assignment-client $RUNDIR
changeowner
fi
}
## End Functions ##
# Make sure only root can run this
checkroot
# Make our HiFi user if needed
createuser
# Handle Yum Install Commands
doyum
# Deal with the source code and compile highfidelity
compilehifi
if [ $? -gt 0 ]; then
echo "Command compilehifi failed, see log file $LOGSDIR/last_compile.log" >> $LOGSDIR/last_compile.log
exit 1
fi
# setup hifi folders
setuphifidirs
# Copy new binaries then change owner
movehifi
# Copy commands to be run to .bashrc
writecommands
# Handle re-running the hifi stack as needed here
handlerunhifi