forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PREP_SYSTEM_FOR_DIETPI.sh
1857 lines (1380 loc) · 68.8 KB
/
PREP_SYSTEM_FOR_DIETPI.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
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
{
#------------------------------------------------------------------------------------------------
# Optimise current Debian install and prepare for DietPi installation
#------------------------------------------------------------------------------------------------
# REQUIREMENTS
# - Currently running Debian Stretch or above, ideally minimal, eg: Raspbian Lite-ish =))
# - systemd as system/init/service manager
# - Either Ethernet connection or local (non-SSH) terminal access
#------------------------------------------------------------------------------------------------
# Dev notes:
# Following items must be exported or assigned to DietPi scripts, if used, until dietpi-obtain_hw_model is executed:
# - G_HW_MODEL
# - G_HW_ARCH
# - G_DISTRO
# - G_DISTRO_NAME
# - G_RASPBIAN
#
# The following environment variables can be set to automate this script (adjust example values to your needs):
# - GITOWNER='MichaIng' (optional, defaults to 'MichaIng')
# - GITBRANCH='master' (must be one of 'master', 'beta' or 'dev')
# - IMAGE_CREATOR='Mr. Tux'
# - PREIMAGE_INFO='Some GNU/Linux'
# - HW_MODEL=0 (must match one of the supported IDs below)
# - WIFI_REQUIRED=0 [01]
# - DISTRO_TARGET=5 [456] (Stretch: 4, Buster: 5, Bullseye: 6)
#------------------------------------------------------------------------------------------------
# Core globals
G_PROGRAM_NAME='DietPi-PREP'
#------------------------------------------------------------------------------------------------
# Critical checks and requirements to run this script
#------------------------------------------------------------------------------------------------
# Exit path for non-root executions
if (( $UID )); then
echo -e '[FAILED] Root privileges required, please run this script with "sudo"\nIn case install the "sudo" package with root privileges:\n\t# apt install sudo\n'
exit 1
fi
# Set $PATH variable to include all expected default binary locations, since we don't know the current system setup: https://github.com/MichaIng/DietPi/issues/3206
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
# Make /tmp a tmpfs if it is not yet a dedicated mount
findmnt /tmp > /dev/null || mount -t tmpfs none /tmp
# Work inside /tmp tmpfs to reduce disk I/O and speed up download and unpacking
# - Save full script path beforehand: https://github.com/MichaIng/DietPi/pull/2341#discussion_r241784962
FP_PREP_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cd /tmp || exit 1
# APT pre-configuration
# - Remove unwanted APT configs
# RPi: Allow PDiffs since the "slow implementation" argument is outdated and PDiffs allow lower download size and less disk I/O
[[ -f '/etc/apt/apt.conf.d/50raspi' ]] && rm -v /etc/apt/apt.conf.d/50raspi
# Meveric: https://github.com/MichaIng/DietPi/issues/1285#issuecomment-355759321
[[ -f '/etc/apt/sources.list.d/deb-multimedia.list' ]] && rm -v /etc/apt/sources.list.d/deb-multimedia.list
[[ -f '/etc/apt/preferences.d/deb-multimedia-pin-99' ]] && rm -v /etc/apt/preferences.d/deb-multimedia-pin-99
[[ -f '/etc/apt/preferences.d/backports' ]] && rm -v /etc/apt/preferences.d/backports
# OMV: https://dietpi.com/phpbb/viewtopic.php?f=11&t=2772
[[ -f '/etc/apt/sources.list.d/openmediavault.list' ]] && rm -v /etc/apt/sources.list.d/openmediavault.list
# Conflicting configs
rm -fv /etc/apt/apt.conf.d/*{recommends,armbian}*
# - Apply wanted APT configs: Overwritten by DietPi code archive
cat << _EOF_ > /etc/apt/apt.conf.d/97dietpi # https://raw.githubusercontent.com/MichaIng/DietPi/dev/rootfs/etc/apt/apt.conf.d/97dietpi
APT::Install-Recommends "false";
APT::Install-Suggests "false";
APT::AutoRemove::RecommendsImportant "false";
APT::AutoRemove::SuggestsImportant "false";
Acquire::Languages "none";
Dir::Cache::srcpkgcache "";
Acquire::GzipIndexes "true";
Acquire::IndexTargets::deb::Packages::KeepCompressedAs "xz";
Acquire::IndexTargets::deb::Translations::KeepCompressedAs "xz";
Acquire::IndexTargets::deb-src::Sources::KeepCompressedAs "xz";
_EOF_
# - Forcing new DEB package config files (during PREP only)
echo -e '#clear DPkg::options;\nDPkg::options:: "--force-confmiss,confnew";' > /etc/apt/apt.conf.d/98dietpi-forceconf
# - Prefer IPv4 by default to avoid hanging access attempts in some cases
# NB: This needs to match the method in: /DietPi/dietpi/func/dietpi-set_hardware preferipv4 enable
echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99-dietpi-force-ipv4
apt-get clean
apt-get update
# Check for/Install DEB packages required for this script to:
aAPT_PREREQS=(
'curl' # Download DietPi-Globals...
'ca-certificates' # ...via HTTPS
'locales' # Set C.UTF-8 locale
'whiptail' # G_WHIP
)
# - Pre-Buster: Support HTTPS sources for APT
grep -q 'stretch' /etc/os-release && aAPT_PREREQS+=('apt-transport-https')
for i in "${aAPT_PREREQS[@]}"
do
if ! dpkg-query -s "$i" &> /dev/null && ! apt-get -y install "$i"; then
echo -e "[FAILED] Unable to install $i, please try to install it manually:\n\t # apt install $i\n"
exit 1
fi
done
unset -v aAPT_PREREQS
# Wget: Prefer IPv4 by default to avoid hanging access attempts in some cases
# - NB: This needs to match the method in: /boot/dietpi/func/dietpi-set_hardware preferipv4 enable
if grep -q '^[[:blank:]]*prefer-family[[:blank:]]*=' /etc/wgetrc; then
sed -i '/^[[:blank:]]*prefer-family[[:blank:]]*=/c\prefer-family = IPv4' /etc/wgetrc
elif grep -q '^[[:blank:]#;]*prefer-family[[:blank:]]*=' /etc/wgetrc; then
sed -i '/^[[:blank:]#;]*prefer-family[[:blank:]]*=/c\prefer-family = IPv4' /etc/wgetrc
else
echo 'prefer-family = IPv4' >> /etc/wgetrc
fi
# Setup locale
# - Remove existing settings that could break dpkg-reconfigure locales
> /etc/environment
[[ -f '/etc/default/locale' ]] && rm /etc/default/locale
# - NB: DEV, any changes here must be also rolled into function '/boot/dietpi/func/dietpi-set_software locale', for future script use
echo 'C.UTF-8 UTF-8' > /etc/locale.gen
# - dpkg-reconfigure includes:
# - "locale-gen": Generate locale(s) based on "/etc/locale.gen" or interactive selection.
# - "update-locale": Add $LANG to "/etc/default/locale" based on generated locale(s) or interactive default language selection.
if ! dpkg-reconfigure -f noninteractive locales; then
echo -e '[FAILED] Locale generation failed. Aborting...\n'
exit 1
fi
# - Export locale vars to assure the following whiptail being beautiful
export LC_ALL='C.UTF-8' LANG='C.UTF-8'
# - Update /etc/default/locales with new values (not effective until next load of bash session, eg: logout/in)
update-locale 'LC_ALL=C.UTF-8'
# Set Git owner
GITOWNER=${GITOWNER:-MichaIng}
# Select Git branch
if ! [[ $GITBRANCH =~ ^(master|beta|dev)$ ]]; then
aWHIP_BRANCH=(
'master' ': Stable release branch (recommended)'
'beta' ': Public beta testing branch'
'dev' ': Unstable development branch'
)
if ! GITBRANCH=$(whiptail --title "$G_PROGRAM_NAME" --menu 'Please select the Git branch the installer should use:' --default-item 'master' --ok-button 'Ok' --cancel-button 'Exit' --backtitle "$G_PROGRAM_NAME" 12 80 3 "${aWHIP_BRANCH[@]}" 3>&1 1>&2 2>&3-); then
echo -e '[ INFO ] No choice detected. Aborting...\n'
exit 0
fi
unset -v aWHIP_BRANCH
fi
echo "[ INFO ] Selected Git branch: $GITOWNER/$GITBRANCH"
#------------------------------------------------------------------------------------------------
# DietPi-Globals
#------------------------------------------------------------------------------------------------
# NB: We have to manually handle errors, until DietPi-Globals are successfully loaded.
# Download
if ! curl -sSfL "https://raw.githubusercontent.com/$GITOWNER/DietPi/$GITBRANCH/dietpi/func/dietpi-globals" -o dietpi-globals; then
echo -e '[FAILED] Unable to download dietpi-globals. Aborting...\n'
exit 1
fi
# Assure no obsolete .hw_model is loaded
rm -fv /boot/dietpi/.hw_model
# Load
if ! . ./dietpi-globals; then
echo -e '[FAILED] Unable to load dietpi-globals. Aborting...\n'
exit 1
fi
rm dietpi-globals
# Reset G_PROGRAM_NAME, which was set to empty string by sourcing dietpi-globals
readonly G_PROGRAM_NAME='DietPi-PREP'
G_INIT
# Apply Git info
G_GITOWNER=$GITOWNER
G_GITBRANCH=$GITBRANCH
unset -v GITOWNER GITBRANCH
# Detect the Debian version of this operating system
if grep -q 'stretch' /etc/os-release; then
G_DISTRO=4
G_DISTRO_NAME='stretch'
elif grep -q 'buster' /etc/os-release; then
G_DISTRO=5
G_DISTRO_NAME='buster'
elif grep -q 'bullseye' /etc/os-release; then
G_DISTRO=6
G_DISTRO_NAME='bullseye'
else
G_DIETPI-NOTIFY 1 "Unknown or unsupported distribution version: $(sed -n '/^PRETTY_NAME=/{s/^PRETTY_NAME=//p;q}' /etc/os-release 2>&1). Aborting...\n"
exit 1
fi
# Detect the hardware architecture of this operating system
G_HW_ARCH_NAME=$(uname -m)
if [[ $G_HW_ARCH_NAME == 'armv6l' ]]; then
G_HW_ARCH=1
elif [[ $G_HW_ARCH_NAME == 'armv7l' ]]; then
G_HW_ARCH=2
elif [[ $G_HW_ARCH_NAME == 'aarch64' ]]; then
G_HW_ARCH=3
elif [[ $G_HW_ARCH_NAME == 'x86_64' ]]; then
G_HW_ARCH=10
else
G_DIETPI-NOTIFY 1 "Unknown or unsupported CPU architecture: \"$G_HW_ARCH_NAME\". Aborting...\n"
exit 1
fi
Main(){
#------------------------------------------------------------------------------------------------
# Init setup step headers
SETUP_STEP=0
readonly G_NOTIFY_3_MODE='Step'
G_DIETPI-NOTIFY 3 "[$SETUP_STEP] Detecting existing DietPi system"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------
if [[ -d '/DietPi' || -d '/boot/dietpi' ]]; then
G_DIETPI-NOTIFY 2 'DietPi system found, uninstalling old instance...'
# Stop services: RAMdisk includes (Pre|Post)Boot due to dependencies
[[ -f '/boot/dietpi/dietpi-services' ]] && /boot/dietpi/dietpi-services stop
[[ -f '/etc/systemd/system/dietpi-ramlog.service' ]] && systemctl stop dietpi-ramlog
[[ -f '/etc/systemd/system/dietpi-ramdisk.service' ]] && systemctl stop dietpi-ramdisk
# Disable DietPi services
for i in /etc/systemd/system/dietpi-*
do
[[ -f $i ]] && systemctl disable --now "${i##*/}"
rm -Rfv "$i"
done
# Delete any previous existing data
# - /DietPi mount point: Pre-v6.29
findmnt /DietPi > /dev/null && umount -R /DietPi
[[ -d '/DietPi' ]] && rm -R /DietPi
rm -Rfv /{boot,mnt,etc,var/lib,var/tmp,run}/*dietpi*
rm -fv /etc{,/cron.*,/{bashrc,profile,sysctl,network/if-up,udev/rules}.d}/{,.}*dietpi*
rm -fv /etc/apt/apt.conf.d/{99-dietpi-norecommends,98-dietpi-no_translations,99-dietpi-forceconf} # Pre-v6.32
[[ -f '/root/DietPi-Automation.log' ]] && rm -v /root/DietPi-Automation.log
[[ -f '/boot/Automation_Format_My_Usb_Drive' ]] && rm -v /boot/Automation_Format_My_Usb_Drive
else
G_DIETPI-NOTIFY 2 'No DietPi system found, skipping old instance uninstall...'
fi
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "[$SETUP_STEP] Target system inputs"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------
# Image creator
while :
do
if [[ $IMAGE_CREATOR ]]; then
G_WHIP_RETURNED_VALUE=$IMAGE_CREATOR
# unset to force interactive input if disallowed name is detected
unset -v IMAGE_CREATOR
else
G_WHIP_INPUTBOX 'Please enter your name. This will be used to identify the image creator within credits banner.\n\nYou can add your contact information as well for end users.\n\nNB: An entry is required.'
fi
if [[ $G_WHIP_RETURNED_VALUE ]]; then
# Disallowed?
DISALLOWED_NAME=0
aDISALLOWED_NAMES=(
'official'
'fourdee'
'daniel knight'
'dan knight'
'michaing'
'diet'
)
for i in "${aDISALLOWED_NAMES[@]}"
do
[[ ${G_WHIP_RETURNED_VALUE,,} =~ $i ]] || continue
DISALLOWED_NAME=1
break
done
unset -v aDISALLOWED_NAMES
if (( $DISALLOWED_NAME )); then
G_WHIP_MSG "\"$G_WHIP_RETURNED_VALUE\" is reserved and cannot be used. Please try again."
else
IMAGE_CREATOR=$G_WHIP_RETURNED_VALUE
break
fi
fi
done
G_DIETPI-NOTIFY 2 "Entered image creator: $IMAGE_CREATOR"
# Pre-image used/name
until [[ $PREIMAGE_INFO ]]
do
G_WHIP_INPUTBOX 'Please enter the name or URL of the pre-image you installed on this system, prior to running this script. This will be used to identify the pre-image credits.\n\nEG: Debian, Raspbian Lite, Meveric, FriendlyARM, or "forum.odroid.com/viewtopic.php?f=ABC&t=XYZ" etc.\n\nNB: An entry is required.'
PREIMAGE_INFO=$G_WHIP_RETURNED_VALUE
done
G_DIETPI-NOTIFY 2 "Entered pre-image info: $PREIMAGE_INFO"
# Hardware selection
# - NB: PLEASE ENSURE HW_MODEL INDEX ENTRIES MATCH dietpi-obtain_hw_model and dietpi-survey_report
# - NBB: DO NOT REORDER INDICES. These are now fixed and will never change (due to survey results etc)
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
G_WHIP_DEFAULT_ITEM=0
G_WHIP_MENU_ARRAY=(
'' '●─ ARM ─ Core devices with GPU support '
'0' ': Raspberry Pi (All models)'
#'0' ': Raspberry Pi 1 (256 MiB)
#'1' ': Raspberry Pi 1/Zero (512 MiB)'
#'2' ': Raspberry Pi 2'
#'3' ': Raspberry Pi 3/3+'
#'4' ': Raspberry Pi 4'
'11' ': Odroid XU3/XU4/MC1/HC1/HC2'
'12' ': Odroid C2'
'15' ': Odroid N2'
'16' ': Odroid C4'
'44' ': Pinebook'
'' '●─ x86_64 '
'21' ': x86_64 Native PC'
'20' ': x86_64 Virtual Machine'
'' '●─ ARM ─ Limited support devices without GPU support '
'10' ': Odroid C1'
'13' ': Odroid U3'
'14' ': Odroid N1'
'70' ': Sparky SBC'
'52' ': ASUS Tinker Board'
'40' ': PINE A64'
'43' ': ROCK64'
'42' ': ROCKPro64'
'45' ': PINE H64'
'59' ': ZeroPi'
'60' ': NanoPi NEO'
'65' ': NanoPi NEO2'
'56' ': NanoPi NEO3'
'57' ': NanoPi NEO Plus2'
'64' ': NanoPi NEO Air'
'63' ': NanoPi M1/T1'
'66' ': NanoPi M1 Plus'
'67' ': NanoPi K1 Plus'
'61' ': NanoPi M2/T2'
'62' ': NanoPi M3/T3/Fire3'
'68' ': NanoPi M4/T4/NEO4'
'58' ': NanoPi M4V2'
'55' ': NanoPi R2S'
'54' ': NanoPi K2'
'72' ': ROCK Pi 4'
'73' ': ROCK Pi S'
'69' ': Firefly RK3399'
'38' ': OrangePi PC 2'
'37' ': OrangePi Prime'
'36' ': OrangePi Win'
'35' ': OrangePi Zero Plus 2 (H3/H5)'
'34' ': OrangePi Plus'
'33' ': OrangePi Lite'
'32' ': OrangePi Zero (H2+)'
'31' ': OrangePi One'
'30' ': OrangePi PC'
'41' ': OrangePi PC Plus'
'53' ': BananaPi (sinovoip)'
'51' ': BananaPi Pro (Lemaker)'
'50' ': BananaPi M2+ (sinovoip)'
'71' ': BeagleBone Black'
'39' ': LeMaker Guitar'
'' '●─ Other '
'22' ': Generic Device'
)
while :
do
# Check for valid entry, e.g. when set via environment variabe
if disable_error=1 G_CHECK_VALIDINT "$HW_MODEL" 0; then
for i in "${G_WHIP_MENU_ARRAY[@]}"
do
[[ $HW_MODEL == "$i" ]] && break 2
done
fi
if ! G_WHIP_MENU 'Please select the current device this is being installed on:\n - NB: Select "Generic device" if not listed.\n - "Core devices": Are fully supported by DietPi, offering full GPU + Kodi support.\n - "Limited support devices": No GPU support, supported limited to DietPi specific issues only (eg: excludes Kernel/GPU/VPU related items).'; then
G_DIETPI-NOTIFY 1 'No choice detected. Aborting...\n'
exit 0
elif [[ $G_WHIP_RETURNED_VALUE ]]; then
HW_MODEL=$G_WHIP_RETURNED_VALUE
break
fi
done
G_HW_MODEL=$HW_MODEL
unset -v HW_MODEL
# RPi: Detect Debian vs Raspbian and 64 vs 32 bit image
if (( $G_HW_MODEL < 10 )); then
if grep -q '^ID=debian' /etc/os-release; then
G_RASPBIAN=0
[[ $(mawk 'NR==1' /var/lib/dpkg/arch) == 'arm64' ]] && G_HW_ARCH=3 || G_HW_ARCH=2
else
G_RASPBIAN=1 G_HW_ARCH=1
fi
fi
G_DIETPI-NOTIFY 2 "Selected hardware model ID: $G_HW_MODEL"
G_DIETPI-NOTIFY 2 "Detected target CPU architecture: $G_HW_ARCH_NAME (ID: $G_HW_ARCH)"
# WiFi selection
if [[ $WIFI_REQUIRED != [01] ]]; then
G_WHIP_MENU_ARRAY=(
'0' ': I do not require WiFi functionality, skip related package install.'
'1' ': I require WiFi functionality, install related packages.'
)
(( $G_HW_MODEL == 20 )) && G_WHIP_DEFAULT_ITEM=0 || G_WHIP_DEFAULT_ITEM=1
if G_WHIP_MENU 'Please select an option:'; then
WIFI_REQUIRED=$G_WHIP_RETURNED_VALUE
else
G_DIETPI-NOTIFY 1 'No choice detected. Aborting...\n'
exit 0
fi
fi
# shellcheck disable=SC2015
(( $WIFI_REQUIRED )) && G_DIETPI-NOTIFY 2 'Marking WiFi as required' || G_DIETPI-NOTIFY 2 'Marking WiFi as NOT required'
# Distro Selection
DISTRO_LIST_ARRAY=(
'5' ': Buster (current stable release, recommended)'
'6' ': Bullseye (testing, if you want to live on bleeding edge)'
)
# - Enable/list available options based on criteria
# NB: Whiptail uses 2 array indices per entry: value + description
G_WHIP_MENU_ARRAY=()
for ((i=0; i<${#DISTRO_LIST_ARRAY[@]}; i+=2))
do
# Disable downgrades
if (( ${DISTRO_LIST_ARRAY[$i]} < $G_DISTRO )); then
G_DIETPI-NOTIFY 2 "Disabled distro downgrade to${DISTRO_LIST_ARRAY[$i+1]%% (*}"
# Enable option
else
G_WHIP_MENU_ARRAY+=("${DISTRO_LIST_ARRAY[$i]}" "${DISTRO_LIST_ARRAY[$i+1]}")
fi
done
unset -v DISTRO_LIST_ARRAY
if (( ! ${#G_WHIP_MENU_ARRAY[@]} )); then
G_DIETPI-NOTIFY 1 'No available distro versions found for this system. Aborting...\n'
exit 1
fi
while :
do
if disable_error=1 G_CHECK_VALIDINT "$DISTRO_TARGET" 0; then
for i in "${G_WHIP_MENU_ARRAY[@]}"
do
[[ $DISTRO_TARGET == "$i" ]] && break 2
done
fi
G_WHIP_DEFAULT_ITEM=${G_WHIP_MENU_ARRAY[0]} # Downgrades disabled, so first item matches current/lowest supported distro version
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
if G_WHIP_MENU "Please select a Debian version to install on this system.\n
Currently installed: $G_DISTRO_NAME (ID: $G_DISTRO)"; then
DISTRO_TARGET=$G_WHIP_RETURNED_VALUE
break
else
G_DIETPI-NOTIFY 1 'No choice detected. Aborting...\n'
exit 0
fi
done
if (( $DISTRO_TARGET == 5 )); then
DISTRO_TARGET_NAME='buster'
elif (( $DISTRO_TARGET == 6 )); then
DISTRO_TARGET_NAME='bullseye'
else
G_DIETPI-NOTIFY 1 'Invalid choice detected. Aborting...\n'
exit 1
fi
G_DIETPI-NOTIFY 2 "Selected Debian version: $DISTRO_TARGET_NAME (ID: $DISTRO_TARGET)"
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "[$SETUP_STEP] Downloading and installing DietPi source code"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------
local url="https://github.com/$G_GITOWNER/DietPi/archive/$G_GITBRANCH.tar.gz"
G_CHECK_URL_TIMEOUT=10 G_CHECK_URL_ATTEMPTS=2 G_CHECK_URL "$url"
G_EXEC_DESC='Downloading DietPi sourcecode' G_EXEC curl -sSfL "$url" -o package.tar.gz
[[ -d DietPi-$G_GITBRANCH ]] && G_EXEC_DESC='Cleaning previously extracted files' G_EXEC rm -R "DietPi-$G_GITBRANCH"
G_EXEC_DESC='Extracting DietPi sourcecode' G_EXEC tar xf package.tar.gz
rm package.tar.gz
[[ -d '/boot' ]] || G_EXEC_DESC='Creating /boot' G_EXEC mkdir /boot
G_DIETPI-NOTIFY 2 'Moving kernel and boot configuration to /boot'
# HW specific config.txt, boot.ini uEnv.txt
if (( $G_HW_MODEL < 10 )); then
G_EXEC mv "DietPi-$G_GITBRANCH/config.txt" /boot/
# Boot in 64-bit mode if this is a 64-bit image
[[ $G_HW_ARCH == 3 ]] && G_CONFIG_INJECT 'arm_64bit=' 'arm_64bit=1' /boot/config.txt
elif (( $G_HW_MODEL == 11 )); then
G_EXEC mv "DietPi-$G_GITBRANCH/boot_xu4.ini" /boot/boot.ini
elif (( $G_HW_MODEL == 12 )); then
G_EXEC mv "DietPi-$G_GITBRANCH/boot_c2.ini" /boot/boot.ini
fi
G_EXEC mv "DietPi-$G_GITBRANCH/dietpi.txt" /boot/
G_EXEC mv "DietPi-$G_GITBRANCH/README.md" /boot/dietpi-README.md
G_EXEC mv "DietPi-$G_GITBRANCH/LICENSE" /boot/dietpi-LICENSE.txt
G_EXEC mv "DietPi-$G_GITBRANCH/CHANGELOG.txt" /boot/dietpi-CHANGELOG.txt
# Reading version string for later use
G_DIETPI_VERSION_CORE=$(mawk 'NR==1' "DietPi-$G_GITBRANCH/dietpi/server_version-6")
G_DIETPI_VERSION_SUB=$(mawk 'NR==2' "DietPi-$G_GITBRANCH/dietpi/server_version-6")
G_DIETPI_VERSION_RC=$(mawk 'NR==3' "DietPi-$G_GITBRANCH/dietpi/server_version-6")
# Remove server_version* / (pre-)patch_file (downloads fresh from dietpi-update)
rm "DietPi-$G_GITBRANCH/dietpi/server_version"*
rm "DietPi-$G_GITBRANCH/dietpi/pre-patch_file"
rm "DietPi-$G_GITBRANCH/dietpi/patch_file"
G_EXEC_DESC='Copy DietPi scripts to /boot/dietpi' G_EXEC cp -Rf "DietPi-$G_GITBRANCH/dietpi" /boot/
G_EXEC_DESC='Copy DietPi system files in place' G_EXEC cp -Rf "DietPi-$G_GITBRANCH/rootfs"/. /
G_EXEC_DESC='Clean download location' G_EXEC rm -R "DietPi-$G_GITBRANCH"
G_EXEC_DESC='Set execute permissions for DietPi scripts' G_EXEC chmod -R +x /boot/dietpi /var/lib/dietpi/services /etc/cron.*/dietpi
G_EXEC systemctl daemon-reload
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "[$SETUP_STEP] APT configuration"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 2 "Setting APT sources.list: $DISTRO_TARGET_NAME $DISTRO_TARGET"
# We need to forward $DISTRO_TARGET* to dietpi-set_software, as well as $G_HW_MODEL + $G_RASPBIAN for Debian vs Raspbian decision.
G_DISTRO=$DISTRO_TARGET G_DISTRO_NAME=$DISTRO_TARGET_NAME G_HW_MODEL=$G_HW_MODEL G_RASPBIAN=$G_RASPBIAN G_EXEC /boot/dietpi/func/dietpi-set_software apt-mirror default
# Meveric, update repo to use our EU mirror: https://github.com/MichaIng/DietPi/issues/1519#issuecomment-368234302
sed -Ei 's|https?://oph\.mdrjr\.net|https://dietpi.com|' /etc/apt/sources.list.d/meveric*.list &> /dev/null
# (Re)create DietPi runtime and logs dir, used by G_AGx
G_EXEC mkdir -p /run/dietpi /var/tmp/dietpi/logs
G_AGUP
# @MichaIng https://github.com/MichaIng/DietPi/pull/1266/files
G_DIETPI-NOTIFY 2 'Marking all packages as auto-installed first, to allow effective autoremove afterwards'
local apackages
mapfile -t apackages < <(apt-mark showmanual)
[[ ${apackages[0]} ]] && G_EXEC apt-mark auto "${apackages[@]}"
unset -v apackages
# DietPi list of minimal required packages, which must be installed:
aPACKAGES_REQUIRED_INSTALL=(
'apt' # Debian package manager
'bash-completion' # Auto completes a wide list of bash commands and options via <tab>
'bzip2' # (.tar).bz2 archiver
'ca-certificates' # Adds known ca-certificates, necessary to practically access HTTPS sources
'console-setup' # DietPi-Config keyboard configuration + console fonts
'cron' # Background job scheduler
'curl' # Web address testing, downloading, uploading etc.
'dirmngr' # GNU key management required for some APT installs via additional repos
'ethtool' # Force Ethernet link speed
'fake-hwclock' # Hardware clock emulation, to allow correct timestamps during boot before network time sync
'gnupg' # apt-key add / gpg
'htop' # System monitor
'ifupdown' # Network interface configuration
'iputils-ping' # "ping" command
'isc-dhcp-client' # DHCP client
'kmod' # "modprobe", "lsmod", used by several DietPi scripts
'locales' # Support locales, used by dietpi-config > Language/Regional Options > Locale
'nano' # Simple text editor
'p7zip' # .7z archiver
'parted' # partprobe + drive partitioning, used by DietPi-Drive_Manager
'procps' # "kill", "ps", "pgrep", "sysctl", used by several DietPi scripts
'psmisc' # "killall", used by several DietPi scripts
'rfkill' # Block/unblock WiFi and Bluetooth adapters, only installed once to unblock everything, purged afterwards!
'sudo' # Root permission wrapper for users permitted via /etc/sudoers(.d/)
'systemd-sysv' # Includes systemd and additional commands: "poweroff", "shutdown" etc.
'tzdata' # Time zone data for system clock, auto summer/winter time adjustment
'udev' # /dev/ and hotplug management daemon
'unzip' # .zip unpacker
'usbutils' # "lsusb", used by DietPi-Software + DietPi-Bugreport
'wget' # Download tool
'whiptail' # DietPi dialogs
#'xz-utils' # (.tar).xz archiver
)
# G_DISTRO specific
# - Dropbear: DietPi default SSH-Client
# On Buster-, "dropbear" pulls in "dropbear-initramfs", which we don't need: https://packages.debian.org/dropbear
# - apt-transport-https: Allows HTTPS sources for ATP
# On Buster+, it is included in "apt" package: https://packages.debian.org/apt-transport-https
if (( $G_DISTRO > 5 )); then
aPACKAGES_REQUIRED_INSTALL+=('dropbear')
else
aPACKAGES_REQUIRED_INSTALL+=('dropbear-run')
(( $G_DISTRO < 5 )) && aPACKAGES_REQUIRED_INSTALL+=('apt-transport-https')
fi
# - systemd-timesyncd: Network time sync daemon
# Available as dedicated package since Bullseye: https://packages.debian.org/systemd-timesyncd
# While the above needs to be checked against "current" distro to not break SSH or APT before distro upgrade, this one should be checked against "target" distro version.
(( $DISTRO_TARGET > 5 )) && aPACKAGES_REQUIRED_INSTALL+=('systemd-timesyncd')
# - fdisk: Partitioning tool used by DietPi-FS_partition_resize and DietPi-Imager
# This has become an own package since Debian Buster: https://packages.debian.org/fdisk
(( $DISTRO_TARGET > 4 )) && aPACKAGES_REQUIRED_INSTALL+=('fdisk')
# G_HW_MODEL specific
# - initramfs: Required for generic bootloader, but not required/used by RPi bootloader, on VM install tiny-initramfs with limited features but sufficient and much smaller + faster
if (( $G_HW_MODEL == 20 )); then
aPACKAGES_REQUIRED_INSTALL+=('tiny-initramfs')
elif (( $G_HW_MODEL > 9 )); then
aPACKAGES_REQUIRED_INSTALL+=('initramfs-tools')
fi
# - Entropy daemon: Use modern rng-tools5 on all devices where it has been proven to work, on RPi rng-tools (default on Raspbian), else haveged: https://github.com/MichaIng/DietPi/issues/2806
if [[ $G_HW_MODEL =~ ^(11|14|16|42|58|68|69|72)$ ]]; then # Odroid XU4, RK3399, Odroid C4
aPACKAGES_REQUIRED_INSTALL+=('rng-tools5')
elif (( $G_HW_MODEL > 9 )); then
aPACKAGES_REQUIRED_INSTALL+=('haveged')
else
aPACKAGES_REQUIRED_INSTALL+=('rng-tools')
fi
# - Drive power management control
(( $G_HW_MODEL == 20 )) || aPACKAGES_REQUIRED_INSTALL+=('hdparm')
# WiFi related
if (( $WIFI_REQUIRED )); then
aPACKAGES_REQUIRED_INSTALL+=('iw') # Tools to configure WiFi adapters
aPACKAGES_REQUIRED_INSTALL+=('wireless-tools') # Same as "iw", deprecated but still required for non-nl80211 adapters
aPACKAGES_REQUIRED_INSTALL+=('crda') # Set WiFi frequencies according to local regulations, based on WiFi country code
aPACKAGES_REQUIRED_INSTALL+=('wpasupplicant') # Support for WPA-protected WiFi network connection
fi
# Install gdisk if root file system is on a GPT partition, used by DietPi-FS_partition_resize
[[ $(parted -s "$(lsblk -npo PKNAME "$(findmnt -no SOURCE /)")" print) == *'Partition Table: gpt'* ]] && aPACKAGES_REQUIRED_INSTALL+=('gdisk')
# Install required filesystem packages
if [[ $(blkid -s TYPE -o value) =~ (^|[[:space:]]|v)'fat' ]]; then
aPACKAGES_REQUIRED_INSTALL+=('dosfstools') # DietPi-Drive_Manager + fat (boot) drive file system check and creation tools
fi
# Kernel/bootloader/firmware
# - We need to install those directly to allow G_AGA() autoremove possible older packages later: https://github.com/MichaIng/DietPi/issues/1285#issuecomment-354602594
# - G_HW_ARCH specific
# x86_64
if (( $G_HW_ARCH == 10 )); then
local apackages=('linux-image-amd64' 'os-prober')
# Grub EFI
if dpkg-query -s 'grub-efi-amd64' &> /dev/null || [[ -d '/boot/efi' ]]; then
apackages+=('grub-efi-amd64')
# On Buster+ enable secure boot compatibility: https://packages.debian.org/grub-efi-amd64-signed
(( $DISTRO_TARGET > 4 )) && apackages+=('grub-efi-amd64-signed' 'shim-signed')
# Grub BIOS
else
apackages+=('grub-pc')
fi
G_AGI "${apackages[@]}"
unset -v apackages
# - G_HW_MODEL specific required firmware/kernel/bootloader packages
# ARMbian grab currently installed packages
elif [[ $(dpkg-query -Wf '${Package} ') == *'armbian'* ]]; then
systemctl stop armbian-*
local apackages=(
'linux-dtb-'
'linux-u-'
'linux-image-'
"linux-$DISTRO_TARGET_NAME-"
'sunxi-tools'
)
for i in "${apackages[@]}"
do
while read -r line
do
aPACKAGES_REQUIRED_INSTALL+=("$line")
G_DIETPI-NOTIFY 2 "ARMbian package detected and added: $line"
done <<< "$(dpkg-query -Wf '${Package}\n' | mawk -v pat="^$i" '$0~pat')"
done
unset -v apackages
# RPi
elif (( $G_HW_MODEL < 10 )); then
# Add raspi-copies-and-fills for 32-bit images only
[[ $G_HW_ARCH == 3 ]] && arm_mem= || arm_mem='raspi-copies-and-fills'
G_AGI libraspberrypi-bin libraspberrypi0 raspberrypi-bootloader raspberrypi-kernel raspberrypi-sys-mods $arm_mem
# Odroid C4
elif (( $G_HW_MODEL == 16 )); then
G_AGI linux-image-arm64-odroid-c4 meveric-keyring
G_EXEC_NOHALT=1 G_EXEC apt-mark manual u-boot # Workaround until C4 u-boot package has been added to repo: https://dietpi.com/meveric/pool/c4/
# Odroid N2
elif (( $G_HW_MODEL == 15 )); then
G_AGI linux-image-arm64-odroid-n2 meveric-keyring
# Odroid N1
elif (( $G_HW_MODEL == 14 )); then
G_AGI linux-image-arm64-odroid-n1 meveric-keyring
# Odroid C2
elif (( $G_HW_MODEL == 12 )); then
G_AGI linux-image-arm64-odroid-c2 meveric-keyring
# Odroid XU3/XU4/MC1/HC1/HC2
elif (( $G_HW_MODEL == 11 )); then
G_AGI linux-image-4.14-armhf-odroid-xu4 meveric-keyring
# ROCK Pi S (official Radxa Debian image)
elif (( $G_HW_MODEL == 73 )) && grep -q 'apt\.radxa\.com' /etc/apt/sources.list.d/*.list; then
G_AGI rockpis-rk-u-boot-latest linux-4.4-rockpis-latest rockchip-overlay
# - Generic kernel + device tree package auto detect
else
mapfile -t apackages < <(dpkg-query -Wf '${Package}\n' | grep -E '^linux-(image|dtb)')
if [[ ${apackages[0]} ]]; then
G_AGI "${apackages[@]}"
else
G_DIETPI-NOTIFY 2 'Unable to find kernel packages for installation. Assuming non-APT/.deb kernel installation.'
fi
unset -v apackages
fi
# - Firmware
if dpkg-query -Wf '${Package}\n' | grep -q '^armbian-firmware'; then
aPACKAGES_REQUIRED_INSTALL+=('armbian-firmware')
else
# Usually no firmware should be necessary for VMs. If user manually passes though some USB device, user might need to install the firmware then.
if (( $G_HW_MODEL != 20 )); then
aPACKAGES_REQUIRED_INSTALL+=('firmware-realtek') # Realtek Eth+WiFi+BT dongle firmware
if (( $G_HW_ARCH == 10 )); then
aPACKAGES_REQUIRED_INSTALL+=('firmware-linux') # Misc free+nonfree firmware
else
aPACKAGES_REQUIRED_INSTALL+=('firmware-linux-free') # Misc free firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-misc-nonfree') # Misc nonfree firmware + Ralink WiFi
fi
fi
if (( $WIFI_REQUIRED )); then
aPACKAGES_REQUIRED_INSTALL+=('firmware-atheros') # Qualcomm/Atheros WiFi+BT dongle firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-brcm80211') # Breadcom WiFi dongle firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-iwlwifi') # Intel WiFi dongle+PCIe firmware
if (( $G_HW_MODEL == 20 )); then
aPACKAGES_REQUIRED_INSTALL+=('firmware-realtek') # Realtek Eth+WiFi+BT dongle firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-misc-nonfree') # Misc nonfree firmware + Ralink WiFi
fi
fi
fi
G_DIETPI-NOTIFY 2 'Generating list of minimal packages, required for DietPi installation'
local apackages
mapfile -t apackages < <(dpkg --get-selections "${aPACKAGES_REQUIRED_INSTALL[@]}" 2> /dev/null | mawk '{print $1}')
[[ ${apackages[0]} ]] && G_EXEC_DESC='Marking required packages as manually installed' G_EXEC apt-mark manual "${apackages[@]}"
unset -v apackages
# Purging additional packages, that (in some cases) do not get autoremoved:
# - dbus: Not required for headless images, but sometimes marked as "important", thus not autoremoved.
# + Workaround for "The following packages have unmet dependencies: glib-networking libgtk-3-0"
# - dhcpcd5: https://github.com/MichaIng/DietPi/issues/1560#issuecomment-370136642
# - mountall: https://github.com/MichaIng/DietPi/issues/2613
# - initscripts: Pre-installed on Jessie systems (?), superseded and masked by systemd, but never autoremoved
G_AGP dbus dhcpcd5 mountall initscripts '*office*' '*xfce*' '*qt5*' '*xserver*' '*xorg*' glib-networking libgtk-3-0
# Remove any autoremove prevention
rm -fv /etc/apt/apt.conf.d/*autoremove*
G_AGA
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "[$SETUP_STEP] APT installations"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------
G_AGDUG
# Distro is now target (for APT purposes and G_AGX support due to installed binary, its here, instead of after G_AGUP)
G_DISTRO=$DISTRO_TARGET
G_DISTRO_NAME=$DISTRO_TARGET_NAME
unset -v DISTRO_TARGET DISTRO_TARGET_NAME
G_DIETPI-NOTIFY 2 'Installing core DietPi pre-req DEB packages'
G_AGI "${aPACKAGES_REQUIRED_INSTALL[@]}"
unset -v aPACKAGES_REQUIRED_INSTALL
G_AGA
G_EXEC_DESC='Preserving modified DEB package config files from now on' G_EXEC rm -v /etc/apt/apt.conf.d/98dietpi-forceconf
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "[$SETUP_STEP] Applying DietPi tweaks and cleanup"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------
# https://github.com/jirka-h/haveged/pull/7 https://github.com/MichaIng/DietPi/issues/3689#issuecomment-678322767
if [[ $G_DISTRO == 5 && $G_HW_ARCH == [23] && $G_HW_MODEL -gt 9 ]] && dpkg-query -s haveged &> /dev/null; then
G_DIETPI-NOTIFY 2 'Upgrading haveged entropy daemon to fix an issue on ARM:'
G_DIETPI-NOTIFY 2 ' - https://github.com/jirka-h/haveged/pull/7'
G_EXEC curl -sSfLO "https://dietpi.com/downloads/binaries/buster/libhavege2_$G_HW_ARCH_NAME.deb"
G_EXEC curl -sSfLO "https://dietpi.com/downloads/binaries/buster/haveged_$G_HW_ARCH_NAME.deb"
G_AGI "./libhavege2_$G_HW_ARCH_NAME.deb" "./haveged_$G_HW_ARCH_NAME.deb"
G_EXEC_NOHALT=1 G_EXEC rm "./libhavege2_$G_HW_ARCH_NAME.deb" "./haveged_$G_HW_ARCH_NAME.deb"
G_AGA
fi
G_DIETPI-NOTIFY 2 'Deleting list of known users and groups, not required by DietPi'
getent passwd pi > /dev/null && userdel -f pi
getent passwd test > /dev/null && userdel -f test # @fourdee
getent passwd odroid > /dev/null && userdel -f odroid
getent passwd rock64 > /dev/null && userdel -f rock64
getent passwd rock > /dev/null && userdel -f rock # Radxa images
getent passwd linaro > /dev/null && userdel -f linaro # ASUS TB