forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PREP_SYSTEM_FOR_DIETPI.sh
1980 lines (1558 loc) · 79.2 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 Buster 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=6 [567] (Buster: 5, Bullseye: 6, Bookworm: 7)
#------------------------------------------------------------------------------------------------
# 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 locale
# - Reset possibly conflicting environment for sub scripts
> /etc/environment
# - Apply override LC_ALL and default LANG for current script
export LC_ALL='C.UTF-8' LANG='C.UTF-8'
# 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
if findmnt -M /tmp > /dev/null
then
(( $(findmnt -Ufnrbo SIZE -M /tmp) < 536870912 )) && mount -o remount,size=536870912 /tmp
else
mount -t tmpfs -o size=536870912 tmpfs /tmp
fi
# 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
# https://github.com/MichaIng/DietPi/issues/4083
rm -fv /etc/apt/sources.list.d/vscode.list /etc/apt/trusted.gpg.d/microsoft.gpg /etc/apt/preferences.d/3rd_parties.pref
# 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?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_
# - During PREP only: Force new DEB package config files and tmpfs lists + archives
cat << '_EOF_' > /etc/apt/apt.conf.d/98dietpi-prep
#clear DPkg::options;
DPkg::options:: "--force-confmiss,confnew";
Dir::Cache "/tmp/apt";
Dir::Cache::archives "/tmp/apt/archives";
Dir::State "/tmp/apt";
Dir::State::extended_states "/var/lib/apt/extended_states";
Dir::State::status "/var/lib/dpkg/status";
Dir::Cache::pkgcache "";
_EOF_
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
'whiptail' # G_WHIP
)
for i in "${aAPT_PREREQS[@]}"
do
dpkg-query -s "$i" &> /dev/null || apt-get -y install "$i" && continue
echo -e "[FAILED] Unable to install $i, please try to install it manually:\n\t # apt install $i\n"
exit 1
done
unset -v aAPT_PREREQS
# 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 ] Exit selected. 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 distro version of this operating system
distro=$(</etc/debian_version)
if [[ $distro == '10.'* || $distro == 'buster/sid' ]]; then
G_DISTRO=5
G_DISTRO_NAME='buster'
elif [[ $distro == '11.'* || $distro == 'bullseye/sid' ]]; then
G_DISTRO=6
G_DISTRO_NAME='bullseye'
elif [[ $distro == '12.'* || $distro == 'bookworm/sid' ]]; then
G_DISTRO=7
G_DISTRO_NAME='bookworm'
else
G_DIETPI-NOTIFY 1 "Unsupported distribution version: \"$distro\". Aborting...\n"
exit 1
fi
unset -v distro
G_DIETPI-NOTIFY 2 "Detected distribution version: ${G_DISTRO_NAME^} (ID: $G_DISTRO)"
# Detect the hardware architecture of this operating system
if grep -q '^ID=raspbian' /etc/os-release; then
# Raspbian: Force ARMv6
G_RASPBIAN=1 G_HW_ARCH=1 G_HW_ARCH_NAME='armv6l'
else
# Debian: ARMv6 is not supported here
G_RASPBIAN=0
G_HW_ARCH_NAME=$(uname -m)
if [[ $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 "Unsupported CPU architecture: \"$G_HW_ARCH_NAME\". Aborting...\n"
exit 1
fi
fi
G_DIETPI-NOTIFY 2 "Detected target CPU architecture: $G_HW_ARCH_NAME (ID: $G_HW_ARCH)"
Main(){
#------------------------------------------------------------------------------------------------
# Init setup step headers
SETUP_STEP=0
readonly G_NOTIFY_3_MODE='Step'
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "[$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
[[ -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 # Includes (Pre|Post)Boot on pre-v6.29 systems
[[ -f '/etc/systemd/system/dietpi-preboot.service' ]] && systemctl stop dietpi-preboot # Includes (Pre|Post)Boot on post-v6.28 systems
# 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
# - Pre-v6.29: /DietPi mount point
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 '/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 "$G_PROGRAM_NAME" "[$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_BUTTON_CANCEL_TEXT='Exit'
if ! 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.'; then
G_DIETPI-NOTIFY 1 'Exit selected. Aborting...\n'
exit 0
fi
fi
# Disallowed names
aDISALLOWED_NAMES=(
'official'
'fourdee'
'daniel knight'
'dan knight'
'michaing'
'diet'
)
for i in "${aDISALLOWED_NAMES[@]}"
do
[[ ${G_WHIP_RETURNED_VALUE,,} =~ $i ]] || continue
G_WHIP_MSG "\"$G_WHIP_RETURNED_VALUE\" is reserved and cannot be used. Please try again."
continue 2
done
unset -v aDISALLOWED_NAMES
IMAGE_CREATOR=$G_WHIP_RETURNED_VALUE
break
done
G_DIETPI-NOTIFY 2 "Entered image creator: $IMAGE_CREATOR"
# Pre-image used/name: Respect environment variable
if [[ ! $PREIMAGE_INFO ]]; then
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
if ! 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, Raspberry Pi OS Lite, Meveric or "forum.odroid.com/viewtopic.php?t=123456" etc.\n\nNB: An entry is required.'; then
G_DIETPI-NOTIFY 1 'Exit selected. Aborting...\n'
exit 0
fi
PREIMAGE_INFO=$G_WHIP_RETURNED_VALUE
fi
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 '
'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'
'13' ': Odroid U3'
'10' ': Odroid C1'
'11' ': Odroid XU3/XU4/MC1/HC1/HC2'
'12' ': Odroid C2'
'15' ': Odroid N2'
'16' ': Odroid C4/HC4'
'70' ': Sparky SBC'
'52' ': ASUS Tinker Board'
'40' ': PINE A64'
'45' ': PINE H64'
'43' ': ROCK64'
'42' ': ROCKPro64'
'44' ': Pinebook'
'46' ': Pinebook Pro'
'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'
'61' ': NanoPi M2/T2'
'62' ': NanoPi M3/T3/Fire3'
'68' ': NanoPi M4/T4/NEO4'
'58' ': NanoPi M4V2'
'67' ': NanoPi K1 Plus'
'54' ': NanoPi K2'
'48' ': NanoPi R1'
'55' ': NanoPi R2S'
'47' ': NanoPi R4S'
'72' ': ROCK Pi 4'
'73' ': ROCK Pi S'
'74' ': Radxa Zero'
'' '●─ x86_64 '
'21' ': x86_64 Native PC'
'20' ': x86_64 Virtual Machine'
'' '●─ Other '
'29' ': Generic Amlogic S922X'
'28' ': Generic Amlogic S905'
'27' ': Generic Allwinner H6'
'26' ': Generic Allwinner H5'
'25' ': Generic Allwinner H3'
'24' ': Generic Rockchip RK3399'
'23' ': Generic Rockchip RK3328'
'22' ': Generic Device'
)
while :
do
# Check for valid environment variabe
[[ $HW_MODEL =~ ^[0-9]+$ ]] && for i in "${G_WHIP_MENU_ARRAY[@]}"
do
[[ $HW_MODEL == "$i" ]] && break 2
done
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
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": Fully supported by DietPi, offering full GPU acceleration + Kodi support.\n - "Limited support devices": No GPU acceleration guaranteed.'; then
G_DIETPI-NOTIFY 0 'Exit selected. Aborting...\n'
exit 0
fi
HW_MODEL=$G_WHIP_RETURNED_VALUE
break
done
G_HW_MODEL=$HW_MODEL
unset -v HW_MODEL
G_DIETPI-NOTIFY 2 "Selected hardware model ID: $G_HW_MODEL"
# 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
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
if G_WHIP_MENU 'Please select an option:'; then
WIFI_REQUIRED=$G_WHIP_RETURNED_VALUE
else
G_DIETPI-NOTIFY 0 'Exit selected. 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 (oldstable, if you must stay with an old release)'
'6' ': Bullseye (current stable release, recommended)'
'7' ': Bookworm (testing, if you want to live on bleeding edge)'
)
# - List supported distro versions up from currently installed one
G_WHIP_MENU_ARRAY=()
for ((i=0; i<${#DISTRO_LIST_ARRAY[@]}; i+=2))
do
(( ${DISTRO_LIST_ARRAY[$i]} < $G_DISTRO )) || G_WHIP_MENU_ARRAY+=("${DISTRO_LIST_ARRAY[$i]}" "${DISTRO_LIST_ARRAY[$i+1]}")
done
unset -v DISTRO_LIST_ARRAY
while :
do
[[ $DISTRO_TARGET =~ ^[0-9]+$ ]] && for i in "${G_WHIP_MENU_ARRAY[@]}"
do
[[ $DISTRO_TARGET == "$i" ]] && break 2
done
G_WHIP_DEFAULT_ITEM=${G_WHIP_MENU_ARRAY[0]} # First item matches current 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
fi
G_DIETPI-NOTIFY 0 'Exit selected. Aborting...\n'
exit 0
done
if (( $DISTRO_TARGET == 5 )); then
DISTRO_TARGET_NAME='buster'
elif (( $DISTRO_TARGET == 6 )); then
DISTRO_TARGET_NAME='bullseye'
else
DISTRO_TARGET_NAME='bookworm'
fi
G_DIETPI-NOTIFY 2 "Selected Debian version: $DISTRO_TARGET_NAME (ID: $DISTRO_TARGET)"
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "[$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
echo "root=PARTUUID=$(findmnt -Ufnro PARTUUID -M /) rootfstype=ext4 rootwait fsck.repair=yes net.ifnames=0 logo.nologo quiet console=serial0,115200 console=tty1" > /boot/cmdline.txt
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
G_EXEC sed -i "s/root=UUID=[^[:blank:]]*/root=UUID=$(findmnt -Ufnro UUID -M /)/" /boot/boot.ini
elif [[ $G_HW_MODEL == 12 && -f '/boot/boot.ini' ]]; then
G_EXEC mv "DietPi-$G_GITBRANCH/boot_c2.ini" /boot/boot.ini
elif [[ $G_HW_MODEL == 15 && -f '/boot/boot.ini' ]]; then
G_EXEC mv "DietPi-$G_GITBRANCH/boot_n2.ini" /boot/boot.ini
G_EXEC sed -i "s/root=UUID=[^[:blank:]]*/root=UUID=$(findmnt -Ufnro UUID -M /)/" /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
# Reading version string for later use
. "DietPi-$G_GITBRANCH/.update/version"
G_DIETPI_VERSION_CORE=$G_REMOTE_VERSION_CORE
G_DIETPI_VERSION_SUB=$G_REMOTE_VERSION_SUB
G_DIETPI_VERSION_RC=$G_REMOTE_VERSION_RC
# Remove server_version-6 / (pre-)patch_file (downloads fresh from dietpi-update)
rm "DietPi-$G_GITBRANCH/dietpi/server_version-6"
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_DIETPI-NOTIFY 2 'Storing DietPi version info:'
G_CONFIG_INJECT 'DEV_GITBRANCH=' "DEV_GITBRANCH=$G_GITBRANCH" /boot/dietpi.txt
G_CONFIG_INJECT 'DEV_GITOWNER=' "DEV_GITOWNER=$G_GITOWNER" /boot/dietpi.txt
G_VERSIONDB_SAVE
# Apply live patches
G_DIETPI-NOTIFY 2 'Applying DietPi live patches to fix known bugs in this version'
for i in "${!G_LIVE_PATCH[@]}"
do
if eval "${G_LIVE_PATCH_COND[$i]}"
then
G_DIETPI-NOTIFY 2 "Applying live patch $i"
eval "${G_LIVE_PATCH[$i]}"
G_LIVE_PATCH_STATUS[$i]='applied'
else
G_LIVE_PATCH_STATUS[$i]='not applicable'
fi
# Store new status of live patch to /boot/dietpi/.version
G_CONFIG_INJECT "G_LIVE_PATCH_STATUS\[$i\]=" "G_LIVE_PATCH_STATUS[$i]='${G_LIVE_PATCH_STATUS[$i]}'" /boot/dietpi/.version
done
G_EXEC cp /boot/dietpi/.version /var/lib/dietpi/.dietpi_image_version
G_EXEC systemctl daemon-reload
#------------------------------------------------------------------------------------------------
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "[$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 own 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.
'ethtool' # Force Ethernet link speed
'fake-hwclock' # Hardware clock emulation, to allow correct timestamps during boot before network time sync
'fdisk' # Partitioning tool used by DietPi-FS_partition_resize and DietPi-Imager
'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')
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')
# 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, else haveged: https://github.com/MichaIng/DietPi/issues/2806
if [[ $G_HW_MODEL -lt 10 || $G_HW_MODEL =~ ^(14|15|16|24|29|42|46|58|68|72|74)$ ]]; then # RPi, S922X, Odroid C4, RK3399 - 47 NanoPi R4S, Radxa Zero
aPACKAGES_REQUIRED_INSTALL+=('rng-tools5')
else
aPACKAGES_REQUIRED_INSTALL+=('haveged')
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
[[ $(blkid -s PTTYPE -o value -c /dev/null "$(lsblk -npo PKNAME "$(findmnt -Ufnro SOURCE -M /)")") == 'gpt' ]] && aPACKAGES_REQUIRED_INSTALL+=('gdisk')
# Install file system tools required for file system resizing and fsck
local ae2fsprogs=('--allow-remove-essential' 'e2fsprogs')
while read -r line
do
if [[ $line == 'ext'[2-4] ]]
then
aPACKAGES_REQUIRED_INSTALL+=('e2fsprogs')
ae2fsprogs=()
elif [[ $line == 'vfat' ]]
then
aPACKAGES_REQUIRED_INSTALL+=('dosfstools')
elif [[ $line == 'f2fs' ]]
then
aPACKAGES_REQUIRED_INSTALL+=('f2fs-tools')
elif [[ $line == 'btrfs' ]]
then
aPACKAGES_REQUIRED_INSTALL+=('btrfs-progs')
fi
done < <(blkid -s TYPE -o value -c /dev/null | sort -u)
# 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
# - Assure that dir for additional sources is present
[[ -d '/etc/apt/sources.list.d' ]] || G_EXEC mkdir /etc/apt/sources.list.d
# - G_HW_ARCH specific
# x86_64
if (( $G_HW_ARCH == 10 )); then
local apackages=('linux-image-amd64' 'os-prober')
# As linux-image-amd64 pulls initramfs already, pre-install the intended implementation here already
(( $G_HW_MODEL == 20 )) && apackages+=('tiny-initramfs') || apackages+=('initramfs-tools')
# Grub EFI with secure boot compatibility
if [[ -d '/boot/efi' ]] || dpkg-query -s 'grub-efi-amd64' &> /dev/null; then
apackages+=('grub-efi-amd64' 'grub-efi-amd64-signed' 'shim-signed')
# Grub BIOS
else
apackages+=('grub-pc')
fi
# Skip creating kernel symlinks and remove existing ones
echo 'do_symlinks=0' > /etc/kernel-img.conf
G_EXEC rm -f /{,boot/}{initrd.img,vmlinuz}{,.old}
# If /boot is on a FAT partition, create a kernel upgrade hook script to remove existing files first: https://github.com/MichaIng/DietPi/issues/4788
if [[ $(findmnt -Ufnro FSTYPE -M /boot) == 'vfat' ]]
then
G_EXEC mkdir -p /etc/kernel/preinst.d
cat << '_EOF_' > /etc/kernel/preinst.d/dietpi
#!/bin/sh -e
# Remove old kernel files if existing: https://github.com/MichaIng/DietPi/issues/4788
{
# Fail if the package name was not passed, which is done when being invoked by dpkg
if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]
then
echo 'DPKG_MAINTSCRIPT_PACKAGE was not set, this script must be invoked by dpkg.'
exit 1
fi
# Loop through files in /boot, shipped by the package, and remove them, if existing
for file in $(dpkg -L "$DPKG_MAINTSCRIPT_PACKAGE" | grep '^/boot/')
do
[ ! -f "$file" ] || rm "$file"
done
}
_EOF_
G_EXEC chmod +x /etc/kernel/preinst.d/dietpi
fi
G_AGI "${apackages[@]}"
unset -v apackages
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# - 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-image-'
'linux-dtb-'
'linux-u-boot-'
)
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
# Add u-boot-tools, required to convert initramfs images into u-boot format
aPACKAGES_REQUIRED_INSTALL+=('u-boot-tools')
# Generate and cleanup uInitrd
local arch='arm'
(( $G_HW_ARCH == 3 )) && arch='arm64'
G_EXEC mkdir -p /etc/initramfs/post-update.d
cat << _EOF_ > /etc/initramfs/post-update.d/99-dietpi-uboot
#!/bin/dash
echo 'update-initramfs: Converting to U-Boot format' >&2
mkimage -A $arch -O linux -T ramdisk -C gzip -n uInitrd -d \$2 /boot/uInitrd-\$1 > /dev/null
ln -sf uInitrd-\$1 /boot/uInitrd > /dev/null 2>&1 || mv /boot/uInitrd-\$1 /boot/uInitrd
exit 0
_EOF_
G_EXEC chmod +x /etc/initramfs/post-update.d/99-dietpi-uboot
G_EXEC mkdir -p /etc/kernel/preinst.d
cat << '_EOF_' > /etc/kernel/preinst.d/dietpi-initramfs_cleanup
#!/bin/dash
# skip if initramfs-tools is not installed
[ -x /usr/sbin/update-initramfs ] || exit 0
# passing the kernel version is required
version="$1"
if [ -z "$version" ]; then
echo "W: initramfs-tools: ${DPKG_MAINTSCRIPT_PACKAGE:-kernel package} did not pass a version number" >&2
exit 0
fi
# avoid running multiple times
if [ -n "$DEB_MAINT_PARAMS" ]; then
eval set -- "$DEB_MAINT_PARAMS"
if [ "$1" != 'upgrade' ]; then
exit 0
fi
fi
_EOF_
# Bullseye: initramfs-tools' /var/lib/initramfs-tools state directory is not used anymore
if (( $DISTRO_TARGET > 5 ))
then
cat << '_EOF_' >> /etc/kernel/preinst.d/dietpi-initramfs_cleanup
# delete unused initrd images
find /boot -name 'initrd.img-*' -o -name 'uInitrd-*' ! -name "*-$version" -printf 'Removing obsolete file %f\n' -delete
exit 0
_EOF_
else
cat << '_EOF_' >> /etc/kernel/preinst.d/dietpi-initramfs_cleanup
# loop through existing initramfs images
for v in $(ls -1 /var/lib/initramfs-tools | linux-version sort --reverse); do
if ! linux-version compare $v eq $version; then
# try to delete delete old initrd images via update-initramfs
INITRAMFS_TOOLS_KERNEL_HOOK=y update-initramfs -d -k $v 2>/dev/null
# delete unused state files
find /var/lib/initramfs-tools -type f ! -name "$version" -printf 'Removing obsolete file %f\n' -delete
# delete unused initrd images
find /boot -name 'initrd.img-*' -o -name 'uInitrd-*' ! -name "*-$version" -printf 'Removing obsolete file %f\n' -delete
fi
done
exit 0
_EOF_
fi
G_EXEC chmod +x /etc/kernel/preinst.d/dietpi-initramfs_cleanup
# Remove obsolete components from Armbian list and connect via HTTPS
G_EXEC eval "echo 'deb http://apt.armbian.com/ ${DISTRO_TARGET_NAME/bookworm/bullseye} main' > /etc/apt/sources.list.d/armbian.list"
# Exclude doubled device tree files, shipped with the kernel package
echo 'path-exclude /usr/lib/linux-image-current-*' > /etc/dpkg/dpkg.cfg.d/01-dietpi-exclude_doubled_devicetrees
G_EXEC rm -Rf /usr/lib/linux-image-current-*
# RPi
elif (( $G_HW_MODEL < 10 )); then
# ARMv6/7: Add raspi-copies-and-fills
local a32bit=()
[[ $G_HW_ARCH == 3 ]] || a32bit=('raspi-copies-and-fills')
G_AGI raspberrypi-bootloader raspberrypi-kernel libraspberrypi0 libraspberrypi-bin raspberrypi-sys-mods raspberrypi-archive-keyring "${a32bit[@]}"
# https://github.com/RPi-Distro/raspberrypi-sys-mods/pull/60
[[ -f '/etc/apt/trusted.gpg.d/microsoft.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg.d/microsoft.gpg
[[ -f '/etc/apt/sources.list.d/vscode.list' ]] && G_EXEC rm /etc/apt/sources.list.d/vscode.list
# Move Raspbian key to active place and remove obsolete combined keyring
[[ -f '/usr/share/keyrings/raspbian-archive-keyring.gpg' ]] && G_EXEC ln -sf /usr/share/keyrings/raspbian-archive-keyring.gpg /etc/apt/trusted.gpg.d/raspbian-archive-keyring.gpg
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# Odroid C4
elif (( $G_HW_MODEL == 16 )); then
G_AGI linux-image-arm64-odroid-c4 meveric-keyring u-boot # On C4, the kernel package does not depend on the U-Boot package
# Apply kernel postinst steps manually, that depend on /proc/cpuinfo content, not matching when running in a container.
[[ -f '/boot/Image' ]] && G_EXEC mv /boot/Image /boot/Image.gz
[[ -f '/boot/Image.gz.bak' ]] && G_EXEC rm /boot/Image.gz.bak
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# Odroid N2
elif (( $G_HW_MODEL == 15 )); then
G_AGI linux-image-arm64-odroid-n2 meveric-keyring
# Apply kernel postinst steps manually, that depend on /proc/cpuinfo content, not matching when running in a container.
[[ -f '/boot/Image' ]] && G_EXEC mv /boot/Image /boot/Image.gz
[[ -f '/boot/Image.gz.bak' ]] && G_EXEC rm /boot/Image.gz.bak
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# Odroid C2
elif (( $G_HW_MODEL == 12 )); then
G_AGI linux-image-arm64-odroid-c2 meveric-keyring
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# Odroid XU3/XU4/MC1/HC1/HC2
elif (( $G_HW_MODEL == 11 )); then
G_AGI linux-image-4.14-armhf-odroid-xu4 meveric-keyring
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# ROCK Pi S (official Radxa Debian image)
elif (( $G_HW_MODEL == 73 )) && grep -q 'apt\.radxa\.com' /etc/apt/sources.list.d/*.list; then
# Install Radxa APT repo cleanly: No Bullseye repo available yet
G_EXEC rm -Rf /etc/apt/{trusted.gpg,sources.list.d/{,.??,.[^.]}*}
G_EXEC eval "curl -sSfL 'https://apt.radxa.com/${DISTRO_TARGET_NAME/bullseye/buster}-stable/public.key' | gpg --dearmor -o /etc/apt/trusted.gpg.d/dietpi-radxa.gpg --yes"
G_EXEC eval "echo 'deb https://apt.radxa.com/${DISTRO_TARGET_NAME/bullseye/buster}-stable/ ${DISTRO_TARGET_NAME/bullseye/buster} main' > /etc/apt/sources.list.d/dietpi-radxa.list"
G_AGUP
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# NB: rockpis-dtbo is not required as it doubles the overlays that are already provided (among others) with the kernel package
G_AGI rockpis-rk-ubootimg linux-4.4-rock-pi-s-latest rockchip-overlay u-boot-tools
# Radxa Zero (official Radxa Debian image)
elif (( $G_HW_MODEL == 74 )) && grep -q 'apt\.radxa\.com' /etc/apt/sources.list.d/*.list; then
# Install Radxa APT repo cleanly: No Bullseye repo available yet
G_EXEC rm -Rf /etc/apt/{trusted.gpg,sources.list.d/{,.??,.[^.]}*}
G_EXEC eval "curl -sSfL 'https://apt.radxa.com/${DISTRO_TARGET_NAME/bullseye/buster}-stable/public.key' | gpg --dearmor -o /etc/apt/trusted.gpg.d/dietpi-radxa.gpg --yes"
G_EXEC eval "echo 'deb https://apt.radxa.com/${DISTRO_TARGET_NAME/bullseye/buster}-stable/ ${DISTRO_TARGET_NAME/bullseye/buster} main' > /etc/apt/sources.list.d/dietpi-radxa.list"
G_AGUP
# Remove obsolete combined keyring
[[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC rm /etc/apt/trusted.gpg
[[ -f '/etc/apt/trusted.gpg~' ]] && G_EXEC rm '/etc/apt/trusted.gpg~'
# Preserve all installed kernel, device tree and bootloader packages, until fixed meta packages are available: https://github.com/radxa/apt
# Additionally install bc, required to calculate the initramfs size via custom hook (by Radxa) which updates /boot/uEnv.txt accordingly on initramfs updates
# And install "file" which is used to detect whether the kernel image is compressed and in case uncompress it
# shellcheck disable=SC2046
G_AGI $(dpkg-query -Wf '${Package}\n' | grep -E '^linux-(image|dtb|u-boot)-|^u-boot') bc file
# - Generic kernel + device tree + U-Boot package auto detect
else
mapfile -t apackages < <(dpkg-query -Wf '${Package}\n' | grep -E '^linux-(image|dtb|u-boot)-|^u-boot')
if [[ ${apackages[0]} ]]; then
G_AGI "${apackages[@]}"
else