forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch_file
439 lines (346 loc) · 17.7 KB
/
patch_file
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#!/bin/bash
{
#////////////////////////////////////
# DietPi Patch File Script
#
#////////////////////////////////////
# Created by Daniel Knight / [email protected] / dietpi.com
#
#////////////////////////////////////
#
# Info:
# - Online patching for hosts filesystem.
# - Runs from dietpi-update
#
# Usage:
# - /DietPi/dietpi/patch_file $SUBVERSION_CURRENT $SUBVERSION_SERVER
#////////////////////////////////////
#Grab input
SUBVERSION_CURRENT=$1
SUBVERSION_SERVER=$2
#Import DietPi-Globals ---------------------------------------------------------------
/DietPi/dietpi/dietpi-obtain_hw_model # Always update
. /DietPi/dietpi/func/dietpi-globals
export G_PROGRAM_NAME='DietPi-Patchfile'
G_INIT
#Import DietPi-Globals ---------------------------------------------------------------
#/////////////////////////////////////////////////////////////////////////////////////
#Globals
#/////////////////////////////////////////////////////////////////////////////////////
# FP_EMR='/DietPi/dietpi/.patch_emr'
# EMR_INDEX=0
# Obtain_EMR_Index(){
# if [ ! -f "$FP_EMR" ]; then
# echo 0 > "$FP_EMR"
# else
# EMR_INDEX=$(cat "$FP_EMR")
# fi
# }
# Update_EMR_Index(){
# ((EMR_INDEX++))
# echo $EMR_INDEX > "$FP_EMR"
# }
#/////////////////////////////////////////////////////////////////////////////////////
#Emergency Patch System:
# This runs before all standard incremental patches. Useful for when shi* hits the ...
# Obtain_EMR_Index
# if (( $EMR_INDEX == 0 )); then
# echo 0
# fi
#/////////////////////////////////////////////////////////////////////////////////////
#Incremental patch system:
Incremental_Patch_System(){
if (( $SUBVERSION_CURRENT == -1 )); then
#-------------------------------------------------------------------------------
#Asus TB G_HW_MODEL change
if [ -f /etc/.dietpi_hw_model_identifier ] &&
(( $(sed -n 1p /etc/.dietpi_hw_model_identifier) == 100 )); then
export G_HW_MODEL=52
echo $G_HW_MODEL > /etc/.dietpi_hw_model_identifier
/DietPi/dietpi/dietpi-obtain_hw_model
fi
#-------------------------------------------------------------------------------
#bash.bashrc removal of any outstanding dietpi entries (moved to globals). Just incase I missed any manually during PREP...
sed -i '/#DietPi_Entries/Q' /etc/bash.bashrc
sed -i '/#Apply system locale/Q' /etc/bash.bashrc
sed -i '/#DietPi Additions/Q' /etc/bash.bashrc
#-------------------------------------------------------------------------------
#Fix doubled and renamed config files:
#https://github.com/Fourdee/DietPi/commit/68148cec6b49afc787deca638456e1c4689e1cab#diff-8370b86e635383d521462994afe04a2d
[ -f /etc/apt/apt.conf.d/99force-ipv ] && rm /etc/apt/apt.conf.d/99force-ipv
[ -f /etc/sysctl.d/97-dietpi.conf ] && mv /etc/sysctl.d/97-dietpi.conf /etc/sysctl.d/99-dietpi.conf
#-------------------------------------------------------------------------------
#Core_ENV update: https://github.com/Fourdee/DietPi/pull/1419
# IPv6 disable x86_64
# consoleblank disable x86_64
/DietPi/dietpi/func/dietpi-set_core_environment
#-------------------------------------------------------------------------------
#Remove -dev keyring
G_AGP debian-keyring
#-------------------------------------------------------------------------------
elif (( $SUBVERSION_CURRENT == 0 )); then
#-------------------------------------------------------------------------------
#Reinstalls:
# Kodi: https://github.com/Fourdee/DietPi/issues/1428
# Fail2Ban: https://github.com/Fourdee/DietPi/issues/1431
# Tonido: https://github.com/Fourdee/DietPi/issues/1432
if [ -f /DietPi/dietpi/.installed ]; then
/DietPi/dietpi/dietpi-software reinstall 31 73 134
fi
#-------------------------------------------------------------------------------
elif (( $SUBVERSION_CURRENT == 1 )); then
#-------------------------------------------------------------------------------
#Regen rootfs mount (removes nofail): https://github.com/Fourdee/DietPi/pull/1480
sed -i '/[[:space:]]\/[[:space:]]/d' /etc/fstab
sed -i '/[[:space:]]\/boot[[:space:]]/d' /etc/fstab
/DietPi/dietpi/dietpi-drive_manager 2
#-------------------------------------------------------------------------------
#locale rework/reset: https://github.com/Fourdee/DietPi/issues/1430#issuecomment-364763302
rm /etc/profile.d/99-dietpi-force-locale.sh &> /dev/null
mv /etc/environment /mnt/dietpi_userdata/environment.bak &> /dev/null
echo '' > /etc/environment
/DietPi/dietpi/func/dietpi-set_software locale en_GB.UTF-8
G_WHIP_MSG "Notice (locale):\n\nTo resolve broken Locales, they have been reset to en_GB.UTF-8.\n\nIf you had a different locale configured on this system, please use dietpi-config at a later date to re-configure.\n\nIn relation to that, DietPi does not use "/etc/environment" anymore, thus it is cleaned. In case you manually edited it, a backup was created: /mnt/dietpi_userdata/environment.bak"
#------------------------------------------------------------------------------
#Removed control from DietPi-Services: https://github.com/Fourdee/DietPi/issues/1501
systemctl enable dnsmasq &> /dev/null
systemctl enable openvpn &> /dev/null
systemctl start dnsmasq &> /dev/null
systemctl start openvpn &> /dev/null
#-------------------------------------------------------------------------------
#CertBot fixes: https://github.com/Fourdee/DietPi/issues/734#issuecomment-361774084
if [ -f /etc/letsencrypt/live/*/cert.pem ]; then
if (( $G_DISTRO > 3 )); then
if grep -q '^aSOFTWARE_INSTALL_STATE\[83\]=2' /DietPi/dietpi/.installed; then
certbot renew --force-renewal -a webroot -w /var/www/ -i apache
elif grep -q '^aSOFTWARE_INSTALL_STATE\[85\]=2' /DietPi/dietpi/.installed; then
certbot renew --force-renewal -a webroot -w /var/www/ -i nginx
elif grep -q '^aSOFTWARE_INSTALL_STATE\[158\]=2' /DietPi/dietpi/.installed; then
certbot renew --force-renewal --preferred-challenges http
fi
else
[ -f /etc/cron.monthly/dietpi-letsencrypt ] && rm /etc/cron.monthly/dietpi-letsencrypt
cat << _EOF_ > /etc/cron.weekly/dietpi-letsencrypt
#!/bin/bash
{
#////////////////////////////////////
# DietPi-LetsEncrypt Autorenew script
#
#////////////////////////////////////
#
# Info:
# - Location /etc/cron.weekly/dietpi-letsencrypt
#
#////////////////////////////////////
#----------------------------------------------------------------
# Main Loop
#----------------------------------------------------------------
/etc/certbot_scripts/certbot-auto -q renew &>> /var/log/dietpi-letsencrypt.log &&
[ -f /home/minio-user/.minio/dietpi-cert-renewl.sh ] && /home/minio-user/.minio/dietpi-cert-renewl.sh
#----------------------------------------------------------------
exit
#----------------------------------------------------------------
}
_EOF_
chmod +x /etc/cron.weekly/dietpi-letsencrypt
fi
fi
#-------------------------------------------------------------------------------
#http://dietpi.com/phpbb/viewtopic.php?f=11&t=2772&p=10646#p10646
rm /etc/apt/sources.list.d/openmediavault.list &> /dev/null
#-------------------------------------------------------------------------------
#DietPi-Software removals: https://github.com/Fourdee/DietPi/issues/1491
if [ -f /DietPi/dietpi/.installed ]; then
sed -i '/^aSOFTWARE_INSTALL_STATE\[100\]=/c\aSOFTWARE_INSTALL_STATE\[100\]=0' /DietPi/dietpi/.installed #grashopper (now pijuice)
sed -i '/^aSOFTWARE_INSTALL_STATE\[106\]=/c\aSOFTWARE_INSTALL_STATE\[106\]=0' /DietPi/dietpi/.installed #raspcontrol (now ntp)
if (( $(grep -ci -m1 '^aSOFTWARE_INSTALL_STATE\[170\]=2' /DietPi/dietpi/.installed) )); then
sed -i '/^aSOFTWARE_INSTALL_STATE\[106\]=/c\aSOFTWARE_INSTALL_STATE\[106\]=2' /DietPi/dietpi/.installed #ntp (replaces raspcontrol)
sed -i '/^aSOFTWARE_INSTALL_STATE\[170\]=/c\aSOFTWARE_INSTALL_STATE\[170\]=0' /DietPi/dietpi/.installed #ntp (now 106)
fi
fi
#-------------------------------------------------------------------------------
#Nodered lacks homedir, create it: https://github.com/Fourdee/DietPi/issues/1446#issuecomment-366370800
if (( $(grep -ci -m1 '^nodered:' /etc/passwd) )) &&
[ ! -d /home/nodered ]; then
mkdir -p /home/nodered
chown -R nodered:nodered /home/nodered
fi
#-------------------------------------------------------------------------------
#Reinstalls:
# NetData 1.9
# Allo GUI update
if [ -f /DietPi/dietpi/.installed ]; then
/DietPi/dietpi/dietpi-software reinstall 65 160
fi
#-------------------------------------------------------------------------------
elif (( $SUBVERSION_CURRENT == 2 )); then
#-------------------------------------------------------------------------------
#Switch from rc.local to own postboot script: https://github.com/Fourdee/DietPi/issues/1376
G_WHIP_MSG "DietPi will not use /etc/rc.local for its own scripts anymore.\n\nHowever, in case you've manually added something, we safe a backup to /etc/rc.local.bak, from where you can copy & paste back to the cleaned /etc/rc.local.\n\nIt will work as before."
/DietPi/dietpi/func/dietpi-set_core_environment
if grep -q '^aSOFTWARE_INSTALL_STATE\[168\]=2' /DietPi/dietpi/.installed; then
[ -d /var/lib/dietpi/postboot.d ] || mkdir /var/lib/dietpi/postboot.d
cat << _EOF_ > /var/lib/dietpi/postboot.d/moode
#!/bin/bash
#moOde additions
SQLDB=/var/local/www/db/moode-sqlite3.db
# set cpu govenor
RESULT=\$(sqlite3 \$SQLDB "select value from cfg_system where param='cpugov'")
echo "\$RESULT" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
/usr/bin/udisks-glue > /dev/null 2>&1
/var/www/command/worker.php > /dev/null 2>&1
_EOF_
fi
#-------------------------------------------------------------------------------
G_DIETPI-NOTIFY 2 "Reducing getty count and resource usage:"
systemctl mask getty-static
#-------------------------------------------------------------------------------
# - Meveric, update repo to use our EU mirror: https://github.com/Fourdee/DietPi/issues/1519#issuecomment-368234302
sed -i 's@https://oph.mdrjr.net/meveric@http://fuzon.co.uk/meveric@' /etc/apt/sources.list.d/meveric* &> /dev/null
#-------------------------------------------------------------------------------
#Remove any existing apt recommends settings, before applying ours: https://github.com/Fourdee/DietPi/issues/1482#issuecomment-368031044
rm /etc/apt/apt.conf.d/*recommends* &> /dev/null
export G_ERROR_HANDLER_COMMAND='/etc/apt/apt.conf.d/99-dietpi-norecommends'
cat << _EOF_ > $G_ERROR_HANDLER_COMMAND
APT::Install-Recommends "false";
APT::Install-Suggests "false";
#APT::AutoRemove::RecommendsImportant "false";
#APT::AutoRemove::SuggestsImportant "false";
_EOF_
export G_ERROR_HANDLER_EXITCODE=$?
G_ERROR_HANDLER
#-------------------------------------------------------------------------------
#Reinstalls:
# Shairport-sync 3.1.7
# RPi Cam
# Aria2 for .conf addition: https://github.com/Fourdee/DietPi/issues/1575#issuecomment-370248708
# Sonarr/Radarr: https://github.com/Fourdee/DietPi/issues/1566#issuecomment-369334473
if [ -f /DietPi/dietpi/.installed ]; then
# - RPi cam pre-patch
mv /var/www/dietpicam /var/www/rpicam &> /dev/null
mv "$G_FP_DIETPI_USERDATA"/dietpicam "$G_FP_DIETPI_USERDATA"/rpicam &> /dev/null
rm /var/www/rpicam/media &> /dev/null
/DietPi/dietpi/dietpi-software reinstall 37 59 132 144 145
fi
#-------------------------------------------------------------------------------
#Add certificate combining for Lighttpd to CertBot auto renewal: https://github.com/Fourdee/DietPi/pull/1553
if [ -f /DietPi/dietpi/.dietpi-letsencrypt ]; then
# - Switch Minio to new certbot.service hook:
if (( $G_DISTRO > 3 )) && grep -q '^aSOFTWARE_INSTALL_STATE\[158\]=2' /DietPi/dietpi/.installed; then
[ -f /etc/systemd/system/certbot.service] && rm /etc/systemd/system/certbot.service
dietpi-letsencrypt 1
fi
grep -q '^aSOFTWARE_INSTALL_STATE\[84\]=2' /DietPi/dietpi/.installed && dietpi-letsencrypt 1
fi
#-------------------------------------------------------------------------------
#Sparky SBC kernel patches: Pro-Ject-S2 dac DSD native support on sparky, also other few dac ids.
if (( $G_HW_MODEL == 70 )); then
G_RUN_CMD wget https://raw.githubusercontent.com/sparky-sbc/sparky-test/master/pro-ject-s2/snd-usb-audio.ko -O /lib/modules/$(uname -r)/kernel/sound/usb/snd-usb-audio.ko
G_RUN_CMD wget https://raw.githubusercontent.com/sparky-sbc/sparky-test/master/pro-ject-s2/snd-usbmidi-lib.ko -O /lib/modules/$(uname -r)/kernel/sound/usb/snd-usbmidi-lib.ko
fi
#-------------------------------------------------------------------------------
#GNU key management required for some APT installs via additional repos: https://github.com/Fourdee/DietPi/issues/1388
G_AGI dirmngr
#-------------------------------------------------------------------------------
# Odroids FFmpeg decendency fix: https://github.com/Fourdee/DietPi/issues/1556#issuecomment-369463910
if (( $G_HW_MODEL > 9 && $G_HW_MODEL < 15 )); then
rm /etc/apt/preferences.d/meveric*
cat << _EOF_ > /etc/apt/preferences.d/backports
Package: *
Pin: release a=jessie-backports
Pin: origin "fuzon.co.uk"
Pin-Priority: 99
Package: *
Pin: release a=jessie-backports
Pin: origin "oph.mdrjr.net"
Pin-Priority: 99
_EOF_
fi
#-------------------------------------------------------------------------------
# Subsonic 5 replaced with Airsonic: https://github.com/Fourdee/DietPi/issues/1585
sed -i '/^aSOFTWARE_INSTALL_STATE\[33\]=/c\aSOFTWARE_INSTALL_STATE\[33\]=0' /DietPi/dietpi/.installed &> /dev/null
#-------------------------------------------------------------------------------
elif (( $SUBVERSION_CURRENT == 3 )); then
#-------------------------------------------------------------------------------
#Never run this in future patches!!! : https://github.com/Fourdee/DietPi/issues/1592
#/DietPi/dietpi/func/dietpi-set_core_environment
#-------------------------------------------------------------------------------
#Re-Apply swap to set /tmp tmpfs size: https://github.com/Fourdee/DietPi/issues/1027#issuecomment-369435049
# + Force auto swapfile size https://github.com/Fourdee/DietPi/issues/1593#issuecomment-371516418
/DietPi/dietpi/func/dietpi-set_dphys-swapfile 1
#-------------------------------------------------------------------------------
#Service updates: http://dietpi.com/phpbb/viewtopic.php?f=11&t=1148&p=11322#p11322
$(which mkdir) -p /var/tmp/dietpi/logs
cat << _EOF_ > /etc/systemd/system/dietpi-ramdisk.service
[Unit]
Description=DietPi-RAMdisk
After=local-fs.target boot.mount
Before=rsyslog.service syslog.service
[Service]
Type=forking
RemainAfterExit=yes
ExecStartPre=$(which mkdir) -p /var/tmp/dietpi/logs
ExecStart=/bin/bash -c '/boot/dietpi/dietpi-ramdisk 0 &>> /var/tmp/dietpi/logs/dietpi-ramdisk.log'
ExecStop=/bin/bash -c '/DietPi/dietpi/dietpi-ramdisk 1 &>> /var/tmp/dietpi/logs/dietpi-ramdisk.log'
[Install]
WantedBy=local-fs.target
_EOF_
systemctl daemon-reload
systemctl enable dietpi-ramdisk.service
cat << _EOF_ > /etc/systemd/system/dietpi-ramlog.service
[Unit]
Description=DietPi-RAMlog
After=local-fs.target boot.mount
Before=rsyslog.service syslog.service
[Service]
Type=forking
RemainAfterExit=yes
ExecStartPre=$(which mkdir) -p /var/tmp/dietpi/logs
ExecStart=/bin/bash -c '/boot/dietpi/dietpi-ramlog 0 &>> /var/tmp/dietpi/logs/dietpi-ramlog.log'
ExecStop=/bin/bash -c '/DietPi/dietpi/dietpi-ramlog 1 &>> /var/tmp/dietpi/logs/dietpi-ramlog.log'
[Install]
WantedBy=local-fs.target
_EOF_
systemctl daemon-reload
systemctl enable dietpi-ramlog.service
#-------------------------------------------------------------------------------
#Assure absence of dhcpcd5, if dhclient (isc-dhcp-client) is active: https://github.com/Fourdee/DietPi/issues/1560#issuecomment-370136642
ps aux | grep -q 'dhclient' && G_AGP dhcpcd5
#-------------------------------------------------------------------------------
#Fix microcode installation based on image creation CPU instead of image target CPU: https://github.com/Fourdee/DietPi/pull/1596
if (( $G_HW_ARCH == 10 )); then
if grep 'vendor_id' /proc/cpuinfo | grep -qi 'intel'; then
dpkg --get-selections | grep -q '^amd64-microcode' && G_AGP amd64-microcode
G_AGI intel-microcode
elif grep 'vendor_id' /proc/cpuinfo | grep -qi 'amd'; then
dpkg --get-selections | grep -q '^intel-microcode' && G_AGP intel-microcode
G_AGI amd64-microcode
fi
fi
#-------------------------------------------------------------------------------
#Reinstalls
# UrBackupServer
/DietPi/dietpi/dietpi-software reinstall 111
#-------------------------------------------------------------------------------
#Cron minutely support: https://github.com/Fourdee/DietPi/pull/1578
mkdir -p /etc/cron.minutely
if (( ! $(grep -ci -m1 'cron.minutely' /etc/crontab) )); then
cat << _EOF_ >> /etc/crontab
*/30 * * * * root cd / && run-parts --report /etc/cron.minutely
_EOF_
fi
#-------------------------------------------------------------------------------
fi
#-------------------------------------------------------------------------------
#NB: all if statements must contain at least one command. Prevents bash having a hissy fit :)
#-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#Run
Incremental_Patch_System
#-------------------------------------------------------------------------------
sleep 0.25
#-------------------------------------------------------------------------------
exit
#-------------------------------------------------------------------------------
}