forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PREP_SYSTEM_FOR_DIETPI.sh
1779 lines (1286 loc) · 60.9 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
{
#------------------------------------------------------------------------------------------------
# Optimize current Debian installation and prep for DietPi installation.
#------------------------------------------------------------------------------------------------
# REQUIREMENTS
# - Currently running Debian (ideally minimal, eg: Raspbian Lite-ish =)) )
# - systemd as system/init/service manager
# - Either eth0 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
#
# 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 pre-reqs, with exit, prior to initial run of script
#------------------------------------------------------------------------------------------------
# Exit path for non-root executions
if (( $UID )); then
echo -e '[FAILED] Root privileges required, please run the script with "sudo"\nIn case install the "sudo" package with root privileges:\n\t# apt-get install -y sudo\n'
exit 1
fi
# Work inside /tmp as usually ramfs 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
# APT: 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
# Allow PDiffs on RPi 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 /etc/apt/apt.conf.d/50raspi
# Check/install minimal APT Pre-Reqs
a_MIN_APT_PREREQS=(
'apt-transport-https' # Allows HTTPS sources for APT
'wget' # Download DietPi-Globals...
'ca-certificates' # ...via HTTPS
'unzip' # Unzip DietPi code
'locales' # Allow ensuring en_GB.UTF-8
'whiptail' # G_WHIP...
'ncurses-bin' # ...using tput
)
# Removing conflicting /etc/apt/sources.list.d entries
# - Meveric: https://github.com/MichaIng/DietPi/issues/1285#issuecomment-355759321
[[ -f '/etc/apt/sources.list.d/deb-multimedia.list' ]] && rm /etc/apt/sources.list.d/deb-multimedia.list
# - OMV: https://dietpi.com/phpbb/viewtopic.php?f=11&t=2772
[[ -f '/etc/apt/sources.list.d/openmediavault.list' ]] && rm /etc/apt/sources.list.d/openmediavault.list
# Fixing sources.list as Debian dropped Jessie support: https://github.com/MichaIng/DietPi/issues/2665
if grep -q 'jessie' /etc/os-release && ! grep -qi 'raspbian' /etc/os-release; then
if [[ $(uname -m) == 'aarch64' ]]; then
echo 'deb http://archive.debian.org/debian/ main contrib non-free' > /etc/apt/sources.list
else
sed -Ei '/jessie-(backports|updates)/d' /etc/apt/sources.list
fi
fi
apt-get clean
apt-get update
for i in "${a_MIN_APT_PREREQS[@]}"
do
if ! dpkg-query -s $i &> /dev/null && ! apt-get install -y $i; then
echo -e "[FAILED] Unable to install $i, please try to install it manually:\n\t # apt-get install -y $i\n"
exit 1
fi
done
unset a_MIN_APT_PREREQS
# Wget: 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
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 '/DietPi/dietpi/func/dietpi-set_software locale', for future script use
echo 'en_GB.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
# - Update /etc/default/locales with new values (not effective until next load of bash session, eg: logout/in)
update-locale 'LC_ALL=en_GB.UTF-8'
# - Export locale vars to assure the following whiptail being beautiful
export LC_ALL='en_GB.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 aWHIP_BRANCH
fi
echo "[ INFO ] Selected Git branch: $GITOWNER/$GITBRANCH"
#------------------------------------------------------------------------------------------------
# DietPi-Globals
#------------------------------------------------------------------------------------------------
# - Download
# - NB: We'll have to manually handle errors, until DietPi-Globals are successfully loaded.
if ! wget "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
# - 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
G_PROGRAM_NAME='DietPi-PREP'
G_INIT
# - Applying Git info
G_GITOWNER=$GITOWNER; unset GITOWNER
G_GITBRANCH=$GITBRANCH; unset GITBRANCH
# - Detect the Debian version of this operating system.
if grep -q 'jessie' /etc/os-release; then
G_DISTRO=3
G_DISTRO_NAME='jessie'
elif 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. Aborting...\n'
exit 1
fi
# - Detect the hardware architecture of this operating system.
G_HW_ARCH_DESCRIPTION=$(uname -m)
if [[ $G_HW_ARCH_DESCRIPTION == 'armv6l' ]]; then
G_HW_ARCH=1
elif [[ $G_HW_ARCH_DESCRIPTION == 'armv7l' ]]; then
G_HW_ARCH=2
elif [[ $G_HW_ARCH_DESCRIPTION == 'aarch64' ]]; then
G_HW_ARCH=3
elif [[ $G_HW_ARCH_DESCRIPTION == 'x86_64' ]]; then
G_HW_ARCH=10
else
G_DIETPI-NOTIFY 1 "Unknown or unsupported CPU architecture: \"$G_HW_ARCH_DESCRIPTION\". Aborting...\n"
exit 1
fi
Main(){
# Setup step, current (used in info)
SETUP_STEP=0
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP: Detecting existing DietPi system:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
if [[ -d '/DietPi/dietpi' || -d '/boot/dietpi' ]]; then
G_DIETPI-NOTIFY 2 'DietPi system found, removing the old files and stopping services. (pre-prep)'
# - Stop services: RAMdisk includes (Pre|Post)Boot due to dependencies
[[ -f '/DietPi/dietpi/dietpi-services' ]] && /DietPi/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 services
for i in /etc/systemd/system/dietpi-*
do
[[ -f $i ]] || continue
systemctl disable --now ${i##*/}
rm $i
done
# - Delete any previous existing data
# Failsafe
umount /DietPi
[[ -d '/DietPi' ]] && rm -R /DietPi
rm -Rf /{boot,mnt,etc,var/lib,var/tmp}/dietpi*
rm -f /etc/{bashrc,profile,sysctl}.d/dietpi*
[[ -f '/root/DietPi-Automation.log' ]] && rm /root/DietPi-Automation.log
[[ -f '/boot/Automation_Format_My_Usb_Drive' ]] && rm /boot/Automation_Format_My_Usb_Drive
else
G_DIETPI-NOTIFY 2 'Non-DietPi system found, skipping pre-prep'
fi
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP Ask user about: Image info / Hardware / WiFi / Distro:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
# 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 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'
'k-plan'
'diet'
)
for i in "${aDISALLOWED_NAMES[@]}"
do
if [[ ${G_WHIP_RETURNED_VALUE,,} =~ $i ]]; then
DISALLOWED_NAME=1
break
fi
done
unset 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
if [[ ! $PREIMAGE_INFO ]]; then
while :
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.'
if [[ $G_WHIP_RETURNED_VALUE ]]; then
PREIMAGE_INFO=$G_WHIP_RETURNED_VALUE
break
fi
done
fi
G_DIETPI-NOTIFY 2 "Entered pre-image info: $PREIMAGE_INFO"
# Hardware selection
# NB: PLEASE ENSURE HW_MODEL INDEX ENTRIES MATCH : PREP, dietpi-obtain_hw_model, dietpi-survey_results,
# NBB: DO NOT REORDER INDEX's. These are now fixed and will never change (due to survey results etc)
G_WHIP_DEFAULT_ITEM=22
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
G_WHIP_MENU_ARRAY=(
'' '●─ Other '
'22' ': Generic device (unknown to DietPi)'
'' '●─ SBC─(Core devices, with GPU support) '
'12' ': Odroid C2'
'11' ': Odroid XU3/XU4/HC1/HC2'
'44' ': Pinebook 1080p'
'0' ': Raspberry Pi (All models)'
#'1' ': Raspberry Pi 1/Zero (512mb)'
#'2' ': Raspberry Pi 2'
#'3' ': Raspberry Pi 3/3+'
#'4' ': Raspberry Pi 4'
'' '●─ PC '
'21' ': x86_64 Native PC'
'20' ': x86_64 Virtual Machine'
'' '●─ SBC─(Limited support devices, no GPU support) '
'52' ': ASUS Tinker Board'
'53' ': BananaPi (sinovoip)'
'51' ': BananaPi Pro (Lemaker)'
'50' ': BananaPi M2+ (sinovoip)'
'71' ': Beagle Bone Black'
'69' ': Firefly RK3399'
'39' ': LeMaker Guitar'
'60' ': NanoPi NEO'
'65' ': NanoPi NEO 2'
'64' ': NanoPi NEO Air'
'63' ': NanoPi M1/T1'
'66' ': NanoPi M1 Plus'
'61' ': NanoPi M2/T2'
'62' ': NanoPi M3/T3/F3'
'68' ': NanoPC T4'
'67' ': NanoPi K1 Plus'
'10' ': Odroid C1'
'14' ': Odroid N1'
'15' ': Odroid N2'
'13' ': Odroid U3'
'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'
'40' ': Pine A64'
'43' ': Rock64'
'42' ': RockPro64'
'70' ': Sparky SBC'
'72' ': ROCK Pi 4'
)
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
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).'
if (( $? )); 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 HW_MODEL
# + Set for future scripts
echo $G_HW_MODEL > /etc/.dietpi_hw_model_identifier
G_DIETPI-NOTIFY 2 "Selected hardware model ID: $G_HW_MODEL"
G_DIETPI-NOTIFY 2 "Detected CPU architecture: $G_HW_ARCH_DESCRIPTION (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_WHIP_DEFAULT_ITEM=1
(( $G_HW_MODEL == 20 )) && G_WHIP_DEFAULT_ITEM=0
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
(( $WIFI_REQUIRED )) && G_DIETPI-NOTIFY 2 'Marking WiFi as required' || G_DIETPI-NOTIFY 2 'Marking WiFi as NOT required'
# Distro Selection
DISTRO_LIST_ARRAY=(
'4' ': Stretch (oldstable, if SBC firmware is not yet Buster-compatible)'
'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 use 2 array indexs per whip displayed entry.
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 DISTRO_LIST_ARRAY
if (( ! ${#G_WHIP_MENU_ARRAY[@]} )); then
G_DIETPI-NOTIFY 1 'No available distro versions 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 $G_DISTRO_NAME"; 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 == 4 )); then
DISTRO_TARGET_NAME='stretch'
elif (( $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)"
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP: Downloading and installing DietPi sourcecode:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
local url="https://github.com/$G_GITOWNER/DietPi/archive/$G_GITBRANCH.zip"
G_CHECK_URL "$url"
G_RUN_CMD wget "$url" -O package.zip
[[ -d DietPi-$G_GITBRANCH ]] && l_message='Cleaning previously extracted files' G_RUN_CMD rm -R "DietPi-$G_GITBRANCH"
l_message='Extracting DietPi sourcecode' G_RUN_CMD unzip package.zip
rm package.zip
[[ -d '/boot' ]] || l_message='Creating /boot' G_RUN_CMD mkdir -p /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_RUN_CMD mv "DietPi-$G_GITBRANCH/config.txt" /boot/
elif (( $G_HW_MODEL == 11 )); then
G_RUN_CMD mv "DietPi-$G_GITBRANCH/boot_xu4.ini" /boot/boot.ini
elif (( $G_HW_MODEL == 12 )); then
G_RUN_CMD mv "DietPi-$G_GITBRANCH/boot_c2.ini" /boot/boot.ini
fi
G_RUN_CMD mv "DietPi-$G_GITBRANCH/dietpi.txt" /boot/
G_RUN_CMD mv "DietPi-$G_GITBRANCH/README.md" /boot/dietpi-README.md
G_RUN_CMD mv "DietPi-$G_GITBRANCH/CHANGELOG.txt" /boot/dietpi-CHANGELOG.txt
# Reading version string for later use
G_DIETPI_VERSION_CORE=$(sed -n 1p "DietPi-$G_GITBRANCH/dietpi/server_version-6")
G_DIETPI_VERSION_SUB=$(sed -n 2p "DietPi-$G_GITBRANCH/dietpi/server_version-6")
G_DIETPI_VERSION_RC=$(sed -n 3p "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"
l_message='Copy DietPi core files to /boot/dietpi' G_RUN_CMD cp -Rf "DietPi-$G_GITBRANCH/dietpi" /boot/
l_message='Copy DietPi rootfs files in place' G_RUN_CMD cp -Rf "DietPi-$G_GITBRANCH/rootfs"/. /
l_message='Clean download location' G_RUN_CMD rm -R "DietPi-$G_GITBRANCH"
l_message='Set execute permissions for DietPi scripts' G_RUN_CMD chmod -R +x /boot/dietpi /var/lib/dietpi/services /etc/cron.*/dietpi
G_RUN_CMD systemctl daemon-reload
G_RUN_CMD systemctl enable dietpi-ramdisk
# Mount tmpfs
G_RUN_CMD mkdir -p /DietPi
G_RUN_CMD mount -t tmpfs -o size=10m tmpfs /DietPi
l_message='Starting DietPi-RAMdisk' G_RUN_CMD systemctl start dietpi-ramdisk
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP: APT configuration:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
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 for Debian vs Raspbian decision.
G_DISTRO=$DISTRO_TARGET G_DISTRO_NAME=$DISTRO_TARGET_NAME G_HW_MODEL=$G_HW_MODEL G_RUN_CMD /DietPi/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@http://fuzon.co.uk@' /etc/apt/sources.list.d/meveric* &> /dev/null
# (Re)create DietPi logs dir, used by G_AGx
G_RUN_CMD mkdir -p /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'
G_RUN_CMD apt-mark auto $(apt-mark showmanual)
# @MichaIng https://github.com/MichaIng/DietPi/pull/1266/files
G_DIETPI-NOTIFY 2 'Disable automatic recommends/suggests install and allow them to be autoremoved:'
# - Remove any existing APT recommends settings
rm -f /etc/apt/apt.conf.d/*recommends*
G_ERROR_HANDLER_COMMAND='/etc/apt/apt.conf.d/99-dietpi-norecommends'
cat << _EOF_ > $G_ERROR_HANDLER_COMMAND
APT::Install-Recommends "false";
APT::Install-Suggests "false";
APT::AutoRemove::RecommendsImportant "false";
APT::AutoRemove::SuggestsImportant "false";
_EOF_
G_ERROR_HANDLER_EXITCODE=$?
G_ERROR_HANDLER
G_DIETPI-NOTIFY 2 'Disable package state translation downloads'
echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/98-dietpi-no_translations
G_DIETPI-NOTIFY 2 'Preserve modified config files on APT update:'
G_ERROR_HANDLER_COMMAND='/etc/apt/apt.conf.d/99-dietpi-forceconf'
cat << _EOF_ > $G_ERROR_HANDLER_COMMAND
Dpkg::options {
"--force-confdef";
"--force-confold";
}
_EOF_
G_ERROR_HANDLER_EXITCODE=$?
G_ERROR_HANDLER
# DietPi list of minimal required packages, which must be installed:
aPACKAGES_REQUIRED_INSTALL=(
'apt-transport-https' # Allows HTTPS sources for ATP
'apt-utils' # Allows "debconf" to pre-configure APT packages for non-interactive install
'bash-completion' # Auto completes a wide list of bash commands and options via <tab>
'bc' # Bash calculator, e.g. for floating point calculation
'bzip2' # (.tar).bz2 wrapper
'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.
'debconf' # APT package pre-configuration, e.g. "debconf-set-selections" for non-interactive install
'dirmngr' # GNU key management required for some APT installs via additional repos
'ethtool' # Ethernet link checking
'fake-hwclock' # Hardware clock emulation, to allow correct timestamps during boot before network time sync
'gnupg' # apt-key add
'htop' # System monitor
'iputils-ping' # "ping" command
'isc-dhcp-client' # DHCP client
'kmod' # "modprobe", "lsmod", used by several DietPi scripts
'locales' # Support locales, necessary for DietPi scripts, as we use en_GB.UTF8 as default language
'nano' # Simple text editor
'p7zip' # .7z wrapper
'parted' # partprobe + drive partitioning, required by DietPi-Drive_Manager
'procps' # "kill", "ps", "pgrep", "sysctl", used by several DietPi scripts
'psmisc' # "killall", used by several DietPi scripts
'resolvconf' # Network nameserver handler + depandant for "ifupdown" (network interface handler) => "iproute2" ("ip" command)
'sudo' # Root permission wrapper for users within /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
)
# G_DISTRO specific
# - Dropbear: DietPi default SSH-Client
# On Buster-, "dropbear" fulls in "dropbear-initramfs", which we don't need
if (( $G_DISTRO > 5 )); then
aPACKAGES_REQUIRED_INSTALL+=('dropbear')
else
aPACKAGES_REQUIRED_INSTALL+=('dropbear-run')
fi
# G_HW_MODEL specific required repo key packages: https://github.com/MichaIng/DietPi/issues/1285#issuecomment-358301273
if (( $G_HW_MODEL > 9 )); then
aPACKAGES_REQUIRED_INSTALL+=('initramfs-tools') # RAM file system initialisation, required for generic bootloader, but not required/used by RPi bootloader
aPACKAGES_REQUIRED_INSTALL+=('haveged') # Entropy daemon: https://github.com/MichaIng/DietPi/issues/2806
else
aPACKAGES_REQUIRED_INSTALL+=('rng-tools') # Entropy daemon: Alternative, that does not work on all devices, but is proven to work on RPi, is default on Raspbian and uses less RAM on idle.
fi
# WiFi related
if (( $WIFI_REQUIRED )); then
aPACKAGES_REQUIRED_INSTALL+=('crda') # WiFi related
aPACKAGES_REQUIRED_INSTALL+=('iw') # WiFi related
aPACKAGES_REQUIRED_INSTALL+=('rfkill') # WiFi related: Used by some onboard WiFi chipsets
aPACKAGES_REQUIRED_INSTALL+=('wireless-tools') # WiFi related
aPACKAGES_REQUIRED_INSTALL+=('wpasupplicant') # WiFi WPA(2) support
fi
# G_HW_MODEL specific
if (( $G_HW_MODEL != 20 )); then
aPACKAGES_REQUIRED_INSTALL+=('dosfstools') # DietPi-Drive_Manager + fat (boot) drive file system check and creation tools
aPACKAGES_REQUIRED_INSTALL+=('hdparm') # Drive power management adjustments
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
G_AGI linux-image-amd64 os-prober
# Grub EFI
if dpkg-query -s 'grub-efi-amd64' &> /dev/null || [[ -d '/boot/efi' ]]; then
local efi_packages='grub-efi-amd64'
# On Buster+ enable secure boot compatibility: https://packages.debian.org/buster/grub-efi-amd64-signed
(( $DISTRO_TARGET > 4 )) && efi_packages+=' grub-efi-amd64-signed shim-signed'
G_AGI $efi_packages
# Grub BIOS
else
G_AGI grub-pc
fi
# - G_HW_MODEL specific required Kernel packages
# ARMbian grab currently installed packages
elif dpkg --get-selections | grep -qi '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")
apt-mark hold $line
G_DIETPI-NOTIFY 2 "PKG detected and set on hold: $line"
done <<< "$(dpkg --get-selections | mawk -v pat="^$i" '$0~pat {print $1}')"
done
unset apackages
# RPi
elif (( $G_HW_MODEL < 10 )); then
G_AGI libraspberrypi-bin libraspberrypi0 raspberrypi-bootloader raspberrypi-kernel raspberrypi-sys-mods raspi-copies-and-fills
# Odroid N2
elif (( $G_HW_MODEL == 15 )); then
G_AGI linux-image-arm64-odroid-n2
# Odroid N1
elif (( $G_HW_MODEL == 14 )); then
G_AGI linux-image-arm64-odroid-n1
# Odroid C2
elif (( $G_HW_MODEL == 12 )); then
G_AGI linux-image-arm64-odroid-c2
# Odroid XU3/4/HC1/HC2
elif (( $G_HW_MODEL == 11 )); then
G_AGI linux-image-4.14-armhf-odroid-xu4
# BBB
elif (( $G_HW_MODEL == 71 )); then
G_AGI device-tree-compiler # dtoverlay compiler
# - Auto detect kernel package incl. ARMbian/others DTB
else
AUTO_DETECT_KERN_PKG=$(dpkg --get-selections | mawk '/^linux-(image|dtb)/ {print $1}')
if [[ $AUTO_DETECT_KERN_PKG ]]; then
G_AGI $AUTO_DETECT_KERN_PKG
else
G_DIETPI-NOTIFY 2 'Unable to find kernel packages for installation. Assuming non-APT/.deb kernel installation.'
fi
fi
# - Firmware
if dpkg --get-selections | 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'
l_message='Marking required packages as manually installed' G_RUN_CMD apt-mark manual ${aPACKAGES_REQUIRED_INSTALL[@]}
# Workaround: Installing required packages which would be autoremoved below due to missing dependants
# - resolvconf to prevent ifupdown removal on Buster mini.iso
G_AGI resolvconf
# 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.
# - dhcpcd5: https://github.com/MichaIng/DietPi/issues/1560#issuecomment-370136642
# - mountall: https://github.com/MichaIng/DietPi/issues/2613
G_AGP dbus dhcpcd5 mountall
# Remove any autoremove prevention
rm -f /etc/apt/apt.conf.d/01autoremove*
G_AGA
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP: APT installations:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
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 DISTRO_TARGET DISTRO_TARGET_NAME
G_DIETPI-NOTIFY 2 'Installing core DietPi pre-req APT packages'
G_AGI ${aPACKAGES_REQUIRED_INSTALL[@]}
unset aPACKAGES_REQUIRED_INSTALL
G_AGA
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP: Prep system for DietPi ENV:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
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 linaro &> /dev/null && userdel -f linaro # ASUS TB
getent passwd dietpi &> /dev/null && userdel -f dietpi # recreated below
getent passwd debian &> /dev/null && userdel -f debian # BBB
getent passwd openmediavault-webgui &> /dev/null && userdel -f openmediavault-webgui # OMV (NanoPi NEO2)
getent passwd admin &> /dev/null && userdel -f admin # OMV (NanoPi NEO2)
getent passwd fa &> /dev/null && userdel -f fa # OMV (NanoPi NEO2)
getent passwd colord &> /dev/null && userdel -f colord # OMV (NanoPi NEO2)