forked from sightsdev/sights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·430 lines (359 loc) · 11.9 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
#!/bin/bash
# SIGHTS installer
# Handles installing and updating SIGHTS
#
# Created by the Semi-Autonomous Rescue Team
# This file is part of the SIGHTS project
#
# https://www.sights.dev/
# https://www.github.com/sightsdev
INSTALL_DIR=/opt
MOTION_VER=4.3.2
update_only='false'
developer_versions='false'
internal_update='false'
apt_updated='false'
set -e
print_detected_ip () {
output="Visit http://localhost$1 on the host machine"
hostname=$(hostname -I)
if [[ $hostname ]]
then
for ip in $hostname
do
output="$output or http://$ip$1"
done
output="$output on any device on the local network."
else
output="$output or connect to a network."
fi
echo "$output"
echo
}
enable_ssh () {
echo -e "\nEnabling SSH..."
systemctl enable ssh
echo -e "\nStarting SSH..."
systemctl start ssh
}
install_dependencies () {
echo -e "\nInstalling dependencies..."
apt update
apt install -y git apache2 python3 python3-pip wget gdebi
apt_updated='true'
echo
}
checkout_release () {
# Check out the latest tag (latest versioned release) for each repository.
# Skip if developer versions are enabled (meaning master will be checked out)
if [ $developer_versions == 'false' ]
then
cd sights
git checkout -f master
git checkout `git tag | sort -V | tail -1`
cd ..
fi
}
install_sights_repositories () {
echo -e "\nDownloading SIGHTS repositories..."
# Get SIGHTS
git clone https://github.com/sightsdev/sights
# Checkout to latest stable release
checkout_release
# Install all Python packages required by SIGHTS
echo -e "\nInstalling required Python packages..."
python3 -m pip install -r sights/src/requirements.txt
echo
}
configure_apache () {
echo -e "\nSetting up Apache..."
# This is the site file that defines where the interface is hosted from
# It also sets up a reverse proxy for Supervisor to work correctly
echo -e "\nEnabling SIGHTS site config..."
ln -sf $INSTALL_DIR/sights/src/configs/apache/sights.conf /etc/apache2/sites-enabled/sights.conf
# This is the required option to allow Apache to host from $INSTALL_DIR
echo -e "\nAllowing Apache to host the interface directory..."
# Only append this to the file if it does not already exist
if grep -Fxq "<Directory ${INSTALL_DIR}/>" /etc/apache2/apache2.conf
then
echo -e "Already done..."
else
echo -e "<Directory ${INSTALL_DIR}/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>" >> /etc/apache2/apache2.conf
fi
echo -e "\nDisabling Apache default site..."
a2dissite 000-default.conf
echo -e "\nEnabling Apache proxy modules..."
a2enmod proxy
a2enmod proxy_http
echo -e "\nStarting Apache..."
service apache2 restart
service apache2 start
service apache2 reload
echo
print_detected_ip "/"
}
try_install_motion () {
echo -e "\nWould you like to attempt to install a prebuilt Motion package?"
echo -e "Currently only available on Raspberry Pi and x64-based platforms."
echo -e "NOTE: This option is not available for the Jetson Nano"
echo -e "\nOtherwise a manual install will be performed.\n"
read -p "Attempt to install a prebuilt package Motion? [y/n] " choice
case "$choice" in
y|Y ) install_motion_auto;;
n|N ) install_motion_manual;;
* ) echo "Invalid response";;
esac
}
install_motion_auto () {
# Only install prebuilt binaries which are available only on supported OSs
if [ $DETECTED_OS == "ubuntu" ] || [ $DETECTED_OS == "debian" ] || [ $DETECTED_OS == "raspbian" ]
then
if [ $DETECTED_CODENAME == "bionic" ] || [ $DETECTED_CODENAME == "cosmic" ] || [ $DETECTED_CODENAME == "buster" ] || [ $DETECTED_CODENAME == "focal" ]
then
echo -e "\nDownloading Motion..."
if [ $DETECTED_OS == "raspbian" ]
then
# Get the armhf binaries (with the pi prefix) for Raspbian
wget https://github.com/Motion-Project/motion/releases/download/release-${MOTION_VER}/pi_${DETECTED_CODENAME}_motion_${MOTION_VER}-1_armhf.deb -O motion.deb
else
# For x86 systems, just use the normal amd64 binaries
wget https://github.com/Motion-Project/motion/releases/download/release-${MOTION_VER}/${DETECTED_CODENAME}_motion_${MOTION_VER}-1_amd64.deb -O motion.deb
fi
echo -e "\nInstalling Motion..."
gdebi -n ./motion.deb
rm ./motion.deb
configure_motion
else
echo -e "\nUnsupported release"
fi
else
echo -e "\nUnsupported distribution"
fi
echo
print_detected_ip ":8080/"
}
install_motion_manual () {
cd /tmp/
echo -e "\nDownloading build script..."
wget https://raw.githubusercontent.com/Motion-Project/motion-packaging/master/builddeb.sh
chmod +x builddeb.sh
echo -e "\nBuilding Motion..."
./builddeb.sh AdhocBuild [email protected] master y any
rm builddeb.sh
echo -e "\nInstalling Motion..."
gdebi -n *motion*.deb
rm *motion*.deb
cd $INSTALL_DIR
configure_motion
}
configure_motion () {
echo -e "\nCreating symlink for Motion configuration files..."
rm -r /etc/motion
ln -sf $INSTALL_DIR/sights/src/configs/motion /etc
echo -e "\nEnabling Motion daemon flag..."
echo "start_motion_daemon=yes" > /etc/default/motion
echo -e "\nEnabling Motion service..."
systemctl enable motion
echo -e "\nStarting Motion service..."
service motion start
service motion restart
}
install_shellinabox () {
echo -e "\nInstalling ShellInABox..."
if [ $apt_updated == 'false' ]; then
apt update
apt_updated='true'
fi
apt install -y shellinabox
echo -e "\nDisabling ShellInABox SSL..."
sed -i 's/SHELLINABOX_ARGS=.*/SHELLINABOX_ARGS="--no-beep --disable-ssl"/' /etc/default/shellinabox
if [ $DETECTED_OS == "raspbian" ]; then
enable_ssh
fi
echo -e "\nStarting shellinabox service..."
service shellinabox start
echo
print_detected_ip ":4200/"
}
configure_supervisor () {
echo -e "\nCreating symlink for Supervisor configuration files..."
ln -sf $INSTALL_DIR/sights/src/configs/supervisor /etc
echo -e "\nInstalling Supervisor SIGHTS extension..."
python3 -m pip install sights/src/supervisor_plugin
echo -e "\nInstalling Supervisor init script"
cp sights/src/configs/systemd/supervisord /etc/init.d/
chmod 755 /etc/init.d/supervisord
chown root:root /etc/init.d/supervisord
update-rc.d supervisord defaults
echo -e "\nRunning Supervisor"
/etc/init.d/supervisord start
echo
print_detected_ip ":9001/"
}
enable_i2c () {
if [ $DETECTED_OS == "raspbian" ]
then
echo -e '\nEnabling i2c-bcm2708 module...'
if grep -q 'i2c-bcm2708' /etc/modules; then
echo 'i2c-bcm2708 module already enabled.'
else
modprobe i2c-bcm2708
echo 'i2c-bcm2708' >> /etc/modules
echo -e '\nEnabled i2c-bcm2708 module.'
fi
echo -e '\nEnabling i2c-dev module...'
if grep -q 'i2c-dev' /etc/modules; then
echo -e 'i2c-dev module already enabled.'
else
modprobe i2c-dev
echo 'i2c-dev' >> /etc/modules
echo -e 'Enabled i2c-dev module.'
fi
echo -e '\nSetting i2c_arm parameter boot config option...'
if grep -q 'dtparam=i2c_arm=on' /boot/config.txt; then
echo -e 'i2c_arm parameter already set.'
else
echo 'dtparam=i2c_arm=on' >> /boot/config.txt
echo -e '\nSet i2c_arm parameter boot config option...'
fi
echo -e '\nRemoving i2c from blacklists...'
if [ -f /etc/modprobe.d/raspi-blacklist.conf ]; then
sed -i 's/^blacklist spi-bcm2708/#blacklist spi-bcm2708/' /etc/modprobe.d/raspi-blacklist.conf
sed -i 's/^blacklist i2c-bcm2708/#blacklist i2c-bcm2708/' /etc/modprobe.d/raspi-blacklist.conf
else
echo 'File raspi-blacklist.conf does not exist, skip this step.'
fi
else
echo -e '\nThis option can only be used on a Raspberry Pi (running Raspbian).'
echo -e '\nFor other devices or operating systems, consult the manufacturers documentation for enabling I2C.'
fi
}
update () {
echo -e "\nUpdating SIGHTS..."
cd sights
git checkout -f master
git pull
cd $INSTALL_DIR
# Checkout appropriate release (stable or dev)
checkout_release
# Update Supervisor
python3 -m pip install sights/src/supervisor_plugin
# Ensure up to date dependencies are installed
python3 -m pip install -r sights/src/requirements.txt
# If update flag specified, just update, then exit
if [ $internal_update == 'false' ]; then
echo -e "\nRestarting Supervisord and SIGHTS..."
service supervisord restart
fi
echo -e "\nUpdate complete!"
echo
print_detected_ip "/"
}
complete_install () {
install_dependencies
install_sights_repositories
configure_apache
try_install_motion
install_shellinabox
configure_supervisor
echo -e "\nInstallation complete! Reboot to ensure proper functionality."
print_detected_ip "/"
}
# Ensure user is running as root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Setup install directory
if [ ! -d "$INSTALL_DIR" ]; then
echo -e "Creating installation directory at $INSTALL_DIR"
mkdir $INSTALL_DIR
fi
# Go to directory
cd $INSTALL_DIR
# Print welcome message
echo " _____ _____ _____ _ _ _______ _____ "
echo " / ____|_ _/ ____| | | |__ __/ ____|"
echo "| (___ | || | __| |__| | | | | (___ "
echo " \___ \ | || | |_ | __ | | | \___ \ "
echo " ____) |_| || |__| | | | | | | ____) |"
echo "|_____/|_____\_____|_| |_| |_| |_____/ "
echo -e "\nSights interactive installer"
echo -e "Created by the Semi-Autonomous Rescue Team"
DETECTED_OS=$(cat /etc/*-release | grep -E "\bID=" | sed 's/ID=//g')
DETECTED_CODENAME=$(cat /etc/*-release | grep "VERSION_CODENAME" | sed 's/VERSION_CODENAME=//g')
echo -e "\nInstalling as: $SUDO_USER"
echo -e "Detected OS: ${DETECTED_OS^} ${DETECTED_CODENAME^}"
if [ $DETECTED_OS == "ubuntu" ] || [ $DETECTED_OS == "debian" ] || [ $DETECTED_OS == "raspbian" ]
then
echo -e "- Using a supported OS -"
else
echo -e "- Using an unsupported OS -"
fi
echo
# Check provided flags
while test $# -gt 0; do
case "$1" in
--update)
update_only='true'
shift
;;
--dev)
developer_versions='true'
shift
;;
--internal)
internal_update='true'
shift
;;
*)
echo "$1 is not a recognized flag!"
exit 1
;;
esac
done
# If developer versions flag specified, notify and continue
if [ $developer_versions == 'true' ]; then
echo -e "Developer versions will be used."
fi
# If update flag specified, just update, then exit
if [ $update_only == 'true' ]; then
echo -e "Performing an update..."
update
exit 0
fi
options=(
"Complete Install"
"Install Dependencies"
"Install SIGHTS Software"
"Configure Apache"
"Install Motion"
"Setup ShellInABox"
"Configure Supervisor"
"Enable I2C"
"Update"
"Detect IPs"
)
PS3="Enter a number (1-${#options[@]}) or q to quit: "
while true; do
select option in "${options[@]}"; do
case "$REPLY" in
1) complete_install ;;
2) install_dependencies ;;
3) install_sights_repositories ;;
4) configure_apache ;;
5) try_install_motion ;;
6) install_shellinabox ;;
7) configure_supervisor ;;
8) enable_i2c ;;
9) update ;;
10) print_detected_ip "/" ;;
q) exit ;;
esac
break
done
done