forked from nbq/hifi-compile-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu-compile-hifi.sh
210 lines (168 loc) · 4.97 KB
/
ubuntu-compile-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
#!/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"
#TESTING
#NEWHIFI=1
## 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 {
echo "Installing needed files for compile"
apt-get update -y
apt-get install -y screen git build-essential cmake qt5-default qtscript5-dev libssl-dev qttools5-dev qttools5-dev-tools \
qtmultimedia5-dev libqt5svg5-dev libqt5webkit5-dev libsdl2-dev libasound2 libxmu-dev libxi-dev freeglut3-dev \
libasound2-dev libjack-jackd2-dev libxrandr-dev libqt5xmlpatterns5-dev libqt5xmlpatterns5 \
libqt5xmlpatterns5-private-dev qml-module-qtquick-controls libqt5websockets5-dev
}
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 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 ..
make domain-server
if [ $? -eq 0 ]; then
echo "DS Build was successful!"
else
echo "DS Build Failed!"
exit 1
fi
make assignment-client
if [ $? -eq 0 ]; then
echo "AC Build was successful!"
else
echo "AC Build Failed!"
exit 1
fi
fi
# ^ Ending the git pull check
# popd on hifi source dir
popd > /dev/null
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 $RUNDIR ]]; then
echo "Creating Runtime Directory"
mkdir $RUNDIR
fi
if [[ ! -d $LOGSDIR ]]; then
mkdir $LOGSDIR
fi
popd > /dev/null
#fi
}
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 {
#checkifrunning
#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"
killrunning
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=/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
#./domain-server &>> $HIFILOGDIR/domain-$TIMESTAMP.log&
#./assignment-client -n 3 &>> $HIFILOGDIR/assignment-$TIMESTAMP.log&
}
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-compile-hifi.sh)'
alias runhifi='bash <(curl -Ls https://raw.githubusercontent.com/nbq/hifi-compile-scripts/master/ubuntu-run-hifi.sh)'
EOF
}
# Steps to create the magic
checkroot
createuser
doapt
setuphifidirs
compilehifi
movehifi
handlerc
handlerunhifi