-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbootstrap
executable file
·325 lines (260 loc) · 10.3 KB
/
bootstrap
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
#!/bin/bash
#
# This script is for use with the Open Glider Network FLARM Detection System only
# Any other uses are NOT authorised
#
# Copyright (c) 2014, Melissa Jenkins, Temeletry Limited ([email protected])
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# - This code must only be used as part of OGN (Open Glider Network)
#
# - Neither the name of Temeletry Limited nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Code has been sponsored by Temeletry Limited (http://www.temeletry.co.uk)
#
#
# This is a bootstrap script. It is designed to install the OGN
# software on any operating system installation. It has been tested
# on BPI and RPI and is believe to work on generic Linux installations
#
progress() {
echo ""
echo -e "\033[32m * $1\033[0m"
}
error() {
echo "#####################################################"
echo -e "\033[31m\033[1m ! $2 \033[0m"
}
echo "starting..."
url="https://ognconfig.onglide.com/files/v2.1"
sudo="sudo"
which sudo || {
if [ `whoami` == 'root' ] ; then
sudo () {
$@
}
sudo=""
progress "Not using sudo - running as root"
else
error "Please install sudo or run this script as root"
exit 1
fi
}
if [ -z "$1" ]; then
progress "Adding ogn user and installing as that"
if [ ! -e /home/ogn ]; then
sudo useradd -m -G `groups|tr ' ' ,` ogn || {
progress "unable to add ogn user?!"
exit
}
echo "ogn:ogn" | sudo chpasswd
progress "Updating package information"
sudo apt-get update
progress "Updating install packages"
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
else
progress "using existing ogn user"
fi
progress "Installing menu helper"
sudo apt-get -y install dialog
dialog --yesno "Do you wish to use online configuration" 0 0
online=$?
dialog --yesno "Do you wish to upgrade the operating system (highly recommended, but not available on all platforms)" 0 0
upgrade=$?
dialog --yesno "Do you wish to enable automatic operating system updates (debian only)?" 0 0
autoupgrade=$?
dialog --defaultno --yesno "Do you wish to prepare the filesystem for image creation? (Takes a LONG time, don't bother if you don't need it!)" 0 0
cleanup=$?
progress "relaunching script"
abs_path="$(readlink -f `dirname $0`)/$(basename $0)"
exec $sudo su -c "/bin/bash $abs_path $online $upgrade $cleanup $autoupgrade $@" root
exit 0
fi
## capture options
online=$1
upgrade=$2
cleanup=$3
autoupgrade=$4
if [ "$upgrade" != "1" ] ; then
if [ -e /usr/bin/rpi-update ] ; then
progress "Updating Operating System (rpi-update)"
rpi-update
updated=1
fi
if [ ! -z $(which do-release-upgrade) ] ; then
progress "Updating Operating System (do-release-upgrade)"
do-release-upgrade
updated=1
fi
fi
## dependencies
progress "Installing dependencies"
apt-get -y install libusb-1.0-0-dev libconfig-dev fftw3-dev libjpeg-dev libconfig9 procserv telnet ntp curl dialog openssl sudo rtl-sdr
cd /home/ogn
progress "Blocking unwanted SDR stuff"
# make sure the mod probe stuff is blocked properly on the pi
# necessary not only on RPi, and wont hurt anyway
touch /etc/modprobe.d/rtl-glidernet-blacklist.conf
echo "blacklist rtl2832" >> /etc/modprobe.d/rtl-glidernet-blacklist.conf
echo "blacklist r820t" >> /etc/modprobe.d/rtl-glidernet-blacklist.conf
echo "blacklist rtl2830" >> /etc/modprobe.d/rtl-glidernet-blacklist.conf
echo "blacklist dvb_usb_rtl28xxu" >> /etc/modprobe.d/rtl-glidernet-blacklist.conf
## davidm: I had to add (one of) these lines as well on my OrangePi running Jessie
echo "blacklist dvb_usb_rtl2832u" >> /etc/modprobe.d/rtl-glidernet-blacklist.conf
echo "blacklist dvb_usb_rtl2830u" >> /etc/modprobe.d/rtl-glidernet-blacklist.conf
#install libjpeg8 as gsm_scan depends on this
LIBJPG_OK=$(sudo ldconfig -p | grep libjpeg.so.8)
if [ "" == "$LIBJPG_OK" ] ; then
progress "installing older version of libjpeg for gsm_scan"
architecture=`dpkg --print-architecture`
curl "http://ftp.nl.debian.org/debian/pool/main/libj/libjpeg8/libjpeg8_8d1-2_"${architecture}".deb" -R -# -o "libjpeg8_8d1-2_"${architecture}".deb"
dpkg -i libjpeg8_8d1-2_${architecture}.deb
rm /home/ogn/libjpeg8_8d1-2_${architecture}.deb
fi;
#
progress "Adding system startup scripts"
curl "${url}/rtlsdr-ogn" -R -# -o /etc/init.d/rtlsdr-ogn
curl "${url}/rtlsdr-ogn.conf" -R -# -o /etc/rtlsdr-ogn.conf
curl "${url}/rtlsdr-ogn-app.conf" -R -# -o /home/ogn/rtlsdr-ogn.conf
chmod +x /etc/init.d/rtlsdr-ogn
progress "Installing updater and using it to install RTLSDR"
curl "${url}/update" -R -# -o /home/ogn/update
chmod +x /home/ogn/update
# if we don't have a configuration file then make a dummy one, we also need to make the rtlsdr-ogn
# symlink or it will get confused
if [ ! -e /home/ogn/rtlsdr-ogn ] ; then
mkdir /home/ogn/rtlsdr-ogn-bootstrap
(cd /home/ogn; ln -s rtlsdr-ogn-bootstrap rtlsdr-ogn)
fi;
if [ ! -e /home/ogn/rtlsdr-ogn.conf ] ; then
curl "${url}/rtlsdr-ogn-app.conf" -R -# -o /home/ogn/rtlsdr-ogn.conf
fi;
# this is until we actually have a file that we can install... we copy the correct one later on
/home/ogn/update -i
# and remove it if we made it - not necessary
if [ -e /home/ogn/rtlsdr-ogn-bootstrap ] ; then
rm -rf /home/ogn/rtlsdr-ogn-bootstrap
fi;
if [ "$autoupgrade" != "1" ]; then
progress "Installing unattended-upgrades helper"
apt-get -y install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
sed -i '/^Unattended-Upgrade::Origins-Pattern {/a "a=stable";' /etc/apt/apt.conf.d/50unattended-upgrades
fi;
progress "Adding startup scripts - this will produce warnings about LSB tabs"
curl "${url}/rtlsdr-ogn" -R -# -o /etc/init.d/rtlsdr-ogn
curl "${url}/rtlsdr-ogn.conf" -R -# -o /etc/rtlsdr-ogn.conf
chmod +x /etc/init.d/rtlsdr-ogn
chown ogn /home/ogn/rtlsdr-ogn.conf
if [ -e /etc/systemd ] ; then
curl "${url}/rtlsdr-ogn.service" -R -# -o /etc/systemd/system/rtlsdr-ogn.service
fi;
if [ "$online" != "1" ] ; then
curl "${url}/httpi" -R -# -o /usr/local/bin/httpi
curl "${url}/first-install" -R -# -o /etc/init.d/first-install
chmod +x /etc/init.d/first-install /usr/local/bin/httpi
##new systemctl calls
if [ -e /etc/systemd ] ; then
systemctl enable first-install
systemctl disable rtlsdr-ogn.service
else
update-rc.d first-install defaults
update-rc.d rtlsdr-ogn remove
fi
touch /etc/ssh/ssh_host_keyswrong
progress "Done. Please reboot your device. You will be able to configure it at http://ognconfig.onglide.com when it reboots"
progress "Also, you may wish to update your operating system"
if [ "$updated" != "1" ] ; then
error "You may need to upgrade your operating system as well"
fi
## clean up the file system
if [ "$cleanup" != "1" ]; then
progress "installing wifi user and settings"
echo ""
apt-get -y install wicd-curses
echo "/usr/bin/wicd-curses" >> /etc/shells
useradd -G netdev wifi
echo "wifi:wifi" | chpasswd
chsh -s /usr/bin/wicd-curses wifi
echo "PermitRootLogin no " >> /etc/ssh/sshd_config
progress "removing unwanted packages"
apt-get -y install localepurge deborphan
localepurge
for dopurge in 'libx11-.*' 'g[+][+].*' 'cpp-4.6' 'libcdparanoia' '.*gtk' '.*gstreamer' 'gcc-4.6$' 'ttf-.*' 'cmake.*' 'git.*' 'pistore.*' 'gdb.*' 'info.*' 'man.*' 'debian-reference.*' 'oracle-java8.*'
do
echo ">>>>>>>>> $dopurge >>>>>>>>>"
apt-get -y remove -y --auto-remove --purge "^$dopurge"
done
echo ">>>done"
# apt-get -y remove -y `deborphan`
echo "deborphan done"
apt-get -y remove dphys-swapfile
rm /var/swap
rm /home/pi/python_games
echo "autoremove start"
apt-get autoremove
echo "autoclean remove"
apt-get autoclean
echo "autoclean done"
apt-get clean
rm -rf /var/cache/apt
rm /home/ogn/rtlsdr-ogn/*jpg
if [ `grep -c tmpfs /etc/fstab` -eq 0 ]; then
progress "setting up tmpfs for /var and /tmp"
echo "tmpfs /tmp tmpfs defaults,size=30M 0 0" >> /etc/fstab
echo "tmpfs /var/log tmpfs defaults,size=30M 0 0" >> /etc/fstab
fi
rm -rf /var/log/*
rm -rf /var/cache/apt/* /var/cache/man /var/cache/fontconfig
rm /var/cache/debconf/*old /var/lib/dpkg/*old
rm -rf /var/lib/apt
rm -rf /boot.bak
rm -rf /home/pi/.bash_history /home/pi/bootstrap /home/pi/.aptitude
currentdate=`date "+%y%m%d%H%M"`
date -s 150101; echo "wifi:wifi" | chpasswd; echo "ogn:ogn" | chpasswd ; echo "pi:raspberry" | chpasswd;
print "passwords reset to default! pi/raspberry ogn/ogn wifi/wifi"
date -s $currentdate
fi
exit
fi;
##new systemctl calls
if [ -e /etc/systemd ] ; then
systemctl enable rtlsdr-ogn.service
systemctl disable first-install
else
update-rc.d rtlsdr-ogn defaults
update-rc.d first-install remove
fi
progress "You device is ready for configuration. Please edit the configuration file: /home/ogn/rtlsdr-ogn.conf"
progress "And then reboot"
if [ $updated != "1" ] ; then
error "You may need to upgrade your operating system as well"
fi;