-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall.sh
306 lines (258 loc) · 9.69 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
#!/bin/bash
[ -z $BASH ] && { exec bash "$0" "$@" || exit; }
# file: install.sh
# This script will install required software for HoneyPi.
# It is recommended to run it in your home directory.
# Ensure the script is run as root
if [ "$(id -u)" != 0 ]; then
echo 'Sorry, you need to run this script with sudo'
exit 1
fi
# Check for stable or pre-release argument
if [ -z "$1" ]; then
echo "Info: No argument for stable/pre-release. Default is stable."
stable=1
else
stable=$1
fi
# Function to log messages
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | tee -a /var/log/honeypi_install.log
}
# Function to update config files
update_config_file() {
local file=$1
local pattern=$2
local entry=$3
log "Updating $file: Adding $entry"
if grep -q "$pattern" "$file"; then
log "Seems $pattern parameter already set in $file, skipping."
else
echo "$entry" >> "$file"
fi
}
# Function to ensure a package is installed
ensure_package_installed() {
if ! dpkg -s "$1" >/dev/null 2>&1; then
log "Installing package $1"
apt-get install -y "$1"
else
log "Package $1 is already installed"
fi
}
# Ensure required packages are installed
ensure_package_installed curl
ensure_package_installed git
ensure_package_installed python3
ensure_package_installed python3-pip
# Replace symbolic link to use bash as default shell interpreter
log 'Use bash as default shell interpreter'
if [ ! -L /bin/sh ] || [ "$(readlink /bin/sh)" != "bash" ]; then
ln -sf bash /bin/sh
fi
# Set locale to reduce debug messages
log 'Set locale to en_GB.UTF-8'
export LANGUAGE=en_GB.UTF-8
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
locale-gen en_GB.UTF-8
dpkg-reconfigure -f noninteractive locales
# Target directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Default GPIO for Ds18b20, per default raspbian would use GPIO 4
w1gpio=11
# System update
log 'System update'
apt-get update && apt-get upgrade -y
# Determine paths for config.txt and cmdline.txt
CONFIG_PATH="/boot/config.txt"
CMDLINE_PATH="/boot/cmdline.txt"
if grep -q 'DO NOT EDIT THIS FILE' /boot/config.txt; then
CONFIG_PATH="/boot/firmware/config.txt"
fi
if grep -q 'DO NOT EDIT THIS FILE' /boot/cmdline.txt; then
CMDLINE_PATH="/boot/firmware/cmdline.txt"
fi
# Enable I2C on Raspberry Pi
log 'Enable I2C'
if ! grep -q 'i2c-bcm2708' /etc/modules; then
echo 'i2c-bcm2708' >> /etc/modules
fi
if ! grep -q '^i2c-dev' /etc/modules; then
echo 'i2c-dev' >> /etc/modules
fi
update_config_file "$CONFIG_PATH" 'dtparam=i2c1=on' 'dtparam=i2c1=on'
update_config_file "$CONFIG_PATH" '^dtparam=i2c_arm=on' 'dtparam=i2c_arm=on'
# Enable 1-Wire on Raspberry Pi
log 'Enable 1-Wire'
if ! grep -q '^w1_gpio' /etc/modules; then
echo 'w1_gpio' >> /etc/modules
fi
if ! grep -q '^w1_therm' /etc/modules; then
echo 'w1_therm' >> /etc/modules
fi
update_config_file "$CONFIG_PATH" '^dtoverlay=w1-gpio' "dtoverlay=w1-gpio,gpiopin=$w1gpio"
# Enable miniuart-bt on Raspberry Pi and set core frequency, for stable miniUART and bluetooth
log "Install required miniuart-bt modules for rak811 & WittyPi..."
update_config_file "$CONFIG_PATH" 'dtoverlay=pi3-miniuart-bt' 'dtoverlay=pi3-miniuart-bt'
update_config_file "$CONFIG_PATH" 'core_freq=250' 'core_freq=250'
# Enable HDMI for a default "safe" mode to work on all screens
log 'Enable HDMI safe mode'
if grep -q '#hdmi_safe=1' "$CONFIG_PATH"; then
sed -i 's/#hdmi_safe=1/hdmi_safe=1/' "$CONFIG_PATH"
log 'Updated hdmi_safe=1 from commented out to enabled in the config file.'
elif grep -q 'hdmi_safe=1' "$CONFIG_PATH"; then
log 'HDMI safe mode already enabled, skipping.'
else
echo 'hdmi_safe=1' >> "$CONFIG_PATH"
log 'Added hdmi_safe=1 to the config file.'
fi
log 'Enable Wifi'
rfkill unblock all
# Enable Wifi-Stick on Raspberry Pi 1 & 2
log 'Enable Wifi-Stick on Raspberry Pi 1 & 2'
if ! grep -q 'net.ifnames=0' "$CMDLINE_PATH"; then
sed -i '1s/$/ net.ifnames=0/' "$CMDLINE_PATH"
log 'Added net.ifnames=0 to the cmdline file.'
else
log 'net.ifnames=0 already set, skipping.'
fi
# Code to run only on Raspberry Pi Zero
log 'Configuring Raspberry Pi Zero specific settings'
if grep -q 'Zero' /proc/device-tree/model; then
serial=0
if [ $serial -eq 1 ]; then
log 'Configuring Serial Login for Raspberry Zero'
update_config_file "$CONFIG_PATH" 'dtoverlay=dwc2' 'dtoverlay=dwc2'
if ! grep -q "modules-load=dwc2,g_serial" "$CMDLINE_PATH"; then
sed -i '1s/$/ modules-load=dwc2,g_serial/' "$CMDLINE_PATH"
fi
echo 'g_serial' >> /etc/modules
systemctl enable [email protected]
else
log 'Configuring usb0 SSH Login for Raspberry Zero'
update_config_file "$CONFIG_PATH" 'dtoverlay=dwc2' 'dtoverlay=dwc2'
if ! grep -q "modules-load=dwc2,g_ether" "$CMDLINE_PATH"; then
sed -i '1s/$/ modules-load=dwc2,g_ether/' "$CMDLINE_PATH"
fi
fi
else
log 'Info: This is not a Raspberry Pi Zero, skip this step.'
fi
# Change timezone
log 'Change Timezone to Berlin'
ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
# Change hostname
log 'Change Hostname to HoneyPi'
sed -i 's/127.0.1.1.*raspberry.*/127.0.1.1 HoneyPi/' /etc/hosts
echo 'HoneyPi' > /etc/hostname
# Install NTP for time synchronization
log 'Install NTP for time synchronization with wittyPi'
apt-get -y install --no-install-recommends ntp
dpkg-reconfigure -f noninteractive ntp
log 'Apply fix for ntpd config'
mkdir -p /var/log/ntpsec/
cp overlays/ntp.conf /etc/ntp.conf
# Install Python and system packages for measurement scripts
log 'Install Python and system packages for measurement scripts'
apt-get -y install --no-install-recommends python3-numpy python3-rpi.gpio python3-smbus libatlas3-base python3-setuptools python3-pip libatlas-base-dev libgpiod2
python3 -m pip config set global.break-system-packages true
# Check if EXTERNALLY-MANAGED file exists before attempting to move it
if [ -f /usr/lib/python3.11/EXTERNALLY-MANAGED ]; then
mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old
log 'Moved EXTERNALLY-MANAGED to EXTERNALLY-MANAGED.old'
else
log 'EXTERNALLY-MANAGED file does not exist, skipping move.'
fi
export PIP_ROOT_USER_ACTION=ignore
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt --upgrade
python3 -m pip install --upgrade setuptools wheel
pip3 install Adafruit_DHT Adafruit_Python_DHT
# Uninstall old numpy and install required version
log 'Install timezonefinder and numpy'
pip3 uninstall --yes numpy
apt-get -y remove python3-numpy
apt-get -y install --no-install-recommends libopenblas-dev
pip3 install timezonefinder==6.1.8 numpy
# Install additional software for version 1.3.7
log 'Install additional software for version 1.3.7'
apt-get -y install --no-install-recommends libopenjp2-7 libtiff5 python3-psutil
# Install and configure lighttpd for web interface
log 'Install and configure lighttpd for web interface'
apt-get -y install --no-install-recommends lighttpd php-cgi
lighttpd-enable-mod fastcgi fastcgi-php
cp overlays/lighttpd.conf /etc/lighttpd/lighttpd.conf
chmod -R 644 /etc/lighttpd/lighttpd.conf
service lighttpd force-reload
# Create www-data user and group
log 'Create www-data user and add pi to group'
groupadd -f www-data
usermod -G www-data -a pi
# Update sudoers for www-data
log 'Update sudoers for www-data'
if ! grep -q 'www-data ALL=NOPASSWD: ALL' /etc/sudoers; then
echo 'www-data ALL=NOPASSWD: ALL' | EDITOR='tee -a' visudo
fi
# Install software for surfstick
log 'Install software for surfstick'
apt-get -y install --no-install-recommends wvdial usb-modeswitch usb-modeswitch-data
cp overlays/wvdial.conf /etc/wvdial.conf
cp overlays/wvdial.conf.tmpl /etc/wvdial.conf.tmpl
chmod 755 /etc/wvdial.conf
cp overlays/wvdial /etc/ppp/peers/wvdial
# Place motd welcome screen
log 'Place motd welcome screen'
cp overlays/motd /etc/motd
# Setup wifi configuration
log 'Setup Wifi Configuration'
if ! grep -q 'network={' /etc/wpa_supplicant/wpa_supplicant.conf; then
cp overlays/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
echo 'Remember to configure your WiFi credentials in /etc/wpa_supplicant/wpa_supplicant.conf'
chmod -R 600 /etc/wpa_supplicant/wpa_supplicant.conf
chmod +x /etc/wpa_supplicant/wpa_supplicant.conf
fi
cp overlays/dhcpcd.conf /etc/dhcpcd.conf
# Enable rc.local
log 'Enable rc.local'
chmod +x /etc/rc.local
systemctl enable rc-local.service
log "Uncomment autostart of honeypi in rc.local"
if grep -q 'sleep 2;python3' /etc/rc.local; then
sed -i '/(sleep 2;python3/c\#' /etc/rc.local # disable autostart in rc.local
fi
# Enable honeypi.service
log 'Enable honeypi.service'
cp overlays/honeypi.service /lib/systemd/system/honeypi.service
chmod 644 /lib/systemd/system/honeypi.service
systemctl daemon-reload
systemctl enable honeypi.service
# Set up Raspberry Pi as Access Point
log 'Set up Raspberry Pi as Access Point'
apt-get -y install --no-install-recommends dnsmasq hostapd
systemctl disable dnsmasq
systemctl disable hostapd || (systemctl unmask hostapd && systemctl disable hostapd)
systemctl stop dnsmasq
systemctl stop hostapd
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
cp overlays/dnsmasq.conf /etc/dnsmasq.conf
cp overlays/hostapd.conf.tmpl /etc/hostapd/hostapd.conf.tmpl
cp overlays/hostapd /etc/default/hostapd
# Set folder permissions
log 'Set folder permissions for /home/pi'
chown -R pi:pi /home/pi
chmod -R 755 /home/pi
# Wait for internet connection
log "Waiting for internet connection..."
while ! timeout 0.2 ping -c 1 -n api.github.com &> /dev/null; do
printf "."
done
# Run HoneyPi Updater
log 'Run HoneyPi Updater'
if [ $stable -eq 0 ]; then
sh update.sh 0
else
sh update.sh
fi
log 'All done. Please reboot your Pi :-)'