forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch_file
executable file
·2111 lines (1745 loc) · 121 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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
{
#////////////////////////////////////
# DietPi Patch File Script
#
#////////////////////////////////////
# Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com
#
#////////////////////////////////////
#
# Info:
# - Online patching for client system
# - Runs from dietpi-update
#
# Usage:
# - /boot/dietpi/patch_file [$G_DIETPI_VERSION_SUB]
#////////////////////////////////////
# Whether to schedule a reboot after DietPi-Update
REBOOT=
# Pre-v6.29: DietPi-RAMdisk removal needs to be done before loading DietPi-Globals, else /boot/dietpi still contains the old code
if [[ -d '/DietPi' && $(readlink -f '/DietPi') != '/boot' ]]; then
# Copy new code to disk
cp -Rf /DietPi/* /boot/
# Disable and remove service and mount
systemctl disable dietpi-ramdisk
umount -Rl /DietPi
sed -i '/[[:blank:]]\/DietPi[[:blank:]]/d' /etc/fstab
rm -Rf /DietPi /boot/dietpi/{,func/}dietpi-ramdisk /etc/systemd/system/dietpi-ramdisk.service
# Create symlink for backwards compatibility
ln -s /boot /DietPi
# Failsafe
sync
fi
# - Pre-create new DietPi runtime dir for later used scripts, created via /etc/tmpfiles.d/dietpi.conf from next boot on
[[ -d '/run/dietpi' ]] || { mkdir -p /run/dietpi; chmod 777 /run/dietpi; }
# Pre-v6.22: Update Git owner due to official lead transfer from Fourdee to MichaIng: https://github.com/MichaIng/DietPi/issues/2589
grep -q '^[[:blank:]]*DEV_GITOWNER=Fourdee' /boot/dietpi.txt && sed -i '/^[[:blank:]]*DEV_GITOWNER=/c\DEV_GITOWNER=MichaIng' /boot/dietpi.txt
if [[ -f '/boot/dietpi/.version' ]] && grep -q '^G_GITOWNER=Fourdee' /boot/dietpi/.version; then
sed -i '/^G_GITOWNER=/c\G_GITOWNER=MichaIng' /boot/dietpi/.version
# Pre-v6.17: New ".version" system
# - As loaded pre-v6.17 dietpi-update will overwrite ".version" to previous 2/3 line system, we need to rerun dietpi-update.
elif [[ ! -f '/boot/dietpi/.version' ]] || ! grep -q '^G_GITOWNER=' /boot/dietpi/.version; then
rm /boot/dietpi/.version
fi
# Pre-v6.29: Convert IMAGE_ADDITIONAL_CREDITS line to .prep_info pre-image and migrate existing HW_UUID line to new .hw_model system
if [[ -f '/boot/dietpi/.hw_model' ]] && ! grep -q '^G_HW_UUID=' /boot/dietpi/.hw_model; then
[[ ! -f '/boot/dietpi/.prep_info' && $(mawk 'NR==8' /boot/dietpi/.hw_model) ]] && cat << _EOF_ > /boot/dietpi/.prep_info
0
$(mawk 'NR==8' /DietPi/dietpi/.hw_model)
_EOF_
echo "G_HW_UUID=$(mawk 'NR==5' /boot/dietpi/.hw_model)" > /boot/dietpi/.hw_model
fi
# Pre-v6.29: Assure that C.UTF-8 locale is available
if ! locale -a | grep -qiE '^C.UTF-?8'; then
apt-get -qq install --reinstall libc-bin
# libc-bin ships C.UTF-8 as static locale already but let's add it to memory-mapped archive as well
localedef --add-to-archive /usr/lib/locale/C.UTF-8
fi
# Update changed hardware IDs before dietpi-obtain_hw_model would reset them to 22
if [[ -f '/etc/.dietpi_hw_model_identifier' ]]
then
G_HW_MODEL=$(</etc/.dietpi_hw_model_identifier)
# Pre-v7.1: https://github.com/MichaIng/DietPi/pull/4193
if [[ $G_HW_MODEL == 69 ]] # Firefly RK3399
then
echo 24 > /etc/.dietpi_hw_model_identifier # Generic Rockchip RK3399
elif [[ $G_HW_MODEL == 50 || $G_HW_MODEL == 41 || $G_HW_MODEL == 3[54310] ]] # BananaPi M2+, OrangePi PC Plus, OPi Zero 2 Plus, OrangePi Plus, OrangePi Lite, OrangePi One, OrangePi PC
then
echo 25 > /etc/.dietpi_hw_model_identifier # Generic Allwinner H3
elif [[ $G_HW_MODEL == 3[87] ]] # OPi PC2, OPi Prime
then
echo 26 > /etc/.dietpi_hw_model_identifier # Generic Allwinner H5
fi
fi
# Import DietPi-Globals --------------------------------------------------------------
/boot/dietpi/func/dietpi-obtain_hw_model # Always update
. /boot/dietpi/func/dietpi-globals
readonly G_PROGRAM_NAME='DietPi-Patch'
G_INIT
# Import DietPi-Globals --------------------------------------------------------------
# Grab input, if given, else fallback to dietpi-globals estimation
# - DietPi-Update includes G_VERSIONDB_SAVE after every subversion patch from v6.27 on.
(( $1 )) && G_DIETPI_VERSION_SUB=$1
# Pre-v6.29: Migrate newly supported SBCs from dev to master branch
if [[ $G_DIETPI_VERSION_SUB -lt 29 && -f '/etc/.dietpi_hw_model_identifier' ]]; then
# NanoPi M4V2 (58)
# PINE H64 (45)
# ROCK Pi S (73)
if [[ $(</etc/.dietpi_hw_model_identifier) =~ ^(58|45|73)$ ]] && grep -qE '^[[:blank:]]*DEV_GITBRANCH=(dev|beta)' /boot/dietpi.txt; then
G_DIETPI-NOTIFY 2 'Migrating from development or beta to DietPi master branch'
G_CONFIG_INJECT 'DEV_GITBRANCH=' 'DEV_GITBRANCH=master' /boot/dietpi.txt
fi
fi
# Pre-v6.20: New $G_DIETPI_INSTALL_STAGE system
# - As loaded pre-v6.20 dietpi-update will recreate ".update_stage", we need to rerun dietpi-update.
if [[ -f '/boot/dietpi/.update_stage' ]]; then
G_EXEC rm /boot/dietpi/.update_stage
if (( $G_DIETPI_INSTALL_STAGE > 0 )); then
echo 2 > /boot/dietpi/.install_stage
# As first run dietpi-update is executed from old dietpi-software, we need to reboot to load new first run setup scripts.
else
echo 0 > /boot/dietpi/.install_stage
REBOOT=1
fi
fi
# Restart DietPi-Update when not yet done, to migrate to v7
if (( $(pgrep -c patch_file) < 2 )); then
# Save current version to rerun patch on next launch
# - We know the core version is 6, so store it like that, else version prior to v6.17 will default to v7: https://github.com/MichaIng/DietPi/issues/4385
G_DIETPI_VERSION_CORE=6
G_VERSIONDB_SAVE
# Remove DietPi-Update and DietPi-Patch working directories to allow concurrent execution.
G_EXEC cd /tmp
G_EXEC rm -Rf /tmp/DietPi-{Update,Patch}
G_DIETPI-NOTIFY 0 'Restarting DietPi-Update with new code...\n'
# Failsafe: Sync changes to disk to avoid async-related issues
sync
G_SLEEP 3
# Apply update forcefully, since user has already chosen to do so
/boot/dietpi/dietpi-update 1
# Reboot system if scheduled, else exit this script + parental dietpi-update only to avoid deprecated update finish
if [[ $REBOOT == 1 ]]; then
G_WHIP_MSG 'The system will now reboot to finish this update.'
reboot
else
G_DIETPI-NOTIFY 0 'Everything done! Terminating the obsolete DietPi-Update parent instance...\n'
kill "$PPID"
exit
fi
fi
#/////////////////////////////////////////////////////////////////////////////////////
# Incremental patch system
#/////////////////////////////////////////////////////////////////////////////////////
# - Prevent backup prompts during patching e.g. from DietPi-Software reinstalls
export G_PROMPT_BACKUP_DISABLED=1
# - Prevent initial and final service control during DietPi-Software reinstalls
export G_SERVICE_CONTROL=0
Subversion_Patch(){
if (( $G_DIETPI_VERSION_SUB == 14 )); then
#-------------------------------------------------------------------------------
# Reinstall fake-hwclock: https://github.com/MichaIng/DietPi/issues/2035#issuecomment-416345155
G_AGI fake-hwclock
#-------------------------------------------------------------------------------
# Reinstalls:
# v6.17 MPD: https://github.com/MichaIng/DietPi/issues/2032#issuecomment-415559451
# v6.33 PlexPy: https://github.com/MichaIng/DietPi/issues/2047
#-------------------------------------------------------------------------------
# Update DietPi-Sync save file to new format
if [[ -f '/boot/dietpi/.dietpi-sync_settings' ]] && ! grep -q '^FP_SOURCE=' /boot/dietpi/.dietpi-sync_settings; then
G_EXEC cp -a /boot/dietpi/.dietpi-sync_settings{,_bk}
cat << _EOF_ > /boot/dietpi/.dietpi-sync_settings
FP_SOURCE=$(mawk 'NR==1' /boot/dietpi/.dietpi-sync_settings_bk)
FP_TARGET=$(mawk 'NR==2' /boot/dietpi/.dietpi-sync_settings_bk)
SYNC_DELETE_MODE=$(mawk 'NR==3' /boot/dietpi/.dietpi-sync_settings_bk)
SYNC_CRONDAILY=$(mawk 'NR==5' /boot/dietpi/.dietpi-sync_settings_bk)
_EOF_
fi
#-------------------------------------------------------------------------------
# Preboot script addition
G_EXEC systemctl enable dietpi-preboot
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 15 )); then
#-------------------------------------------------------------------------------
# Move to new WiFi cred array system and db store: https://github.com/MichaIng/DietPi/issues/368
if [[ ! -f '/var/lib/dietpi/dietpi-wifi.db' ]]; then
cat << _EOF_ > /var/lib/dietpi/dietpi-wifi.db
aWIFI_SSID[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_SSID=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_KEY[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_KEY=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_KEYMGR[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_KEYMGR=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_PROTO[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_PROTO=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_PAIRWISE[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_PAIRWISE=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_AUTH_ALG[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_AUTH_ALG=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_EAP[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_EAP=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_IDENTITY[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_IDENTITY=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_PASSWORD[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_PASSWORD=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_PHASE1[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_PHASE1=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_PHASE2[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_PHASE2=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
aWIFI_CERT[0]='$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_CERT=' /boot/dietpi.txt | sed 's/^[^=]*=//')'
_EOF_
# Apply + init the remainder of array (5) + set permissions on file
/boot/dietpi/func/dietpi-wifidb 1
fi
#-------------------------------------------------------------------------------
# Fix rare WiFi interface start issue: https://github.com/MichaIng/DietPi/issues/2074
# shellcheck disable=SC2016
[[ -f '/etc/network/if-pre-up.d/wireless-tools' ]] && sed -i '\|^[[:blank:]]ifconfig "$IFACE" up$|c\\t/sbin/ip link set dev "$IFACE" up' /etc/network/if-pre-up.d/wireless-tools
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 16 )); then
#-------------------------------------------------------------------------------
# Survey/BugReport SFTP uploads, add cert for access: https://github.com/MichaIng/DietPi/issues/2022
# - Switch to "ssh.dietpi.com" die to Cloudflare: https://github.com/MichaIng/DietPi/issues/2022
# - On v6.15 this was missing in PREP, thus images created meanwhile, so redo with v6.17 patch:
[[ -d '/root/.ssh' ]] || G_EXEC mkdir /root/.ssh
[[ -f '/root/.ssh/known_hosts' ]] || > /root/.ssh/known_hosts
G_EXEC sed -i '/^dietpi.com/d' /root/.ssh/known_hosts
G_EXEC sed -i '/^185.101.93.93/d' /root/.ssh/known_hosts
if (( $G_DISTRO < 7 ))
then
G_CONFIG_INJECT '\[?ssh.dietpi.com(]:29248)?[[:blank:]]' '[ssh.dietpi.com]:29248 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE6aw3r6aOEqendNu376iiCHr9tGBIWPgfrLkzjXjEsHGyVSUFNnZt6pftrDeK7UX+qX4FxOwQlugG4fymOHbimRCFiv6cf7VpYg1Ednquq9TLb7/cIIbX8a6AuRmX4fjdGuqwmBq3OG7ZksFcYEFKt5U4mAJIaL8hXiM2iXjgY02LqiQY/QWATsHI4ie9ZOnwrQE+Rr6mASN1BVFuIgyHIbwX54jsFSnZ/7CdBMkuAd9B8JkxppWVYpYIFHE9oWNfjh/epdK8yv9Oo6r0w5Rb+4qaAc5g+RAaknHeV6Gp75d2lxBdCm5XknKKbGma2+/DfoE8WZTSgzXrYcRlStYN' /root/.ssh/known_hosts
else
G_CONFIG_INJECT '\[?ssh.dietpi.com(]:29248)?[[:blank:]]' '[ssh.dietpi.com]:29248 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJdEPlagpQ+RVHNOX3jkG1Bya7Oza1dAke8h8NszVW84' /root/.ssh/known_hosts
fi
#-------------------------------------------------------------------------------
# ROCK64, remove HW accell config, as its not currently functional: https://github.com/MichaIng/DietPi/issues/2086
[[ $G_HW_MODEL == 43 && -f '/etc/X11/xorg.conf.d/20-armsoc.conf' ]] && G_EXEC rm /etc/X11/xorg.conf.d/20-armsoc.conf
#-------------------------------------------------------------------------------
# Convert and remove old dietpi.txt entry (this includes the comment)
grep -q 'CONFIG_PREFER_IPVERSION' /boot/dietpi.txt && G_EXEC sed -i '/CONFIG_PREFER_IPVERSION/d' /boot/dietpi.txt
#-------------------------------------------------------------------------------
# Update IPv6 handling: https://github.com/MichaIng/DietPi/issues/2027
# - Advice user to re-enable IPv6 on kernel level
if [[ ! -d '/proc/sys/net/ipv6' ]]; then
G_WHIP_MENU_ARRAY=(
0 ': Re-enable IPv6 on kernel level, disable via sysctl instead (Recommended)'
1 ': Keep IPv6 disabled on kernel level, I know what I am doing!'
)
G_WHIP_DEFAULT_ITEM=0
if G_WHIP_MENU '[WARNING] IPv6 is disabled via kernel module blacklist or boot cmd line.\n
This feature was previously offered via DietPi-Config and has since been removed.\n
Since more and more software requires and expects IPv6 kernel settings to be available. If you keep the current settings, this might lead to APT install errors and/or general system instability.\n
We strongly recommend you select "0 : Re-enable IPv6 on kernel level". By doing so, IPv6 will remain disabled for the interfaces at sysctl level, and, no IPv6 addresses will be assigned to your network devices.\n\nTLDR: Select option "0" :)' && (( $G_WHIP_RETURNED_VALUE == 0 )); then
# Remove kernel module blacklisting
[[ -f '/etc/modprobe.d/99-dietpi-blacklist-ipv6.conf' ]] && rm /etc/modprobe.d/99-dietpi-blacklist-ipv6.conf
# Failsafe: Comment "blacklist ipv6" entries in all other sysctl config files
local i
for i in /etc/modprobe.d/*
do
[[ -f $i ]] && sed -i 's/^[[:blank:]]*blacklist[[:blank:]]ipv6/#&/' "$i"
done
# Remove boot cmd line entry
# - RPi
if (( $G_HW_MODEL < 10 )); then
# Separately remove with leading and trailing blank, since we don't know, if it's first or last argument and we must not remove both blanks
sed -i '/^[[:blank:]]*root=/s/[[:blank:]]ipv6.disable=1//' /boot/cmdline.txt
sed -i '/^[[:blank:]]*root=/s/ipv6.disable=1[[:blank:]]//' /boot/cmdline.txt
# - Odroid
elif (( $G_HW_MODEL < 20 )); then
sed -i '/^[[:blank:]]*setenv boot/s/[[:blank:]]ipv6.disable=1//' /boot/boot.ini
sed -i '/^[[:blank:]]*setenv boot/s/ipv6.disable=1[[:blank:]]//' /boot/boot.ini
# - x86
elif (( $G_HW_ARCH == 10 )); then
sed -i '/^[[:blank:]]*GRUB_CMDLINE_LINUX_DEFAULT="/s/[[:blank:]]ipv6.disable=1//' /etc/default/grub
sed -i '/^[[:blank:]]*GRUB_CMDLINE_LINUX_DEFAULT="/s/ipv6.disable=1[[:blank:]]//' /etc/default/grub
update-grub
fi
# Disable IPv6 via sysctl
echo -e 'net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1' > /etc/sysctl.d/dietpi-disable_ipv6.conf
G_CONFIG_INJECT 'CONFIG_ENABLE_IPV6=' 'CONFIG_ENABLE_IPV6=0' /boot/dietpi.txt
fi
fi
#-------------------------------------------------------------------------------
# Reinstalls:
# v6.20 MPD
# v6.19 Chromium: Update kiosk mode autostart script: https://github.com/MichaIng/DietPi/issues/2158
if (( $G_DIETPI_INSTALL_STAGE == 2 )); then
# Run Transmission and Plex Media Server as "dietpi" group: https://github.com/MichaIng/DietPi/issues/2067#issuecomment-427579779
if grep -q '^aSOFTWARE_INSTALL_STATE\[44\]=2' /boot/dietpi/.installed; then
mkdir -p /etc/systemd/system/transmission-daemon.service.d
echo -e '[Service]\nGroup=dietpi' >> /etc/systemd/system/transmission-daemon.service.d/dietpi-group.conf
G_CONFIG_INJECT '\"umask\":' ' "umask": 7,' /etc/transmission-daemon/settings.json
fi
if grep -q '^aSOFTWARE_INSTALL_STATE\[42\]=2' /boot/dietpi/.installed; then
mkdir -p /etc/systemd/system/plexmediaserver.service.d
echo -e '[Service]\nGroup=dietpi' >> /etc/systemd/system/plexmediaserver.service.d/dietpi-group.conf
fi
fi
#-------------------------------------------------------------------------------
# Now part of rootfs: https://github.com/MichaIng/DietPi/issues/2103
G_EXEC chmod +x /var/lib/dietpi/services/dietpi-wifi-monitor.sh
#-------------------------------------------------------------------------------
# Remove obsolete EMR patch file and redo removal of obsolete script files, as they were not removed from disk: https://github.com/MichaIng/DietPi/pull/2123#issuecomment-428121908
G_EXEC rm -Rf /boot/dietpi/{.patch_emr,dietpi-{obtain_hw_model,cpu_set,ramlog,logclear,banner}}
#-------------------------------------------------------------------------------
# Remove www-data under sudo without PW: https://github.com/MichaIng/DietPi/issues/2121
G_EXEC sed -i '/^www-data ALL=NOPASSWD: ALL/d' /etc/sudoers
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 17 )); then
#-------------------------------------------------------------------------------
# Remove mysql.service as we use mariadb.service, both cannot exist: https://github.com/MichaIng/DietPi/issues/1913#issuecomment-441343798
if [[ -f '/etc/init.d/mysql' ]]; then
G_DIETPI-NOTIFY 2 'Switching from /etc/init.d/mysql to mariadb.service'
killall -qw mariadb mysqld # Failsafe
G_EXEC systemctl disable --now mysql
G_EXEC rm /etc/init.d/mysql
update-rc.d -f mysql remove
fi
#-------------------------------------------------------------------------------
# Workarounds
# - Workaround for NanoPi Fire3 with tty1 disabled: https://github.com/MichaIng/DietPi/issues/2225
if (( $G_HW_MODEL == 62 )) && dmesg | grep -qi 'NanoPi Fire3'; then
chvt 2
echo -e '#!/bin/dash\nchvt 2' > /var/lib/dietpi/postboot.d/fire3_tty2
fi
#-------------------------------------------------------------------------------
# Reinstalls:
# v6.25 OMPD: https://github.com/MichaIng/DietPi/issues/2156#issue-372201367
# v6.25 myMPD: https://github.com/MichaIng/DietPi/issues/2156#issue-372201367
# RoonBridge: https://community.roonlabs.com/t/dietpi-allo-units-not-getting-the-roonbridge-b167-update-from-b164/52503/10?u=dan_knight
# v6.34 Radarr/Lidarr/Sonarr: https://github.com/MichaIng/DietPi/issues/2219
# v6.33 Mosquitto: https://github.com/MichaIng/DietPi/issues/2243#issuecomment-439492463
if (( $G_DIETPI_INSTALL_STAGE == 2 ))
then
echo 106 121 144 >> /var/tmp/dietpi/dietpi-update_reinstalls
# - Switch to "mariadb" systemd service on Stretch+: https://github.com/MichaIng/DietPi/pull/2196
if grep -q '^aSOFTWARE_INSTALL_STATE\[88\]=2' /boot/dietpi/.installed
then
G_WHIP_MSG '[ INFO ] Switch from "mysql" to "mariadb" service
\nOn Stretch (and above) systems, DietPi-Services will use the pre-installed "mariadb" systemd service now, instead of the obsolete "mysql" init.d service.
\nYou will not face any practical differences, since both services start the same MariaDB binary. In case you manually want to handle the service, use "systemctl start|stop|restart mariadb" from now on.'
fi
fi
#-------------------------------------------------------------------------------
# systemd-logind required for shutdown options: https://github.com/MichaIng/DietPi/issues/2155#issuecomment-437702869
(( $G_DIETPI_INSTALL_STAGE == 2 )) && grep -q '^aSOFTWARE_INSTALL_STATE\[31\]=2' /boot/dietpi/.installed && systemctl unmask systemd-logind
#-------------------------------------------------------------------------------
# Patch Odroid LCD: https://github.com/MichaIng/DietPi/issues/2256
[[ -f '/etc/systemd/system/odroid-lcd35.service' ]] && /boot/dietpi/func/dietpi-set_hardware lcdpanel odroid-lcd35
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 18 )); then
#-------------------------------------------------------------------------------
# Conf renaming: https://github.com/MichaIng/DietPi/pull/2312/files
# - Apache
if [[ -f '/etc/apache2/sites-available/owncloud.conf' ]]; then
a2dissite owncloud
G_EXEC mv /etc/apache2/sites-available/owncloud.conf /etc/apache2/sites-available/dietpi-owncloud.conf
fi
if [[ -f '/etc/apache2/sites-available/nextcloud.conf' ]]; then
a2dissite nextcloud
G_EXEC mv /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-available/dietpi-nextcloud.conf
fi
if [[ -f '/etc/apache2/sites-available/rutorrent.conf' ]]; then
a2dissite rutorrent
G_EXEC mv /etc/apache2/sites-available/rutorrent.conf /etc/apache2/sites-available/dietpi-rutorrent.conf
a2ensite dietpi-rutorrent
fi
# - Nginx
[[ -f '/etc/nginx/sites-dietpi/owncloud.config' ]] && G_EXEC mv /etc/nginx/sites-dietpi/owncloud.config /etc/nginx/sites-dietpi/dietpi-owncloud.conf
[[ -f '/etc/nginx/sites-dietpi/nextcloud.config' ]] && G_EXEC mv /etc/nginx/sites-dietpi/nextcloud.config /etc/nginx/sites-dietpi/dietpi-nextcloud.conf
[[ -f '/etc/nginx/sites-dietpi/rutorrent.config' ]] && G_EXEC mv /etc/nginx/sites-dietpi/rutorrent.config /etc/nginx/sites-dietpi/dietpi-rutorrent.conf
# - Failsafe and custom entries
for i in /etc/nginx/sites-dietpi/*.config
do
[[ -f $i ]] || break
G_EXEC mv "$i" "${i%ig}"
done
# - Apply to Nginx vhost
# - Move to v6.19 => v6.20 patch for users, which update directly from v6.19.5 to v6.20
#grep -q 'include /etc/nginx/sites-dietpi/\*\.config;' /etc/nginx/sites-available/default &> /dev/null && G_CONFIG_INJECT 'include /etc/nginx/sites-dietpi/\*\.config;' 'include /etc/nginx/sites-dietpi/*.conf;' /etc/nginx/sites-available/default
# - Kodi input rules
[[ -f '/etc/udev/rules.d/99-input.rules' ]] && mv /etc/udev/rules.d/99-input.rules /etc/udev/rules.d/99-dietpi-kodi.rules
#-------------------------------------------------------------------------------
# ASUS TB 2.0.8 image, fix corrupt characters in desktops
if (( $G_HW_MODEL == 52 )) && dpkg --get-selections | grep -q 'fonts-dejavu-core'; then
G_AGI --reinstall libfreetype6 fonts-dejavu-core
G_EXEC fc-cache -r -v
fi
#-------------------------------------------------------------------------------
# Switch to udev rule for WiFi powersaving disable
rm -f /etc/systemd/system/wifi_disable_powersave.service*
#-------------------------------------------------------------------------------
# - Reinstalls
# Chromium: https://github.com/MichaIng/DietPi/issues/2298
# v6.27 Allo GUI: https://github.com/MichaIng/DietPi/issues/2305
# v6.27 GMrender: Due to Allo GUI service enable failure.
# Xorg: XU4 conf
# v6.23 Pydio: https://github.com/MichaIng/DietPi/issues/2308
(( $G_DIETPI_INSTALL_STAGE == 2 )) && echo 6 113 >> /var/tmp/dietpi/dietpi-update_reinstalls
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 19 )); then
#-------------------------------------------------------------------------------
# rpi-update drop support info
if command -v rpi-update > /dev/null && G_WHIP_YESNO '[ INFO ] RPi-Update detected\n\nIn our effort to improve system stability, and, offer software installations which build custom modules (eg: WireGuard), we can no longer support systems with non-stock-APT kernel installed (eg: rpi-update).\n\nWould you like to revert to the APT kernel now, ensuring stability and official DietPi system support?'; then
local arpi_firmware=('raspberrypi-bootloader' 'raspberrypi-kernel' 'libraspberrypi-bin' 'libraspberrypi0')
G_AGP rpi-update
command -v rpi-source > /dev/null && G_EXEC rm "$(command -v rpi-source)"
G_AGI --reinstall "${arpi_firmware[@]}"
apt-mark unhold "${arpi_firmware[@]}"
fi
#-------------------------------------------------------------------------------
# Apply Nginx vhost patch: https://github.com/MichaIng/DietPi/pull/2327
# - Moved from v6.18 => v6.19 patch for users, which update directly from v6.19.5 to v6.20
grep -q 'include /etc/nginx/sites-dietpi/\*\.config;' /etc/nginx/sites-available/default &> /dev/null && G_CONFIG_INJECT 'include /etc/nginx/sites-dietpi/\*\.config;' 'include /etc/nginx/sites-dietpi/*.conf;' /etc/nginx/sites-available/default
#-------------------------------------------------------------------------------
# Migrate Blynk to new dir structure: https://github.com/MichaIng/DietPi/issues/2322
if (( $G_DIETPI_INSTALL_STAGE == 2 )) && grep -q '^aSOFTWARE_INSTALL_STATE\[131\]=2' /boot/dietpi/.installed &&
[[ -d '/mnt/dietpi_userdata/blynk' && ! -d '/mnt/dietpi_userdata/blynk/data' ]]; then
G_EXEC mv /mnt/dietpi_userdata/blynk /mnt/dietpi_userdata/blynk_bak
G_EXEC mv /etc/blynkserver /mnt/dietpi_userdata/blynk
G_EXEC mv /mnt/dietpi_userdata/blynk/server.jar /mnt/dietpi_userdata/blynk/blynkserver.jar
G_EXEC mv /mnt/dietpi_userdata/blynk_bak/server.properties /mnt/dietpi_userdata/blynk/
G_EXEC mv /mnt/dietpi_userdata/blynk_bak /mnt/dietpi_userdata/blynk/data
G_CONFIG_INJECT 'data.folder=' 'data.folder=/mnt/dietpi_userdata/blynk/data' /mnt/dietpi_userdata/blynk/server.properties
fi
#-------------------------------------------------------------------------------
# Grafana: Remove obsolete x86_64 APT source, reinstall below to apply official repo: https://github.com/MichaIng/DietPi/issues/2449
G_EXEC rm -f /etc/apt/sources.list.d/grafana*.list
#-------------------------------------------------------------------------------
# - Reinstalls
# Blynk: Apply new run user, update binary (jar)
# v6.22 Deluge: https://github.com/MichaIng/DietPi/issues/2339
# Netdata: https://github.com/MichaIng/DietPi/pull/2337
# NAA Daemon: https://github.com/MichaIng/DietPi/issues/2387#issue-395321320
# MPD: https://github.com/MichaIng/DietPi/issues/2377
# Samba: https://github.com/MichaIng/DietPi/issues/2396#issuecomment-451701569
# v6.33 Amiberry 2.24
# Shairport Sync: https://github.com/MichaIng/DietPi/issues/2439
# v6.27 Grafana: https://github.com/MichaIng/DietPi/issues/2449
if (( $G_DIETPI_INSTALL_STAGE == 2 )); then
echo 37 65 124 128 131 >> /var/tmp/dietpi/dietpi-update_reinstalls
# Samba: Link disk cache to RAM: https://github.com/MichaIng/DietPi/issues/2396
if grep -q '^aSOFTWARE_INSTALL_STATE\[96\]=2' /boot/dietpi/.installed; then
G_EXEC rm -Rf /var/cache/samba
G_EXEC mkdir -p /run/samba-cache
G_EXEC ln -s /run/samba-cache /var/cache/samba
G_EXEC eval "echo 'd /run/samba-cache' > /etc/tmpfiles.d/dietpi-samba_cache.conf"
fi
fi
#-------------------------------------------------------------------------------
# DietPi file renaming/removal:
# - autologin.conf: https://github.com/MichaIng/DietPi/pull/2343
[[ -f '/etc/systemd/system/getty@tty1.service.d/autologin.conf' ]] && G_EXEC mv /etc/systemd/system/getty@tty1.service.d/autologin.conf /etc/systemd/system/getty@tty1.service.d/dietpi-autologin.conf
# - README.md: https://github.com/MichaIng/DietPi/pull/2341
[[ -f '/boot/README.md' ]] && G_EXEC mv /boot/README.md /boot/dietpi-README.md
# - kill-ssh-user-sessions-before-network: https://github.com/MichaIng/DietPi/pull/2357/commits/c8eb15c169cfaba69fec0b3e631e2241e0bdb7d5
systemctl disable kill-ssh-user-sessions-before-network 2> /dev/null
[[ -f '/etc/systemd/system/kill-ssh-user-sessions-before-network.service' ]] && G_EXEC rm /etc/systemd/system/kill-ssh-user-sessions-before-network.service
[[ -f '/var/lib/dietpi/services/kill-ssh-user-sessions-before-network.sh' ]] && G_EXEC rm /var/lib/dietpi/services/kill-ssh-user-sessions-before-network.sh
systemctl enable dietpi-kill_ssh
# - dietpi-unsupported_terminal.sh: https://github.com/MichaIng/DietPi/issues/2347
[[ -f '/etc/profile.d/dietpi-unsupported_terminal.sh' ]] && G_EXEC rm /etc/profile.d/dietpi-unsupported_terminal.sh
# - Possible leftover from PREP:
[[ -f '/boot/dietpi/pre-patch_file' ]] && G_EXEC rm /boot/dietpi/pre-patch_file
# - dietpi/conf removal: https://github.com/MichaIng/DietPi/pull/2393
[[ -d '/boot/dietpi/conf' ]] && G_EXEC rm -R /boot/dietpi/conf
#-------------------------------------------------------------------------------
#.dietpi-autostart_index removal, if zero: https://github.com/MichaIng/DietPi/pull/2343
[[ -f '/boot/dietpi/.dietpi-autostart_index' ]] && (( $(</boot/dietpi/.dietpi-autostart_index) == 0 )) && G_EXEC rm /boot/dietpi/.dietpi-autostart_index
#-------------------------------------------------------------------------------
# Disable coturn logging for existing installs: https://github.com/MichaIng/DietPi/pull/2333
(( $G_DIETPI_INSTALL_STAGE == 2 )) && grep -q '^aSOFTWARE_INSTALL_STATE\[168\]=2' /boot/dietpi/.installed && G_CONFIG_INJECT 'DAEMON_ARGS=' "DAEMON_ARGS='-c /etc/turnserver.conf -o -l stdout --no-stdout-log --simple-log'" /etc/default/coturn
#-------------------------------------------------------------------------------
# Remove nofail and x-systemd.automount option from /boot mount: https://github.com/MichaIng/DietPi/pull/2357#issuecomment-449177715
G_EXEC sed -i '\|[[:blank:]]/boot[[:blank:]]|s|,x-systemd.automount||' /etc/fstab
G_EXEC sed -i '\|[[:blank:]]/boot[[:blank:]]|s|,nofail||' /etc/fstab
#-------------------------------------------------------------------------------
# Re-enable owncloud/Nextcloud Apache configs, to fix faulty v6.19 installs: https://github.com/MichaIng/DietPi/pull/2361/commits/e33ca150cf29a4f278f5df2defc495053700a91e
[[ -f '/etc/apache2/sites-available/dietpi-owncloud.conf' ]] && G_EXEC a2ensite dietpi-owncloud
[[ -f '/etc/apache2/sites-available/dietpi-nextcloud.conf' ]] && G_EXEC a2ensite dietpi-nextcloud
#-------------------------------------------------------------------------------
# Clear install state for Medusa
[[ $G_DIETPI_INSTALL_STAGE == 2 && ! -d '/mnt/dietpi_userdata/medusa' ]] && sed -i '/^aSOFTWARE_INSTALL_STATE\[116\]=/d' /boot/dietpi/.installed
# - Inform user about SickRage being replaced by Medusa
if [[ -d '/etc/sickrage' || -d '/mnt/dietpi_userdata/sickrage' ]]; then
G_WHIP_MSG '[WARNING] We found an existing SickRage install on your system\n
We already dropped SickRage from DietPi-Software install options with v6.18, now it has been fully replaced with "Medusa", an older stabilized fork.
DietPi will still handle your SickRage service and directory permissions, but this might change soon.\n
We encourage everyone to use Medusa instead. There are guides for migrating your SickRage TV shows and settings, but the most general advice is to do a fresh install of Medusa: dietpi-software install 116\n
Also have a look at "Sonarr", another alternative TV show manager, available for install via DietPi-Software.'
fi
#-------------------------------------------------------------------------------
# Remove obsolete flags: https://github.com/MichaIng/DietPi/pull/2398#issuecomment-452398770
[[ -f '/var/lib/dietpi/.G_RPI_UPDATE' ]] && rm /var/lib/dietpi/.G_RPI_UPDATE
# https://github.com/MichaIng/DietPi/pull/2407/commits/5b7ad8bddc9dd5ffe89a2614615eb936333c8d41
[[ -f '/var/lib/dietpi/.compiled_i-sabre-k2m' ]] && rm /var/lib/dietpi/.compiled_i-sabre-k2m
#-------------------------------------------------------------------------------
# RPi changes: https://github.com/MichaIng/DietPi/pull/2402
if (( $G_HW_MODEL < 10 )); then
# Remove/Replace obsolete config.txt settings
G_EXEC sed -i 's/display_rotate/display_hdmi_rotate/' /boot/config.txt
G_EXEC sed -i '/disable_pvt/d' /boot/config.txt
G_EXEC sed -i '/avoid_pwm_pll/d' /boot/config.txt
# Remove doubled AUTO_SETUP_HEADLESS entry, introduced with Beta v6.20.2
if (( $(grep -c '^[[:blank:]]*AUTO_SETUP_HEADLESS=' /boot/dietpi.txt) > 1 )); then
# Last match is the correct one, added by "dietpi-set_hardware headless 1"
local current=$(grep '^[[:blank:]]*AUTO_SETUP_HEADLESS=' /boot/dietpi.txt | tail -1 | sed 's/^[^=]*=//')
G_EXEC sed -i '/^[[:blank:]]*AUTO_SETUP_HEADLESS=/d' /boot/dietpi.txt
G_EXEC eval "echo 'AUTO_SETUP_HEADLESS=$current' >> /boot/dietpi.txt"
fi
# Apply new headless mode method, if set
grep -q '^[[:blank:]]*CONFIG_HDMI_OUTPUT=0' /boot/dietpi.txt && /boot/dietpi/func/dietpi-set_hardware headless 1
# Renamed to: AUTO_SETUP_HEADLESS (added by verify_dietpi.txt automatically)
G_EXEC sed -i '/CONFIG_HDMI_OUTPUT/d' /boot/config.txt
fi
#-------------------------------------------------------------------------------
# Buster: "systemd" does not depend on "procps" anymore, thus we need to set it manually installed, simply applied on all distro versions.
G_AGI procps
#-------------------------------------------------------------------------------
# Remove wireless-power setting from /etc/network/interfaces, if not supported by adapter/firmware: https://github.com/MichaIng/DietPi/issues/2198
iwconfig "$(G_GET_NET -q -t wlan iface)" power off &> /dev/null || sed -i '/^wireless-power/d' /etc/network/interfaces
#-------------------------------------------------------------------------------
# Remove Armbian banner/profiles left on ASUS TB image
G_EXEC rm -f /etc/profile.d/armbian-*
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 20 )); then
#-------------------------------------------------------------------------------
# Image updates
if [[ $G_HW_MODEL == 4[0234] && ! -f '/etc/armbian-release' ]]; then
G_WHIP_MSG "[ INFO ] The base image for $G_HW_MODEL_NAME has been updated.\n\nPlease reinstall your system with the latest image from https://dietpi.com#download.\n\nYou can continue to use this existing installation, however, some kernel features may not be available."
fi
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 21 )); then
#-------------------------------------------------------------------------------
# Redo our /etc/bash.bashrc entry, user confirmed 4 entries: https://github.com/MichaIng/DietPi/issues/2529
# As well allow ".bash" file ending and remove obsolete dietpi-*.sh scripts: https://github.com/MichaIng/DietPi/pull/2636
G_EXEC sed -i '\#for i in /etc/bashrc#d' /etc/bash.bashrc
# shellcheck disable=SC2016
G_CONFIG_INJECT '.*/etc/bashrc\.d/.*' 'for i in /etc/bashrc.d/*.sh /etc/bashrc.d/*.bash; do [ -r "$i" ] && . $i; done' /etc/bash.bashrc
G_EXEC rm -f /etc/bashrc.d/dietpi-*.sh
#-------------------------------------------------------------------------------
# Mopidy fix: https://github.com/MichaIng/DietPi/issues/2536
getent passwd mopidy > /dev/null && G_EXEC usermod -aG dietpi,audio -d /mnt/dietpi_userdata/mopidy mopidy
#-------------------------------------------------------------------------------
# Removed dependency on "p7zip-full", use "7zr" (p7zip) instead: https://github.com/MichaIng/DietPi/pull/2559
G_AGI p7zip
if dpkg-query -s p7zip-full &> /dev/null &&
! G_WHIP_BUTTON_OK_TEXT='Yes' G_WHIP_BUTTON_CANCEL_TEXT='No' G_WHIP_YESNO '[QUESTION] Do you want to keep "p7zip-full"?\n
DietPi does not require the "p7zip-full" package anymore but just "p7zip" instead.
- "p7zip" provides the lightweight standalone "7zr" command to handle 7zip archives only.
- "p7zip-full" additionally provides the "7z" and "7za" commands which can handle other archive types as well.
However, DietPi internally uses "unzip", "tar" and "unrar" to handle those.\n
Do you still want to keep "p7zip-full"?'; then
apt-mark auto p7zip-full
G_AGA
fi
#-------------------------------------------------------------------------------
# Fix Pi-hole permissions to allow "pihole -up"
if [[ -d '/var/www/html/pihole' && -d '/var/www/html/admin' ]]; then
G_EXEC cd /var/www/html/admin
git reset --hard HEAD
G_EXEC cd "$G_WORKING_DIR"
fi
#-------------------------------------------------------------------------------
# MPD: Fix permissions issue: https://github.com/MichaIng/DietPi/issues/2462
if [[ -f '/etc/mpd.conf' ]]; then
G_EXEC sed -Ei '/^(user|group)[[:blank:]]/d' /etc/mpd.conf
G_EXEC sed -i '/^Group=/d' /lib/systemd/system/mpd.service
G_CONFIG_INJECT 'User=' 'User=mpd' /lib/systemd/system/mpd.service '\[Service\]'
G_CONFIG_INJECT 'PermissionsStartOnly=' 'PermissionsStartOnly=true' /lib/systemd/system/mpd.service '^User=mpd'
getent passwd mpd > /dev/null && G_EXEC usermod -aG audio,dietpi mpd
fi
#-------------------------------------------------------------------------------
# Fix rc-local.service from old images to match new systemd-rc-local-generator: https://github.com/MichaIng/DietPi/issues/2566
systemctl disable rc-local rc.local
grep -q 'dietpi' /lib/systemd/system/rc-local.service && cat << '_EOF_' > /lib/systemd/system/rc-local.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
_EOF_
#-------------------------------------------------------------------------------
# Remove obsolete DietPi-Sync log: https://github.com/MichaIng/DietPi/pull/2606
[[ -f '/var/log/dietpi-sync.log' ]] && rm /var/log/dietpi-sync.log
#-------------------------------------------------------------------------------
# XU4, use Meveric's xorg.conf which detects 3.x and 4.x kernel configuration requirements:
if [[ $G_HW_MODEL == 11 && -f '/etc/X11/xorg.conf' ]]; then
G_EXEC rm /etc/X11/xorg.conf
G_AGI --reinstall firmware-samsung xf86-video-armsoc-odroid malit628-odroid
fi
#-------------------------------------------------------------------------------
# RPi | Remove "framebuffer_depth" handling: https://github.com/MichaIng/DietPi/pull/2635
(( $G_HW_MODEL < 10 )) && G_EXEC sed -i '/framebuffer_depth/d' /boot/config.txt
#-------------------------------------------------------------------------------
# Nextcloud: Add OCM/OCS provider redirects as this is checked and printed as warning on admin panel: https://github.com/MichaIng/DietPi/issues/2638
if [[ -f '/etc/apache2/sites-available/dietpi-nextcloud.conf' ]] &&
! grep -q 'oc[ms]-provider' /etc/apache2/sites-available/dietpi-nextcloud.conf; then
echo 'Redirect permanent /ocm-provider /nextcloud/ocm-provider
Redirect permanent /ocs-provider /nextcloud/ocs-provider' >> /etc/apache2/sites-available/dietpi-nextcloud.conf
fi
if [[ -f '/etc/lighttpd/conf-available/99-dietpi-nextcloud.conf' ]] &&
! grep -q 'oc[ms]-provider' /etc/lighttpd/conf-available/99-dietpi-nextcloud.conf; then
echo 'url.redirect += (
"^/ocm-provider" => "/nextcloud/ocm-provider",
"^/ocs-provider" => "/nextcloud/ocs-provider"
)' >> /etc/lighttpd/conf-available/99-dietpi-nextcloud.conf
fi
if [[ -f '/etc/nginx/sites-dietpi/dietpi-nextcloud.conf' ]] && ! grep -q 'oc[ms]-provider' /etc/nginx/sites-dietpi/dietpi-nextcloud.conf; then
# shellcheck disable=SC2016
echo 'location ~ ^\/(?:ocm-provider|ocs-provider).* {
rewrite ^ /nextcloud$request_uri;
}' >> /etc/nginx/sites-dietpi/dietpi-nextcloud.conf
fi
#-------------------------------------------------------------------------------
# Reinstalls
# v6.33 Amiberry 2.25: https://github.com/MichaIng/DietPi/issues/2599
# v6.27 Allo GUI v13: https://github.com/sparky-sbc/sparky-test/tree/master/dietpi-gui-usbdebug
# Deluge: Patch according to installer rework: https://github.com/MichaIng/DietPi/pull/2594
# rTorrent: https://github.com/MichaIng/DietPi/issues/2629
if (( $G_DIETPI_INSTALL_STAGE == 2 )); then
local reinstall_indices=
if [[ -f '/root/.rtorrent.rc' ]] && grep -q '^aSOFTWARE_INSTALL_STATE\[107\]=2' /boot/dietpi/.installed; then
reinstall_indices+=' 107'
G_CONFIG_INJECT 'system.umask.set[[:blank:]=]' 'system.umask.set = 002' /root/.rtorrent.rc
G_EXEC mkdir -p /mnt/dietpi_userdata/rtorrent
G_EXEC mv /root/.rtorrent.rc /mnt/dietpi_userdata/rtorrent/
fi
if grep -q '^aSOFTWARE_INSTALL_STATE\[45\]=2' /boot/dietpi/.installed && getent passwd deluge > /dev/null; then # Only do this once, regardless of re-patches
reinstall_indices+=' 45'
G_AGP deluge-webui
G_EXEC mkdir -p /var/log/deluged /mnt/dietpi_userdata
[[ -e ~deluge ]] && G_EXEC mv ~deluge /mnt/dietpi_userdata/deluge_home_backup
G_EXEC userdel -rf deluge
G_EXEC rm -Rf /{root,home/*}/.config/deluge
[[ -f '/var/log/deluged.log' ]] && G_EXEC mv /var/log/deluged.log /var/log/deluged/daemon.log
[[ -f '/var/log/deluge-web.log' ]] && G_EXEC mv /var/log/deluge-web.log /var/log/deluged/web.log
G_WHIP_MSG '[ INFO ] Deluge rework\n
Our Deluge installer has been reworked to match Debian APT package defaults and official documentations. This also resolves an issue when attempting to access "deluge-console".
- It runs now as user "debian-deluged".
- The user "deluge" has been removed, its home directory has been backed up to:
/mnt/dietpi_userdata/deluge_home_backup
in case it existed.
- Logs have been moved to /var/log/deluged/daemon.log|web.log.
- Apart from that, all your settings and data have been preserved.\n
NB: When accessing "deluge-console" you need to do that as user "debian-deluged":
sudo -u debian-deluged deluge-console'
fi
echo "$reinstall_indices" >> /var/tmp/dietpi/dietpi-update_reinstalls
fi
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 22 )); then
#-------------------------------------------------------------------------------
# Apply Serial/UART rework: https://github.com/MichaIng/DietPi/pull/2678
# - Cleanup: Remove serial-getty masks for all non-existent serial devices
for i in /etc/systemd/system/serial-getty@tty{S,AMA,SAC}[0-9].service
do
[[ -L $i && $(readlink "$i") == '/dev/null' ]] || continue
local tty=${i##*serial-getty@}
tty=${tty%.service}
[[ -e /dev/$tty ]] || systemctl unmask "serial-getty@$tty"
done
# - Fix: Disable serial-getty instances for all non-existent serial devices
for i in /etc/systemd/system/getty.target.wants/serial-getty@tty{S,AMA,SAC}[0-9].service
do
[[ -L $i ]] || continue
local tty=${i##*serial-getty@}
tty=${tty%.service}
[[ -e /dev/$tty ]] || systemctl disable "serial-getty@$tty"
done
#-------------------------------------------------------------------------------
# Patch proxy settings changes: https://github.com/MichaIng/DietPi/pull/2716
sed -i '/^[[:blank:]]*CONFIG_PROXY_ENABLED=/d' /boot/dietpi.txt
local proxy=''
if proxy=$(grep '^[[:blank:]]*export {http,https,ftp}_proxy=' /etc/bash.bashrc); then
[[ -f '/etc/bashrc.d/dietpi-proxy.sh' ]] || echo "$proxy" > /etc/bashrc.d/dietpi-proxy.sh
G_EXEC sed -i '/^[[:blank:]]*export {http,https,ftp}_proxy=/d' /etc/bash.bashrc
fi
#-------------------------------------------------------------------------------
# dietpi-set_dphys-swapfile renamed to: "dietpi-set_swapfile": https://github.com/MichaIng/DietPi/pull/2720
[[ -f '/boot/dietpi/func/dietpi-set_dphys-swapfile' ]] && rm /boot/dietpi/func/dietpi-set_dphys-swapfile
#-------------------------------------------------------------------------------
# Remove obsolete OpenJDK APT preferences on Jessie: https://github.com/MichaIng/DietPi/pull/2753
[[ -f '/etc/apt/preferences.d/99-dietpi-openjdk-8-jdk' ]] && rm /etc/apt/preferences.d/99-dietpi-openjdk-8-jdk
#-------------------------------------------------------------------------------
if (( $G_DIETPI_INSTALL_STAGE == 2 )); then
# Infom Sonarr/Radarr/Lidarr users about DietPi-Arr_to_RAM: https://github.com/MichaIng/DietPi/pull/2698
grep -qE '^aSOFTWARE_INSTALL_STATE\[(106|144|145)\]=2' /boot/dietpi/.installed && G_WHIP_MSG 'DietPi-Arr_to_RAM | Link Sonarr/Radarr/Lidarr database files to RAM\n
With v6.18 we silently added a new script that allows linking Sonarr/Radarr/Lidarr database files to RAM, increasing access performance, reducing disk I/O and avoiding constant external HDD spinning due to the very regular access to these files.\n
This script has gone through some rework and polishing with v6.23 and can now be enabled to automatically link those databases to RAM on boot and store them back to disk on shutdown.\n
Further info and usage: https://dietpi.com/forum/t/dietpi-arr-to-ram-link-sonarr-radarr-lidarr-database-files-to-ram/3120'
#-----------------------------------------------------------------------
# Fix IPv6 connections with WireGuard: https://github.com/MichaIng/DietPi/issues/2691
if [[ -f '/etc/wireguard/wg0.conf' ]] && ! grep -q 'sysctl' /etc/wireguard/wg0.conf; then
[[ -f '/etc/sysctl.d/dietpi-wireguard.conf' ]] && G_EXEC rm /etc/sysctl.d/dietpi-wireguard.conf
sed -i "/^ListenPort/a\PostUp = sysctl net.ipv4.conf.%i.forwarding=1 net.ipv4.conf.\$(ip r l 0/0 | mawk '{print \$5;exit}').forwarding=1" /etc/wireguard/wg0.conf
sed -i "/^ListenPort/a\PostUp = sysctl net.ipv6.conf.\$(ip r l 0/0 | mawk '{print \$5;exit}').accept_ra=2" /etc/wireguard/wg0.conf
sed -i "/^ListenPort/a\PostUp = sysctl net.ipv6.conf.%i.forwarding=1 net.ipv6.conf.\$(ip r l 0/0 | mawk '{print \$5;exit}').forwarding=1" /etc/wireguard/wg0.conf
sed -i "/^ListenPort/a\PostUp = ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o \$(ip r l 0/0 | mawk '{print \$5;exit}') -j MASQUERADE" /etc/wireguard/wg0.conf
sed -i "/^ListenPort/a\PostDown = ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o \$(ip r l 0/0 | mawk '{print \$5;exit}') -j MASQUERADE" /etc/wireguard/wg0.conf
fi
#-----------------------------------------------------------------------
# NordVPN: Tiny fix for doubled auth-user-pass entry: https://github.com/MichaIng/DietPi/commit/847a016638c6929153dc16e7ce054d3dce5e4c60
if [[ -f '/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_dietpi.conf' ]]; then
local PROTOCOL NORDVPN_SERVER
# shellcheck disable=SC1091
. /var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_dietpi.conf
if [[ -f /etc/openvpn/ovpn_$PROTOCOL/$NORDVPN_SERVER && $(grep -c '^auth-user-pass' "/etc/openvpn/ovpn_$PROTOCOL/$NORDVPN_SERVER") == 2 ]]; then
sed -i '/^auth-user-pass$/d' "/etc/openvpn/ovpn_$PROTOCOL/$NORDVPN_SERVER"
fi
unset -v NORDVPN_USERNAME NORDVPN_PASSWORD NORDVPN_SERVER PROTOCOL
fi
#-----------------------------------------------------------------------
# Remove obsolete "bluetooth" meta package and mark bluez instead
if dpkg-query -s bluetooth &> /dev/null; then
apt-mark manual bluez
apt-mark auto bluetooth
G_AGA
fi
#-----------------------------------------------------------------------
# Add /etc/network/interfaces.d/ drop-in config support
grep -q 'interfaces\.d' /etc/network/interfaces || sed -i '1i\source interfaces.d/*' /etc/network/interfaces
#-----------------------------------------------------------------------
# Blynk: Fix logging and move to RAMlog: https://github.com/MichaIng/DietPi/pull/2779
if [[ -f '/etc/systemd/system/blynkserver.service' && -f '/mnt/dietpi_userdata/blynk/server.properties' ]]; then
G_CONFIG_INJECT 'WorkingDirectory=' 'WorkingDirectory=/mnt/dietpi_userdata/blynk' /etc/systemd/system/blynkserver.service '\[Service\]'
G_EXEC mkdir -p /var/log/blynk
G_EXEC chown -R blynk:dietpi /var/log/blynk
G_CONFIG_INJECT 'logs.folder=' 'logs.folder=/var/log/blynk' /mnt/dietpi_userdata/blynk/server.properties
fi
#-----------------------------------------------------------------------
# PHP7.3 migration: https://github.com/MichaIng/DietPi/issues/2367
# - Only upgrade versions lower than 7.2 and skip any check version Buster+ where this is impossible
if (( $G_DISTRO < 5 )) && grep -q '^aSOFTWARE_INSTALL_STATE\[89\]=2' /boot/dietpi/.installed && ! command -v php7.{2,3} > /dev/null; then
echo 89 >> /var/tmp/dietpi/dietpi-update_reinstalls
# Software which does not support PHP7.3, install PHP7.2 instead
local PHP_NAME='php7.3'
# - ownCloud up to v10.2
if [[ -f '/var/www/owncloud/version.php' ]]; then
# shellcheck disable=SC2016
local oc_version_major=$(sed -n '/$OC_VersionString/{s/^[^0-9]*//;s/\..*$//;p;q}' /var/www/owncloud/version.php)
# shellcheck disable=SC2016
local oc_version_minor=$(sed -n '/$OC_VersionString/{s/^[^.]*\.//;s/\..*$//;p;q}' /var/www/owncloud/version.php)
(( $oc_version_major < 10 || ( $oc_version_major == 10 && oc_version_minor < 3 ) )) && PHP_NAME='php7.2'
fi
G_WHIP_MSG "[ INFO ] PHP upgrade\n
Your PHP instance will be upgraded to ${PHP_NAME^^}. This enhances security and performance of your web applications and is required to run some of the latest web application versions, e.g. Nextcloud 17, ownCloud 10.3, phpBB 3.3 and others.\n
We will update webserver configurations and backup the whole /etc/php directory to /etc/php_bak, so you can recover custom settings.\n
NB: For any custom PHP-dependent web applications, which you have installed manually (outside of DietPi-Software), you might need to adjust the used socket to: /run/php/$PHP_NAME-fpm.sock
NBB: Reinstall manually installed PHP modules via: G_AGI $PHP_NAME-<mod_name>"
# Backup config
[[ -d '/etc/php' ]] && G_EXEC cp -a /etc/php{,_bak}
# Update PHP socket
# - Lighttpd
[[ -f '/etc/lighttpd/conf-available/15-fastcgi-php.conf' ]] && sed -i "s@\"socket\".*\$@\"socket\" => \"/run/php/$PHP_NAME-fpm.sock\",@" /etc/lighttpd/conf-available/15-fastcgi-php.conf
# - Nginx
[[ -f '/etc/nginx/nginx.conf' ]] && sed -i "s#/run/php.*-fpm.sock#/run/php/$PHP_NAME-fpm.sock#g" /etc/nginx/nginx.conf
# Mark old PHP packages for autoremoval
local apackages=()
mapfile -t apackages < <(dpkg --get-selections 'php7.[01]-*' 'libapache2-mod-php7.[01]' 2> /dev/null | mawk '{print $1}')
apt-mark auto "${apackages[@]}" 2> /dev/null
unset -v apackages
# Disable old mod-php so that new version is enabled automatically on package install
command -v a2dismod > /dev/null && a2dismod php7.{0,1} 2> /dev/null
fi
#-----------------------------------------------------------------------
# Reinstalls
# Subsonic: https://github.com/MichaIng/DietPi/pull/2705
[[ -L '/var/subsonic/transcode' ]] && rm /var/subsonic/transcode
# Plex Media Server: https://github.com/MichaIng/DietPi/pull/2722
dpkg-query -s plexmediaserver-installer &> /dev/null && dpkg -r plexmediaserver-installer
# Logitech Media Server: https://github.com/MichaIng/DietPi/commit/eccef6700381c3f044ec4d435beb167736db0bb4
if [[ -f '/etc/systemd/system/squeezeboxserver.service' ]]; then
systemctl disable --now squeezeboxserver
mv /etc/systemd/system/squeezeboxserver.service /etc/systemd/system/logitechmediaserver.service
fi
[[ -d '/etc/systemd/system/squeezeboxserver.service.d' ]] && mv /etc/systemd/system/squeezeboxserver.service.d /etc/systemd/system/logitechmediaserver.service.d
# SABnzbd: https://github.com/MichaIng/DietPi/pull/2768
# v6.27 Jackett: https://github.com/MichaIng/DietPi/pull/2773
if [[ -d '/opt/jackett/.config' ]]; then
G_EXEC cp -a /opt/jackett/.config/. /opt/jackett/
G_EXEC rm -R /opt/jackett/.config
fi
echo 34 35 42 47 48 114 139 >> /var/tmp/dietpi/dietpi-update_reinstalls
fi
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 23 )); then
#-------------------------------------------------------------------------------
# Add Plex and Emby users to dietpi group to grant media and network mount access
getent passwd emby > /dev/null && usermod -aG dietpi emby
getent passwd plex > /dev/null && usermod -aG dietpi plex
#-------------------------------------------------------------------------------
# Patch Lighttpd config file on ARMv6 (Buster version installed): https://github.com/MichaIng/DietPi/issues/2808
if [[ -f '/etc/lighttpd/lighttpd.conf' && ! -f '/usr/share/lighttpd/create-mime.assign.pl' && -f '/usr/share/lighttpd/create-mime.conf.pl' ]]; then
sed -i 's|/usr/share/lighttpd/create-mime\.assign\.pl|/usr/share/lighttpd/create-mime.conf.pl|g' /etc/lighttpd/lighttpd.conf
fi
#-------------------------------------------------------------------------------
# Restart DietPi-WiFi-Monitor to apply fixed script now: https://github.com/MichaIng/DietPi/issues/2802
systemctl -q is-active dietpi-wifi-monitor && systemctl restart dietpi-wifi-monitor
#-------------------------------------------------------------------------------
elif (( $G_DIETPI_VERSION_SUB == 24 )); then
#-------------------------------------------------------------------------------
# DietPi-Services 2.0
rm -f /boot/dietpi/{,.}dietpi-process_tool
if [[ -f '/usr/share/applications/dietpi-process_tool.desktop' ]]; then
G_EXEC rm /usr/share/applications/dietpi-process_tool.desktop
G_EXEC curl -sSfL "https://github.com/$G_GITOWNER/DietPi/raw/$G_GITBRANCH/.conf/desktop/apps/dietpi-services.desktop" -o /usr/share/applications/dietpi-services.desktop
G_EXEC chmod +x /usr/share/applications/dietpi-services.desktop
fi
#-------------------------------------------------------------------------------
# Disable APT cache by default (leaves package download dir at disk by default)
if [[ ! -f '/etc/apt/apt.conf.d/99-dietpi-cache' ]]; then
G_WHIP_MSG '[ INFO ] Disabling APT cache\n
We added new options to "dietpi-config" > "Advanced Options" > "APT Cache" to disable the APT cache or move cache, repo lists and/or package download dir to RAM.\n
By default we disable the APT cache, which saves 50 - 100 MiB disk writes on each "apt-get update" call, but slows down "apt-cache" calls.\n
Use "dietpi-config" to adjust these settings to your needs.'
/boot/dietpi/func/dietpi-set_software apt-cache cache disable
fi
#-------------------------------------------------------------------------------
# FFmpeg on RPi: Failsafe reinstall new APT package and mark priorly required libraries as auto + autoremove
if (( $G_HW_MODEL < 10 )) && command -v ffmpeg > /dev/null; then
[[ $(ffmpeg -version 2> /dev/null | sed -n '1{s/[^0-9]//g;p}') == 32* ]] && G_AGI --reinstall ffmpeg
apt-mark auto libx264 libmp3lame libfdk-aac
G_AGA
fi