forked from Telraam/Telraam-RPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
general-configuration-HOWTO.txt
390 lines (338 loc) · 11.6 KB
/
general-configuration-HOWTO.txt
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
# -----------------
# MAIN INSTALLATION
# -----------------
Target OS: Raspbian GNU/Linux 9 (stretch)
# ========
# PACKAGES
# ========
sudo apt-get update -y
sudo apt-get upgrade -y
(SKIP due to incompatibilities when compiling OpenCV: sudo apt-get dist-upgrade -y)
sudo apt-get purge wolfram-engine -y
sudo apt-get purge libreoffice* -y
sudo apt-get purge minecraft-pi -y
sudo apt-get remove chromium-browser -y
sudo apt-get remove epiphany-browser -y
sudo apt-get install midori -y
sudo apt-get install conky-all -y
sudo apt-get install exfat-fuse exfat-utils -y
sudo apt-get autoremove -y
sudo apt-get clean -y
*** Create.conkyrc
*** Manually add startup script Conky.desktop to ~/.config/autostart
rm -rf ~/MagPi
rm -rf ~/Music
rm -rf ~/Templates
rm -rf ~/Videos
# ====================
# INSTALL WEB SERVICES
# ====================
sudo apt-get install apache2 -y
sudo apt-get install php libapache2-mod-php -y
sudo apt-get install php-mysql mysql-server -y
# ============
# RASPI CONFIG
# ============
sudo raspi-config
*** Boot options -> B3 Splash Screen -> Disable
*** Interfacing options
*** Enable Camera
*** Enable SSH (accessible via raspberrypi.local)
(UNIX-style login, with username 'pi' and password 'pi')
*** Enable VNC
*** Disable Bluetooth
# ==============================
# DISABLE ETH0 & CHANGE HOSTNAME
# ==============================
sudo nano /etc/rc.local
*** sudo ifconfig eth0 down
sudo nano /etc/hostname
*** change raspberrypi: telraam
sudo nano /etc/hosts
*** change raspberrypi: telraam
# ====================
# COPY TO SHARED DRIVE
# ====================
mkdir ~/Telraam
mkdir ~/Scripts
*** Copy over all Python scripts
*** Copy over royalty-free TML background image to ~/Pictures
chmod +x ~/Telraam/Scripts/*
# =========================
# APPEND .PROFILE & .BASHRC
# =========================
export PATH=$PATH:~/Scripts
alias cls='clear'
alias dir='ls -lh'
alias adir='ls -alh'
alias wdir='ls -h'
alias wadir='ls -ah'
alias del='rm'
alias cd..='cd ..'
alias d='sudo du -h | sort -r -h | less'
alias el='elinks http://www.google.be/'
alias h='htop'
alias x='startx'
alias b='epiphany-browser > /dev/null 2> /dev/null'
alias c='sudo raspi-config'
alias u='sudo apt-get update; sudo apt-get upgrade; sudo apt-get autoremove; sudo apt-get clean'
alias ipc='hostname -I'
alias mac='python3 ~/Telraam/Scripts/telraam_show_mac_address.py'
alias ap='nano ~/Telraam/Scripts/telraam_ap_control_loop.py'
alias wpa='sudo nano /etc/wpa_supplicant/wpa_supplicant.conf'
alias clearbash='cat /dev/null > ~/.bash_history && history -c && exit'
alias tsysapstatus='sudo systemctl status telraam_ap_control_loop.service | cat'
alias tsysapstart='sudo systemctl start telraam_ap_control_loop.service'
alias tsysapstop='sudo systemctl stop telraam_ap_control_loop.service'
alias tsysaprestart='sudo systemctl restart telraam_ap_control_loop.service'
alias tsysapenable='sudo systemctl enable telraam_ap_control_loop.service'
alias tsysapdisable='sudo systemctl disable telraam_ap_control_loop.service'
alias tsyscamstatus='sudo systemctl status telraam_camera_stream.service | cat'
alias tsyscamstart='sudo systemctl start telraam_camera_stream.service'
alias tsyscamstop='sudo systemctl stop telraam_camera_stream.service'
alias tsyscamrestart='sudo systemctl restart telraam_camera_stream.service'
alias tsyscamenable='sudo systemctl enable telraam_camera_stream.service'
alias tsyscamdisable='sudo systemctl disable telraam_camera_stream.service'
alias tsysmonstatus='sudo systemctl status telraam_monitoring.service | cat'
alias tsysmonstart='sudo systemctl start telraam_monitoring.service'
alias tsysmonstop='sudo systemctl stop telraam_monitoring.service'
alias tsysmonrestart='sudo systemctl restart telraam_monitoring.service'
alias tsysmonenable='sudo systemctl enable telraam_monitoring.service'
alias tsysmondisable='sudo systemctl disable telraam_monitoring.service'
alias tsysmon='sudo python3 ~/Telraam/Scripts/telraam_monitoring.py --idandtrack --verbose --display; sudo rm -rf test'
alias tsys='cls; tsyscamstatus; tsysapstatus; tsysmonstatus'
alias m='sudo mysql'
sudo reboot
# =====================
# INSTALL SAMBA SERVICE
# =====================
sudo apt-get install samba samba-common-bin -y
mkdir ~/Shared
sudo nano /etc/samba/smb.conf
*** Append the following text block to the end of the file
-------
[Shared]
comment = Pi shared folder
path = /home/pi/Shared
writeable = Yes
browseable = yes
# guest ok = yes
create mask = 0644
directory mask = 0755
force user = pi
netbios name = telraam
name resolve order = bcast lmhosts host wins
-------
sudo smbpasswd -a pi
*** pi
*** pi
sudo /etc/init.d/samba restart
(-> accessible via Windows explorer: \\telraam.local)
# ==============
# INSTALL OPENCV
# ==============
OPENCV_VERSION='3.4.3'
sudo apt-get install build-essential cmake pkg-config -y
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt-get install libxvidcore-dev libx264-dev -y
sudo apt-get install libgtk2.0-dev libgtk-3-dev -y
sudo apt-get install libatlas-base-dev gfortran -y
sudo apt-get install python2.7-dev python3-dev -y
sudo apt-get install python-numpy python-scipy -y
sudo rm -rf ~/.cache/pip
wget -O opencv.zip https://github.com/Itseez/opencv/archive/${OPENCV_VERSION}.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/${OPENCV_VERSION}.zip
unzip opencv.zip; unzip opencv_contrib.zip
rm opencv.zip; rm opencv_contrib.zip
cd ~/opencv-${OPENCV_VERSION}/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-${OPENCV_VERSION}/modules -D BUILD_EXAMPLES=ON ..
sudo nano /etc/dphys-swapfile
*** CONF_SWAPSIZE=1024
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
make -j4
sudo make install
sudo ldconfig
cd /usr/local/lib/python3.5/dist-packages/
sudo mv cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so
cd
rm -rf opencv-${OPENCV_VERSION} opencv_contrib-${OPENCV_VERSION}
python
>>> import cv2
>>> cv2.__version__
?->'3.4.3'
exit()
sudo nano /etc/dphys-swapfile
*** CONF_SWAPSIZE=100
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
u
# ===================
# SETUP CAMERA STREAM
# ===================
(based on https://picamera.readthedocs.io/en/latest/recipes2.html#web-streaming)
sudo chmod +x /home/pi/Telraam/Scripts/telraam_camera_stream.py
sudo cp telraam_camera_stream.service /lib/systemd/system/
sudo chmod 644 /lib/systemd/system/telraam_camera_stream.service
sudo systemctl daemon-reload
sudo systemctl enable telraam_camera_stream.service
# =========================================
# URL FOR LOCALLY TESTING THE CAMERA STREAM
# =========================================
http://127.0.0.1:8000/stream.mjpg
# ====================
# SETUP MYSQL DATABASE
# ====================
sudo apt-get install python-mysqldb -y
sudo apt-get install python3-mysqldb -y
sudo mysql
CREATE DATABASE telraam;
USE telraam;
CREATE TABLE connection(wifi_ssid VARCHAR(32),wifi_pwd VARCHAR(64));
GRANT ALL PRIVILEGES ON * . * TO 'pi'@'localhost' IDENTIFIED BY 'pi';
exit
# =======================
# SETUP MONITORING SCRIPT
# =======================
pip3 install pandas
sudo pip3 install pandas
sudo chmod +x /home/pi/Telraam/Scripts/telraam_monitoring.py
sudo cp telraam_monitoring.service /lib/systemd/system/
sudo chmod 644 /lib/systemd/system/telraam_monitoring.service
sudo systemctl daemon-reload
sudo systemctl enable telraam_monitoring.service
# ==================
# SETUP ACCESS POINT
# ==================
sudo apt-get install dnsmasq hostapd -y
sudo systemctl stop dnsmasq
sudo systemctl stop hostapd
sudo nano /etc/dhcpcd.conf
*** append with the following
# TELRAAM
interface wlan0
static ip_address=192.168.254.1/24
nohook wpa_supplicant
sudo service dhcpcd restart
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
*** append with the following
interface=wlan0
dhcp-range=192.168.254.2,192.168.254.254,255.255.255.0,24h
sudo nano /etc/hostapd/hostapd.conf
*** append with the following
interface=wlan0
driver=nl80211
ssid=TELRAAM
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=TelraamTelraam
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
sudo nano /etc/default/hostapd
*** replace #DAEMON_CONF with DAEMON_CONF="/etc/hostapd/hostapd.conf"
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl start dnsmasq
sudo nano /etc/sysctl.conf
*** uncomment net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo nano /etc/rc.local
*** add before "exit 0"
#sudo ifconfig eth0 down
sudo iptables-restore < /etc/iptables.ipv4.nat
sudo reboot
sudo chmod +x /home/pi/Telraam/Scripts/telraam_ap_control_loop.py
sudo nano /lib/systemd/system/telraam_ap_control_loop.service
[Unit]
Description=Telraam manage-access point & connections to wifi
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/Telraam/Scripts/telraam_ap_control_loop.py
[Install]
WantedBy=multi-user.target
sudo chmod 644 /lib/systemd/system/telraam_ap_control_loop.service
sudo systemctl daemon-reload
sudo systemctl enable telraam_ap_control_loop.service
# ============
# DISABLE IPV6
# ============
sudo nano /boot/cmdline.txt
*** Add to the end of the single line
*** ipv6.disable=1
sudo nano /etc/sysctl.conf
*** net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -p
# ===================
# SETUP LOGIN WEBPAGE
# ===================
sudo rm -rf /var/www/html/index.html
sudo cp index.php /var/www/html/
sudo chmod 755 /var/www/html/index.php
# ======
# FINISH
# ======
Welcome page (after connecting to the AP) is found at 192.168.254.1
# =========================
# START HEADLESS BY DEFAULT
# =========================
sudo raspi-config
*** 3 Boot Options
*** B1 Desktop / CLI
*** B1 Console
# ===========
# DISABLE VNC
# ===========
sudo raspi-config
*** Interfacing options
*** Disable VNC
# ==========================
# INSTALL UPDATE AT MIDNIGHT
# ==========================
pip install wget
pip3 install wget
sudo pip install wget
sudo pip3 install wget
sudo nano /etc/cron.d/updatecron
0 0 * * * root /usr/bin/python3 /home/pi/Telraam/Scripts/telraam_auto_updater_cron.py
# ===============
# CLEAR HISTORIES
# ===============
sudo mysql
use telraam;
truncate connection;
exit
sudo rm -f /root/.mysql_history
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
*** Delete network information
cat /dev/null > ~/.bash_history && history -c && sudo halt
# ============
# SHRINK IMAGE
# ============
*** Externally create full image of SD card
*** Copy image to external USB drive (formatted as exFAT)
*** Create empty (second) external USB drive (formatted as exFAT)
*** Mount both drives on the RPi
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin
sudo pishrink.sh /media/pi/DRIVE/largeimage.img /media/pi/DRIVE/smallimage.img
# ==============================
# SSH ACCESS TO THE PI VIA PUTTY
# ==============================
Hostname: telraam.local
Password: pi
-> Connection -> Data -> Terminal-type string: linux
Window -> Translation -> Remote character set: UTF-8