-
Notifications
You must be signed in to change notification settings - Fork 26
/
install.sh
executable file
·454 lines (334 loc) · 12.1 KB
/
install.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/bin/bash
cat << "EOM"
_ _ _ _ _
| (_) __ _ _ _(_) __| | __ _ __ _| | __ ___ ___ _
| | |/ _` | | | | |/ _` | / _` |/ _` | |/ _` \ \/ / | | |
| | | (_| | |_| | | (_| | | (_| | (_| | | (_| |> <| |_| |
|_|_|\__, |\__,_|_|\__,_| \__, |\__,_|_|\__,_/_/\_\\__, |
|_| |___/ |___/
https://github.com/LiquidGalaxy/liquid-galaxy
https://github.com/LiquidGalaxyLAB/liquid-galaxy
-------------------------------------------------------------
EOM
# Parameters
MASTER=false
INSTALL_DRIVERS=false
MASTER_IP=""
MASTER_USER=$USER
MASTER_HOME=$HOME
MASTER_PASSWORD=""
LOCAL_USER=$USER
MACHINE_ID="1"
MACHINE_NAME="lg"$MACHINE_ID
TOTAL_MACHINES="3"
INSTALL_DRIVERS_CHAR="n"
LG_FRAMES="lg3 lg1 lg2"
OCTET="42"
SCREEN_ORIENTATION="V"
GIT_FOLDER_NAME="liquid-galaxy"
GIT_URL="https://github.com/LiquidGalaxyLAB/liquid-galaxy"
EARTH_DEB="http://dl.google.com/dl/earth/client/current/google-earth-stable_current_i386.deb"
if [ `getconf LONG_BIT` = "64" ]; then
EARTH_DEB="http://dl.google.com/dl/earth/client/current/google-earth-stable_current_amd64.deb"
fi
EARTH_FOLDER="/opt/google/earth/pro/"
NETWORK_INTERFACE=$(/sbin/route -n | grep "^0.0.0.0" | rev | cut -d ' ' -z -f1 | rev)
NETWORK_INTERFACE_MAC=$(/sbin/ifconfig | grep $NETWORK_INTERFACE | awk '{print $5}')
SSH_PASSPHRASE=""
USER_PATH=$(pwd)/$GIT_FOLDER_NAME
read -p "Machine id (i.e. 1 for lg1) (1 == master): " MACHINE_ID
if [ "$(echo $MACHINE_ID | cut -c-2)" == "lg" ]; then
MACHINE_ID="$(echo $MACHINE_NAME | cut -c3-)"
fi
MACHINE_NAME="lg"$MACHINE_ID
if [ $MACHINE_ID == "1" ]; then
MASTER=true
MASTER_IP=$(/sbin/ifconfig | grep --after-context=1 $NETWORK_INTERFACE | awk -F " Bcast" '{print $1}' | awk -F "inet addr:" '{print $2}')
echo "Save the IP ADDRESS of this machine: $MASTER_IP"
read -p "Press any key to continue"
else
echo "Make sure Master machine (lg1) is connected to the network before proceding!"
read -p "Master machine IP (i.e. 192.168.1.42): " MASTER_IP
read -p "Master local user password (i.e. lg password): " MASTER_PASSWORD
fi
read -p "Total machines count (i.e. 3): " TOTAL_MACHINES
read -p "Unique number that identifies your Galaxy (octet) (i.e. 42): " OCTET
read -p "Do you want to install extra drivers? (y/n): " INSTALL_DRIVERS_CHAR
#
# Pre-start
#
PRINT_IF_NOT_MASTER=""
if [ $MASTER == false ]; then
PRINT_IF_NOT_MASTER=$(cat <<- EOM
MASTER_IP: $MASTER_IP
MASTER_USER: $MASTER_USER
MASTER_HOME: $MASTER_HOME
MASTER_PASSWORD: $MASTER_PASSWORD
EOM
)
fi
mid=$((TOTAL_MACHINES / 2))
array=()
for j in `seq $((mid + 2)) $TOTAL_MACHINES`;
do
array+=("lg"$j)
done
for j in `seq 1 $((mid+1))`;
do
array+=("lg"$j)
done
printf -v LG_FRAMES "%s " "${array[@]}"
if [ $INSTALL_DRIVERS_CHAR == "y" ] || [$INSTALL_DRIVERS_CHAR == "Y" ] ; then
INSTALL_DRIVERS=true
fi
cat << EOM
Liquid Galaxy will be installed with the following configuration:
MASTER: $MASTER
LOCAL_USER: $LOCAL_USER
MACHINE_ID: $MACHINE_ID
MACHINE_NAME: $MACHINE_NAME $PRINT_IF_NOT_MASTER
TOTAL_MACHINES: $TOTAL_MACHINES
OCTET (UNIQUE NUMBER): $OCTET
INSTALL_DRIVERS: $INSTALL_DRIVERS
GIT_URL: $GIT_URL
GIT_FOLDER: $GIT_FOLDER_NAME
EARTH_DEB: $EARTH_DEB
EARTH_FOLDER: $EARTH_FOLDER
NETWORK_INTERFACE: $NETWORK_INTERFACE
NETWORK_MAC_ADDRESS: $NETWORK_INTERFACE_MAC
Is it correct? Press any key to continue or CTRL-C to exit
EOM
read
if [ "$(cat /etc/os-release | grep NAME=\"Ubuntu\")" == "" ]; then
echo "Warning!! This script is meant to be run on an Ubuntu OS. It may not work as expected."
echo -n "Press any key to continue or CTRL-C to exit"
read
fi
if [[ $EUID -eq 0 ]]; then
echo "Do not run it as root!" 1>&2
exit 1
fi
# Initialize sudo access
sudo -v
FOLDER_EXIST=$(find / -iname $GIT_FOLDER_NAME -print -quit 2>/dev/null)
if [ "$FOLDER_EXIST" == "" ]; then
sudo apt install git
git clone $GIT_URL
else
echo "Folder already exists"
USER_PATH=$FOLDER_EXIST
fi
#
# General
#
export DEBIAN_FRONTEND=noninteractive
# Update OS
echo "Checking for system updates..."
sudo apt-get -yq upgrade
echo "Upgrading system packages ..."
sudo apt-get -yq update
echo "Installing new packages..."
sudo apt-get install -yq python3 python3-pip tcpdump git chromium-browser nautilus openssh-server sshpass squid3 squid-cgi apache2 xdotool unclutter lsb-core lsb libc6-dev-i386 gcc
pip3 install evdev
echo "Installing lsb packages..."
sudo apt-get install -yq lsb-core lsb
if [ $INSTALL_DRIVERS == true ] ; then
echo "Installing extra drivers..."
sudo apt-get install -yq libfontconfig1:i386 libx11-6:i386 libxrender1:i386 libxext6:i386 libglu1-mesa:i386 libglib2.0-0:i386 libsm6:i386
sudo apt-get install nvidia-361
fi
echo "Installing Google Earth..."
wget -q $EARTH_DEB
sudo dpkg -i google-earth*.deb
rm google-earth*.deb
# OS config tweaks (like disabling idling, hiding launcher bar, ...)
echo "Setting system configuration..."
sudo tee /etc/lightdm/lightdm.conf > /dev/null << EOM
[Seat:*]
autologin-guest=false
autologin-user=$LOCAL_USER
autologin-user-timeout=0
autologin-session=ubuntu
EOM
echo autologin-user=lg >> sudo /etc/lightdm/lightdm.conf
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
gsettings set org.gnome.desktop.session idle-delay 0
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.settings-daemon.plugins.power idle-dim false
echo -e 'Section "ServerFlags"\nOption "blanktime" "0"\nOption "standbytime" "0"\nOption "suspendtime" "0"\nOption "offtime" "0"\nEndSection' | sudo tee -a /etc/X11/xorg.conf > /dev/null
gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ launcher-hide-mode 1
sudo update-alternatives --set x-www-browser /usr/bin/chromium-browser
sudo update-alternatives --set gnome-www-browser /usr/bin/chromium-browser
sudo apt-get remove --purge -yq update-notifier*
#
# Liquid Galaxy
#
# Setup Liquid Galaxy files
echo "Setting up Liquid Galaxy..."
sudo cp -r $USER_PATH/earth/ $HOME
sudo ln -s $EARTH_FOLDER $HOME/earth/builds/latest
awk '/LD_LIBRARY_PATH/{print "export LC_NUMERIC=en_US.UTF-8"}1' $HOME/earth/builds/latest/googleearth | sudo tee $HOME/earth/builds/latest/googleearth > /dev/null
# Enable solo screen for slaves
if [ $MASTER != true ]; then
sudo sed -i -e 's/slave_x/slave_'${MACHINE_ID}'/g' $HOME/earth/kml/slave/myplaces.kml
sudo sed -i -e 's/sync_nlc_x/sync_nlc_'${MACHINE_ID}'/g' $HOME/earth/kml/slave/myplaces.kml
fi
sudo cp -r $USER_PATH/gnu_linux/home/lg/. $HOME
for file in *; do
sudo mv "$HOME/dotfiles/$file" "$HOME/dotfiles/.$file"
done
sudo cp -r . $HOME
cd - > /dev/null
sudo cp -r $USER_PATH/gnu_linux/etc/ $USER_PATH/gnu_linux/patches/ $USER_PATH/gnu_linux/sbin/ /
sudo chmod 0440 /etc/sudoers.d/42-lg
sudo ln -s /etc/apparmor.d/sbin.dhclient /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/sbin.dhclient
sudo /etc/init.d/apparmor restart > /dev/null
sudo chown -R $LOCAL_USER:$LOCAL_USER $HOME
sudo chown $LOCAL_USER:$LOCAL_USER $HOME/earth/builds/latest/drivers.ini
sudo chmod +0666 /dev/uinput
# Configure SSH
if [ $MASTER == true ]; then
echo "Setting up SSH..."
$HOME/tools/clean-ssh.sh
else
echo "Starting SSH files sync with master..."
sshpass -p "$MASTER_PASSWORD" scp -o StrictHostKeyChecking=no $MASTER_IP:$MASTER_HOME/ssh-files.zip $HOME/
unzip $HOME/ssh-files.zip -d $HOME/ > /dev/null
sudo cp -r $HOME/ssh-files/etc/ssh /etc/
sudo cp -r $HOME/ssh-files/root/.ssh /root/ 2> /dev/null
sudo cp -r $HOME/ssh-files/user/.ssh $HOME/
sudo rm -r $HOME/ssh-files/
sudo rm $HOME/ssh-files.zip
fi
sudo chmod 0600 $HOME/.ssh/lg-id_rsa
sudo chmod 0600 /root/.ssh/authorized_keys
sudo chmod 0600 /etc/ssh/ssh_host_dsa_key
sudo chmod 0600 /etc/ssh/ssh_host_ecdsa_key
sudo chmod 0600 /etc/ssh/ssh_host_rsa_key
sudo chown -R $LOCAL_USER:$LOCAL_USER $HOME/.ssh
sudo chmod 777 /tmp/
# prepare SSH files for other nodes (slaves)
if [ $MASTER == true ]; then
mkdir -p ssh-files/etc
sudo cp -r /etc/ssh ssh-files/etc/
mkdir -p ssh-files/root/
sudo cp -r /root/.ssh ssh-files/root/ 2> /dev/null
mkdir -p ssh-files/user/
sudo cp -r $HOME/.ssh ssh-files/user/
sudo zip -FSr "ssh-files.zip" ssh-files
if [ $(pwd) != $HOME ]; then
sudo mv ssh-files.zip $HOME/ssh-files.zip
fi
sudo chown -R $LOCAL_USER:$LOCAL_USER $HOME/ssh-files.zip
sudo rm -r ssh-files/
fi
# Screens configuration
cat > $HOME/personavars.txt << 'EOM'
DHCP_LG_FRAMES="lg3 lg1 lg2"
DHCP_LG_FRAMES_MAX=3
FRAME_NO=$(cat $HOME/frame 2>/dev/null)
DHCP_LG_SCREEN="$(( ${FRAME_NO} + 1 ))"
DHCP_LG_SCREEN_COUNT=1
DHCP_OCTET=42
DHCP_LG_PHPIFACE="http://lg1:81/"
DHCP_EARTH_PORT=45678
DHCP_EARTH_BUILD="latest"
DHCP_EARTH_QUERY="/tmp/query.txt"
DHCP_MPLAYER_PORT=45680
EOM
sed -i "s/\(DHCP_LG_FRAMES *= *\).*/\1\"$LG_FRAMES\"/" $HOME/personavars.txt
sed -i "s/\(DHCP_LG_FRAMES_MAX *= *\).*/\1$TOTAL_MACHINES/" $HOME/personavars.txt
sed -i "s/\(DHCP_OCTET *= *\).*/\1$OCTET/" $HOME/personavars.txt
sudo $HOME/bin/personality.sh $MACHINE_ID $OCTET > /dev/null
# Network configuration
sudo tee -a "/etc/network/interfaces" > /dev/null << EOM
auto eth0
iface eth0 inet dhcp
EOM
sudo sed -i "s/\(managed *= *\).*/\1true/" /etc/NetworkManager/NetworkManager.conf
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$NETWORK_INTERFACE_MAC\",KERNEL==\"$NETWORK_INTERFACE\",NAME=\"eth0\"" | sudo tee /etc/udev/rules.d/10-network.rules > /dev/null
sudo sed -i '/lgX.liquid.local/d' /etc/hosts
sudo sed -i '/kh.google.com/d' /etc/hosts
sudo sed -i '/10.42./d' /etc/hosts
sudo tee -a "/etc/hosts" > /dev/null 2>&1 << EOM
10.42.$OCTET.1 lg1
10.42.$OCTET.2 lg2
10.42.$OCTET.3 lg3
10.42.$OCTET.4 lg4
10.42.$OCTET.5 lg5
10.42.$OCTET.6 lg6
10.42.$OCTET.7 lg7
10.42.$OCTET.8 lg8
EOM
sudo sed -i '/10.42./d' /etc/hosts.squid
sudo tee -a "/etc/hosts.squid" > /dev/null 2>&1 << EOM
10.42.$OCTET.1 lg1
10.42.$OCTET.2 lg2
10.42.$OCTET.3 lg3
10.42.$OCTET.4 lg4
10.42.$OCTET.5 lg5
10.42.$OCTET.6 lg6
10.42.$OCTET.7 lg7
10.42.$OCTET.8 lg8
EOM
sudo tee "/etc/iptables.conf" > /dev/null << EOM
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [43616:6594412]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p tcp -m multiport --dports 22 -j ACCEPT
-A INPUT -s 10.42.0.0/16 -p udp -m udp --dport 161 -j ACCEPT
-A INPUT -s 10.42.0.0/16 -p udp -m udp --dport 3401 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 81,8111,8112 -j ACCEPT
-A INPUT -p udp -m multiport --dports 8113 -j ACCEPT
-A INPUT -s 10.42.$OCTET.0/24 -p tcp -m multiport --dports 80,3128,3130 -j ACCEPT
-A INPUT -s 10.42.$OCTET.0/24 -p udp -m multiport --dports 80,3128,3130 -j ACCEPT
-A INPUT -s 10.42.$OCTET.0/24 -p tcp -m multiport --dports 9335 -j ACCEPT
-A INPUT -s 10.42.$OCTET.0/24 -d 10.42.$OCTET.255/32 -p udp -j ACCEPT
-A INPUT -j DROP
-A FORWARD -j DROP
COMMIT
*nat
:PREROUTING ACCEPT [52902:8605309]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [358:22379]
:POSTROUTING ACCEPT [358:22379]
COMMIT
EOM
# Launch on boot
mkdir -p $HOME/.config/autostart/
echo -e "[Desktop Entry]\nName=LG\nExec=bash "$HOME"/earth/scripts/launch-earth.sh\nType=Application" > $HOME"/.config/autostart/lg.desktop"
gcc -m32 -o "$HOME"/write-event $GIT_FOLDER_NAME/input_event/write-event.c
sudo chmod 0755 "$HOME"/write-event
# Web interface
if [ $MASTER == true ]; then
echo "Installing web interface (master only)..."
sudo apt-get -yq install php php-cgi libapache2-mod-php
sudo touch /etc/apache2/httpd.conf
sudo sed -i '/accept.lock/d' /etc/apache2/apache2.conf
sudo rm /var/www/html/index.html
sudo cp -r $USER_PATH/php-interface/. /var/www/html/
sudo chown -R $LOCAL_USER:$LOCAL_USER /var/www/html/
fi
# Cleanup
sudo rm -r $USER_PATH
#
# Global cleanup
#
echo "Cleaning up..."
sudo apt-get -yq autoremove
if [ `getconf LONG_BIT` = "64" ]; then
echo "Installing additional libraries for 64 bit OS"
sudo apt-get install -y libfontconfig1:i386 libx11-6:i386 libxrender1:i386 libxext6:i386 libglu1-mesa:i386 libglib2.0-0:i386 libsm6:i386
fi
#Make chromium default browser
xdg-settings set default-web-browser chromium-browser.desktop
echo "Liquid Galaxy installation completed! :-)"
echo "Press ENTER key to reboot now"
read
reboot
exit 0