forked from theyosh/TerrariumPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·263 lines (211 loc) · 8.04 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
#!/bin/bash
BASEDIR=$(dirname $(readlink -nf $0))
SCRIPT_USER=`who -m | awk '{print $1}'`
SCRIPT_USER_ID=`id -u ${SCRIPT_USER}`
VERSION=`grep ^version defaults.cfg | cut -d' ' -f 3`
WHOAMI=`whoami`
LOGFILE="${BASEDIR}/log/terrariumpi.log"
ACCESSLOGFILE="${BASEDIR}/log/terrariumpi.access.log"
TMPFS="/run/user/${SCRIPT_USER_ID}"
if [ "${WHOAMI}" != "root" ]; then
echo "Start TerrariumPI installation as user root"
echo "sudo ./install.sh"
exit 0
fi
#set -e
# Install dialog for further installation
if ! hash whiptail 2>/dev/null; then
aptitude -y install whiptail
fi
whiptail --backtitle "TerrariumPI v. ${VERSION}" --title " TerrariumPI Installer " --yesno "TerrariumPI is going to be installed to run with user '${SCRIPT_USER}'. If this is not the right user stop the installation now!\n\nDo you want to continue?" 0 60
case $? in
1|255) whiptail --backtitle "TerrariumPI v. ${VERSION}" --title " TerrariumPI Installer " --msgbox "TerrariumPI installation is aborted" 0 60
exit 0
;;
esac
# Clean up first
whiptail --backtitle "TerrariumPI v. ${VERSION}" --title " TerrariumPI Installer " --yesno "TerrariumPI is going to remove not needed programs in order to free up diskspace and make future updates faster. All desktop software will be removed.\n\nDo you want to remove not needed programs?" 0 0
case $? in
0) whiptail --backtitle "TerrariumPI v. ${VERSION}" --title " TerrariumPI Installer " --infobox "TerrariumPI is removing not needed programs" 0 0
debconf-apt-progress -- apt-get -y remove wolfram-engine sonic-pi oracle-java8-jdk desktop-base gnome-desktop3-data libgnome-desktop-3-10 epiphany-browser-data epiphany-browser nuscratch scratch wiringpi "^libreoffice.*"
debconf-apt-progress -- apt-get -y autoremove
;;
esac
# Install required packages to get the terrarium software running
debconf-apt-progress -- apt-get -y update
debconf-apt-progress -- apt-get -y full-upgrade
debconf-apt-progress -- apt-get -y install libftdi1 screen git subversion watchdog build-essential i2c-tools owfs ow-shell sqlite3 vlc-nox libasound2-dev sispmctl lshw python-imaging python-dateutil python-ow python-rpi.gpio python-psutil python-dev python-picamera python-opencv python-pip python-pigpio python-requests python-mediainfodll python-gpiozero python-smbus libffi-dev
PROGRESS=55
# Update submodules if downloaded through tar or zip
(
cd "${BASEDIR}/"
cat <<EOF
XXX
$PROGRESS
Install required software\n\nInstalling base software ...
XXX
EOF
PROGRESS=$((PROGRESS + 10))
cat <<EOF
XXX
$PROGRESS
Install required software\n\nInstalling base software ...
XXX
EOF
git submodule init > /dev/null
PROGRESS=$((PROGRESS + 10))
cat <<EOF
XXX
$PROGRESS
Install required software\n\nInstalling base software ...
XXX
EOF
git submodule update > /dev/null
cd "${BASEDIR}/.."
PIP_MODULES="gevent untangle uptime bottle bottle_websocket pylibftdi pyalsaaudio pyserial"
for PIP_MODULE in ${PIP_MODULES}
do
PROGRESS=$((PROGRESS + 2))
cat <<EOF
XXX
$PROGRESS
Install required software\n\nInstalling python module ${PIP_MODULE} ...
XXX
EOF
pip install -q --upgrade ${PIP_MODULE}
done
PROGRESS=$((PROGRESS + 2))
cat <<EOF
XXX
$PROGRESS
Install required software\n\nCloning Adafruit DHT python library ...
XXX
EOF
if [ ! -d Adafruit_Python_DHT ]
then
git clone https://github.com/adafruit/Adafruit_Python_DHT.git >/dev/null
fi
PROGRESS=$((PROGRESS + 2))
cat <<EOF
XXX
$PROGRESS
Install required software\n\nUpdating Adafruit DHT python library ...
XXX
EOF
cd Adafruit_Python_DHT
git pull > /dev/null
PROGRESS=$((PROGRESS + 2))
cat <<EOF
XXX
$PROGRESS
Install required software\n\nCompiling Adafruit DHT python library ...
XXX
EOF
python setup.py -q install 2> /dev/null
cd "${BASEDIR}"
chown ${SCRIPT_USER}. .
chown ${SCRIPT_USER}. * -Rf
PROGRESS=100
cat <<EOF
XXX
$PROGRESS
Install required software\n\nDone! ...
XXX
EOF
sleep 1
) | whiptail --backtitle "TerrariumPI v. ${VERSION}" --title " TerrariumPI Installer " --gauge "Install required software\n\nInstalling python module ${PIP_MODULE} ..." 0 60 0
# Basic config:
# Enable 1Wire en I2C during boot
if [ -f /boot/config.txt ]; then
if [ `grep -ic "#dtparam=i2c_arm=on" /boot/config.txt` -eq 1 ]; then
sed -i.bak 's/^#dtparam=i2c_arm=on/dtparam=i2c_arm=on/' /boot/config.txt
fi
if [ `grep -ic "dtparam=i2c_arm=on" /boot/config.txt` -eq 0 ]; then
echo "dtparam=i2c_arm=on" >> /boot/config.txt
fi
if [ `grep -ic "dtoverlay=w1-gpio" /boot/config.txt` -eq 0 ]; then
echo "dtoverlay=w1-gpio" >> /boot/config.txt
fi
# Enable camera
if [ `grep -ic "gpu_mem=" /boot/config.txt` -eq 0 ]; then
echo "gpu_mem=128" >> /boot/config.txt
fi
fi
# Create needed groups
groupadd -f dialout 2> /dev/null
groupadd -f sispmctl 2> /dev/null
groupadd -f gpio 2> /dev/null
# Add user to all groupds
usermod -a -G dialout,sispmctl,gpio ${SCRIPT_USER} 2> /dev/null
# Docu https://pylibftdi.readthedocs.io/
# Make sure that the normal Pi user can read and write to the usb driver
echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GROUP="dialout", MODE="0660"' > /etc/udev/rules.d/99-libftdi.rules
echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", GROUP="dialout", MODE="0660"' >> /etc/udev/rules.d/99-libftdi.rules
# https://pypi.python.org/pypi/pysispm
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="04b4", ATTR{idProduct}=="fd10", GROUP="sispmctl", MODE="660"' > /etc/udev/rules.d/60-sispmctl.rules
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="04b4", ATTR{idProduct}=="fd11", GROUP="sispmctl", MODE="660"' >> /etc/udev/rules.d/60-sispmctl.rules
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="04b4", ATTR{idProduct}=="fd12", GROUP="sispmctl", MODE="660"' >> /etc/udev/rules.d/60-sispmctl.rules
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="04b4", ATTR{idProduct}=="fd13", GROUP="sispmctl", MODE="660"' >> /etc/udev/rules.d/60-sispmctl.rules
# Reload udev controll
udevadm control --reload-rules
# Install 1 Wire I2C stuff
if [ -f /etc/owfs.conf ]; then
sed -i.bak 's/^server: FAKE = DS18S20,DS2405/#server: FAKE = DS18S20,DS2405/' /etc/owfs.conf
if [ `grep -ic "server: device=/dev/i2c-1" /etc/owfs.conf` -eq 0 ]; then
echo "server: device=/dev/i2c-1" >> /etc/owfs.conf
fi
fi
if [ -f /etc/modprobe.d/raspi-blacklist.conf ]; then
sed -i.bak 's/^blacklist i2c-bcm2708/#blacklist i2c-bcm2708/' /etc/modprobe.d/raspi-blacklist.conf
fi
if [ -f /etc/modules ]; then
if [ `grep -ic "i2c-dev" /etc/modules` -eq 0 ]; then
echo "i2c-dev" >> /etc/modules
fi
fi
# Make sure pigpiod is started at boot, and that user PI can restart it with sudo command
echo "${SCRIPT_USER} ALL=(ALL) NOPASSWD: /usr/sbin/service pigpiod restart" > /etc/sudoers.d/terrariumpi
systemctl enable pigpiod
# Remove unneeded OWS services
update-rc.d -f owftpd remove
update-rc.d -f owfhttpd remove
# Set the timezone
dpkg-reconfigure tzdata
# Move log file to temprorary mount
if grep -qs "${TMPFS} " /proc/mounts; then
# TMPFS user dir is available....
if ! [ -h "${LOGFILE}" ]; then
# There is not a symlink to tmpfs partition
if [ -f "${LOGFILE}" ]; then
# There is an existing logfile already. Move it
mv ${LOGFILE} ${TMPFS}
fi
su -c "ln -s ${TMPFS}/terrariumpi.log ${LOGFILE}" -s /bin/bash ${SCRIPT_USER}
fi
if ! [ -h "${ACCESSLOGFILE}" ]; then
# There is not a symlink to tmpfs partition
if [ -f "${ACCESSLOGFILE}" ]; then
# There is an existing logfile already. Move it
mv ${ACCESSLOGFILE} ${TMPFS}
fi
su -c "ln -s ${TMPFS}/terrariumpi.access.log ${ACCESSLOGFILE}" -s /bin/bash ${SCRIPT_USER}
fi
fi
# Make TerrariumPI start during boot
if [ `grep -ic "start.sh" /etc/rc.local` -eq 0 ]; then
sed -i.bak "s@^exit 0@# Starting TerrariumPI server\n${BASEDIR}/start.sh\n\nexit 0@" /etc/rc.local
fi
# We are done!
sync
whiptail --backtitle "TerrariumPI v. ${VERSION}" --title " TerrariumPI Installer " --yesno "TerrariumPI is installed/upgraded. To make sure that all is working please reboot.\n\nDo you want to reboot now?" 0 60
case $? in
0)
for SECONDS in {5..1}
do
echo "TerrariumPI installation is rebooting the Raspberry PI in ${SECONDS} seconds..."
sleep 1
done
sync
reboot
;;
esac