forked from SvenVD/rpisurv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·95 lines (75 loc) · 3.05 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
#!/bin/bash
if [ ! "$BASH_VERSION" ] ; then
echo "ERROR: Please use bash not sh or other shells to run this installer. You can also run this script directly like ./install.sh"
exit 1
fi
get_init_sys() {
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
SYSTEMD=1
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
SYSTEMD=0
else
echo "Unrecognised init system"
return 1
fi
}
echo "Use this installer on your own risk. Make sure this host does not contain important data and is replacable"
echo "This installer will disable graphical login on your pi, please revert with the raspi-config command if needed"
echo
echo "By using this software, you agree that by default limited and non-sensitive (runtime and unique id) stats"
echo "will be sent regularly to a collector server. You can disable this anytime by changing the update_stats: config option to False."
echo "This has been introduced to get a general idea about how big the rpisurv community is."
echo
echo "Do you want to continue press <Enter>, Ctrl-C to cancel"
read
get_init_sys
BASEPATH="$(cd $(dirname "${BASH_SOURCE[0]}");pwd)"
#Install needed packages
sudo apt-get install python-pygame python-yaml python libraspberrypi-bin -y
#Only install omxplayer if it isn't already installed (from source or package)
if [ ! -e /usr/bin/omxplayer ];then
sudo apt-get install omxplayer -y
else
echo "Omxplayer install detected, not reinstalling"
fi
#Prevent starting up in graphical mode, we do not need this -> save resources
if [ $SYSTEMD -eq 1 ]; then
sudo systemctl set-default multi-user.target
#enable systemd-timesyncd
sudo timedatectl set-ntp true
else
[ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable
#Enable timesync
TIMESYNCCMD="/usr/sbin/service ntp stop 2>/dev/null 1>&2; /usr/sbin/ntpdate 0.debian.pool.ntp.org 2>/dev/null 1>&2; /usr/sbin/service ntp start 2>/dev/null 1>&2"
if ! grep -q "^$TIMESYNCCMD" /etc/rc.local ;then
sudo echo "$TIMESYNCCMD" >> /etc/rc.local
fi
fi
SOURCEDIR="$BASEPATH/surveillance"
MAINSOURCE="surveillance.py"
CONFFILE="conf/surveillance.yml"
DESTPATH="/usr/local/bin/rpisurv"
sudo mkdir -p "$DESTPATH"
sudo rsync -av "$SOURCEDIR/" "$DESTPATH/"
STARTUPCMD="cd $DESTPATH; python "$MAINSOURCE" &"
if [ $SYSTEMD -eq 1 ]; then
#Remove old way of starting rpisurv
sudo sed -i /$MAINSOURCE/d /etc/rc.local
sudo cp -v rpisurv /usr/bin/
sudo chmod 700 /usr/bin/rpisurv
sudo cp -v rpisurv.service /etc/systemd/system/
sudo chmod 644 /etc/systemd/system/rpisurv.service
sudo systemctl daemon-reload
sudo systemctl enable rpisurv
else
#No systemd detected use old method to start
if ! grep -q "^$STARTUPCMD" /etc/rc.local ;then
#Filter out exit 0 command if present
sudo sed -i '/exit 0$/d' /etc/rc.local
sudo echo "$STARTUPCMD" >> /etc/rc.local
#Add exit 0 as last line for good practise
sudo echo "exit 0" >> /etc/rc.local
fi
fi
#Link config file into /etc as convenient way to edit
sudo ln -fs $DESTPATH/"$CONFFILE" /etc/rpisurv