-
-
Notifications
You must be signed in to change notification settings - Fork 501
/
PREP_SYSTEM_FOR_DIETPI.sh
1683 lines (1197 loc) · 56.1 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
#------------------------------------------------------------------------------------------------
#Core globals
G_PROGRAM_NAME='DietPi-PREP'
GITOWNER=${GITOWNER:-Fourdee}
#------------------------------------------------------------------------------------------------
# Critical checks and pre-reqs, with exit, prior to initial run of script
#------------------------------------------------------------------------------------------------
#Exit path for non-root logins
if (( $UID )); then
echo -e 'ERROR: 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/Fourdee/DietPi/pull/2341#discussion_r241784962
FP_PREP_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cd /tmp
#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
# - APT
echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99-dietpi-force-ipv4
# - Wget
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
#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/Fourdee/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&p=10646#p10594
[[ -f /etc/apt/sources.list.d/openmediavault.list ]] && rm /etc/apt/sources.list.d/openmediavault.list
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
#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 LANG=en_GB.UTF-8
update-locale LC_CTYPE=en_GB.UTF-8
update-locale LC_TIME=en_GB.UTF-8
update-locale LC_ALL=en_GB.UTF-8
# - Export locale vars to assure the following whiptail being beautiful
export LANG=en_GB.UTF8
export LC_ALL=en_GB.UTF8
#Select gitbranch
aWHIP_BRANCH=(
'master' ': Stable release (recommended)'
'beta' ': Public beta testing branch'
'dev' ': Unstable dev branch'
)
if WHIP_RETURN=$(whiptail --title "$G_PROGRAM_NAME" --menu 'Please select a Git branch:' --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
GITBRANCH=$WHIP_RETURN
else
echo -e '[ INFO ] No choice detected. Aborting...\n'
exit 0
fi
unset aWHIP_BRANCH WHIP_RETURN
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
DISTRO_TARGET=0
DISTRO_TARGET_NAME=''
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'
else
G_DIETPI-NOTIFY 1 'Unknown or unsupported distribution version. Aborting...\n'
exit 1
fi
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
#WiFi install flag
WIFI_REQUIRED=0
#Image creator flags
IMAGE_CREATOR=''
PREIMAGE_INFO=''
#Setup step, current (used in info)
SETUP_STEP=0
#URL connection test var holder
INTERNET_ADDRESS=''
Main(){
#------------------------------------------------------------------------------------------------
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, running pre-prep'
# - Stop services
[[ -f /DietPi/dietpi/dietpi-services ]] && /DietPi/dietpi/dietpi-services stop
[[ -f /etc/systemd/system/dietpi-ramdisk.service ]] && systemctl stop dietpi-ramdisk
[[ -f /etc/systemd/system/dietpi-ramlog.service ]] && systemctl stop dietpi-ramlog
# - Delete any previous existing data
# Failsafe
umount /DietPi
[[ -d /DietPi ]] && rm -R /DietPi
[[ -d /boot/dietpi ]] && rm -R /boot/dietpi
[[ -d /mnt/dietpi-backup ]] && rm -R /mnt/dietpi-backup
[[ -d /mnt/dietpi-sync ]] && rm -R /mnt/dietpi-sync
[[ -d /mnt/dietpi_userdata ]] && rm -R /mnt/dietpi_userdata
[[ -d /etc/dietpi ]] && rm -R /etc/dietpi # Pre v160
[[ -d /var/lib/dietpi ]] && rm -R /var/lib/dietpi
[[ -d /var/tmp/dietpi ]] && rm -R /var/tmp/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 (inputs): Image info / Hardware / WiFi / Distro:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
#Image creator
while :
do
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.'
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
G_DIETPI-NOTIFY 2 "Entered image creator: $IMAGE_CREATOR"
break
fi
fi
done
#Pre-image used/name
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
G_DIETPI-NOTIFY 2 "Entered pre-image info: $PREIMAGE_INFO"
break
fi
done
#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) '
'52' ': ASUS Tinker Board'
'10' ': Odroid C1'
'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+'
'' '●─ PC '
'21' ': x86_64 Native PC'
'20' ': x86_64 VMware/VirtualBox'
'' '●─ SBC─(Limited support devices, no GPU support) '
'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'
'14' ': Odroid N1'
'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'
)
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 (( $? )) || [[ -z $G_WHIP_RETURNED_VALUE ]]; then
G_DIETPI-NOTIFY 1 'No choice detected. Aborting...\n'
exit 0
fi
# + Set for future scripts
G_HW_MODEL=$G_WHIP_RETURNED_VALUE
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)"
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:' && (( $G_WHIP_RETURNED_VALUE )); then
G_DIETPI-NOTIFY 2 'Marking WiFi as required'
WIFI_REQUIRED=1
else
G_DIETPI-NOTIFY 2 'Marking WiFi as NOT required'
fi
#Distro Selection
DISTRO_LIST_ARRAY=(
'4' ': Stretch (current stable release, recommended)'
'5' ': Buster (testing only, not officially supported)'
)
# - 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 [[ -z ${G_WHIP_MENU_ARRAY+x} ]]; then
G_DIETPI-NOTIFY 1 'No available distro versions for this system. Aborting...\n'
exit 1
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'
G_WHIP_MENU "Please select a distro version to install on this system. Selecting a distro that is older than the current installed on system, is not supported.\n\nCurrently installed:\n - $G_DISTRO $G_DISTRO_NAME"
if (( $? )) || [[ -z $G_WHIP_RETURNED_VALUE ]]; then
G_DIETPI-NOTIFY 1 'No choice detected. Aborting...\n'
exit 0
fi
DISTRO_TARGET=$G_WHIP_RETURNED_VALUE
if (( $DISTRO_TARGET == 4 )); then
DISTRO_TARGET_NAME='stretch'
elif (( $DISTRO_TARGET == 5 )); then
DISTRO_TARGET_NAME='buster'
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 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
INTERNET_ADDRESS="https://github.com/$GITOWNER/DietPi/archive/$GITBRANCH.zip"
G_CHECK_URL "$INTERNET_ADDRESS"
G_RUN_CMD wget "$INTERNET_ADDRESS" -O package.zip
[[ -d DietPi-$GITBRANCH ]] && l_message='Cleaning previously extracted files' G_RUN_CMD rm -R "DietPi-$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-$GITBRANCH/config.txt" /boot/
elif (( $G_HW_MODEL == 10 )); then
G_RUN_CMD mv "DietPi-$GITBRANCH/boot_c1.ini" /boot/boot.ini
elif (( $G_HW_MODEL == 11 )); then
G_RUN_CMD mv "DietPi-$GITBRANCH/boot_xu4.ini" /boot/boot.ini
elif (( $G_HW_MODEL == 12 )); then
G_RUN_CMD mv "DietPi-$GITBRANCH/boot_c2.ini" /boot/boot.ini
fi
G_RUN_CMD mv "DietPi-$GITBRANCH/dietpi.txt" /boot/
G_RUN_CMD mv "DietPi-$GITBRANCH/README.md" /boot/dietpi-README.md
G_RUN_CMD mv "DietPi-$GITBRANCH/CHANGELOG.txt" /boot/dietpi-CHANGELOG.txt
# - Remove server_version* / (pre-)patch_file (downloads fresh from dietpi-update)
rm "DietPi-$GITBRANCH/dietpi/server_version"*
rm "DietPi-$GITBRANCH/dietpi/pre-patch_file"
rm "DietPi-$GITBRANCH/dietpi/patch_file"
l_message='Copy DietPi core files to /boot/dietpi' G_RUN_CMD cp -Rf "DietPi-$GITBRANCH/dietpi" /boot/
l_message='Copy DietPi rootfs files in place' G_RUN_CMD cp -Rf "DietPi-$GITBRANCH/rootfs"/. /
l_message='Clean download location' G_RUN_CMD rm -R "DietPi-$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
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/Fourdee/DietPi/issues/1519#issuecomment-368234302
sed -i 's@https://oph.mdrjr.net/meveric@http://fuzon.co.uk/meveric@' /etc/apt/sources.list.d/meveric* &> /dev/null
# - (Re)create DietPi logs dir, used by G_AGx
G_RUN_CMD mkdir -p /var/tmp/dietpi/logs
G_AGUP
# - @MichaIng https://github.com/Fourdee/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/Fourdee/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 '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-full' # .7z wrapper
'parted' # Drive partitioning, required by DietPi-Boot + 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_HW_MODEL specific required repo key packages: https://github.com/Fourdee/DietPi/issues/1285#issuecomment-358301273
if (( $G_HW_MODEL >= 10 )); then
G_AGI debian-archive-keyring
aPACKAGES_REQUIRED_INSTALL+=('initramfs-tools') # RAM file system initialization, required for generic boot loader, but not required/used by RPi bootloader
else
G_AGI raspbian-archive-keyring
fi
# - WiFi related packages
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_DISTRO specific required packages:
if (( $G_DISTRO < 4 )); then
aPACKAGES_REQUIRED_INSTALL+=('dropbear') # DietPi default SSH-Client
else
aPACKAGES_REQUIRED_INSTALL+=('dropbear-run') # DietPi default SSH-Client (excluding initramfs integration, available since Stretch)
fi
# - G_HW_MODEL specific required packages:
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 required packages
# - G_HW_ARCH specific required Kernel packages
# As these are kernel, or bootloader packages, we need to install them directly to allow autoremove of in case older kernel packages:
# https://github.com/Fourdee/DietPi/issues/1285#issuecomment-354602594
# 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
G_AGI grub-efi-amd64
# 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=(
"armbian-tools-$DISTRO_TARGET_NAME"
"linux-dtb-"
"linux-u-"
"linux-image-"
"linux-$DISTRO_TARGET_NAME"
'sunxi'
)
for i in "${apackages[@]}"
do
while read -r line
do
if [[ $line ]]; then
aPACKAGES_REQUIRED_INSTALL+=("$line")
apt-mark hold $line
G_DIETPI-NOTIFY 2 "PKG detected and set on hold: $line"
fi
done <<< "$(dpkg --get-selections | mawk -v pat="^$i" '$0~pat {print $1}')"
done
unset apackages
# RPi
elif (( $G_HW_MODEL < 10 )); then
apt-mark unhold libraspberrypi-bin libraspberrypi0 raspberrypi-bootloader raspberrypi-kernel raspberrypi-sys-mods raspi-copies-and-fills
rm -Rf /lib/modules/*
G_AGI libraspberrypi-bin libraspberrypi0 raspberrypi-bootloader raspberrypi-kernel raspberrypi-sys-mods
G_AGI --reinstall libraspberrypi-bin libraspberrypi0 raspberrypi-bootloader raspberrypi-kernel
# Buster systemd-udevd doesn't support the current raspi-copies-and-fills: https://github.com/Fourdee/DietPi/issues/1286
(( $DISTRO_TARGET < 5 )) && G_AGI raspi-copies-and-fills
# Odroid N1
elif (( $G_HW_MODEL == 14 )); then
G_AGI linux-image-arm64-odroid-n1
#G_AGI libdrm-rockchip1 #Not currently on meveric's repo
# 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.9-armhf-odroid-xu3
G_AGI $(dpkg --get-selections | mawk '/^linux-image/ {print $1}')
dpkg --get-selections | grep -q '^linux-image' || G_AGI linux-image-4.14-armhf-odroid-xu4
# Odroid C1
elif (( $G_HW_MODEL == 10 )); then
G_AGI linux-image-armhf-odroid-c1
# BBB
elif (( $G_HW_MODEL == 71 )); then
G_AGI device-tree-compiler #Kern
# - Auto detect kernel package incl. ARMbian/others DTB
else
AUTO_DETECT_KERN_PKG=$(dpkg --get-selections | grep -E '^linux-(image|dtb)' | awk '{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') # Eth/WiFi/BT dongle firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-linux-nonfree')
fi
if (( $WIFI_REQUIRED )); then
aPACKAGES_REQUIRED_INSTALL+=('firmware-atheros') # WiFi dongle firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-brcm80211') # WiFi dongle firmware
aPACKAGES_REQUIRED_INSTALL+=('firmware-iwlwifi') # Intel WiFi dongle/PCI-e firwmare
# Intel/Nvidia/WiFi (ralink) dongle firmware: https://github.com/Fourdee/DietPi/issues/1675#issuecomment-377806609
# On Jessie, firmware-misc-nonfree is not available, firmware-ralink instead as dedicated package.
if (( $G_DISTRO < 4 )); then
aPACKAGES_REQUIRED_INSTALL+=('firmware-ralink')
else
aPACKAGES_REQUIRED_INSTALL+=('firmware-misc-nonfree')
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[@]}
# Purging additional packages, that (in some cases) do not get autoremoved:
# - dhcpcd5: https://github.com/Fourdee/DietPi/issues/1560#issuecomment-370136642
# - dbus: Not required for headless images, but sometimes marked as "important", thus not autoremoved.
G_AGP dbus dhcpcd5
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
G_DIETPI-NOTIFY 2 'Installing core DietPi pre-req APT packages'
G_AGI ${aPACKAGES_REQUIRED_INSTALL[@]}
unset aPACKAGES_REQUIRED_INSTALL
G_AGA
# Reenable HTTPS for deb.debian.org, since system was dist-upgraded to Stretch+
(( $G_HW_MODEL > 9 )) && sed -i 's/http:/https:/g' /etc/apt/sources.list
#------------------------------------------------------------------------------------------------
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, 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
G_DIETPI-NOTIFY 2 'Removing misc files/folders/services, not required by DietPi'
[[ -d /home ]] && rm -R /home
[[ -d /media ]] && rm -R /media
[[ -d /selinux ]] && rm -R /selinux
# - www
[[ -d /var/www ]] && rm -Rf /var/www/{,.??,.[^.]}*
# - sourcecode (linux-headers etc)
[[ -d /usr/src ]] && rm -Rf /usr/src/{,.??,.[^.]}*
# - root
[[ -e /root/.cache ]] && rm -R /root/.cache
[[ -e /root/.local ]] && rm -R /root/.local
[[ -e /root/.config ]] && rm -R /root/.config
# - documentation folders
[[ -d /usr/share/man ]] && rm -R /usr/share/man
[[ -d /usr/share/doc ]] && rm -R /usr/share/doc
[[ -d /usr/share/doc-base ]] && rm -R /usr/share/doc-base
[[ -d /usr/share/calendar ]] && rm -R /usr/share/calendar
# - Previous debconfs
rm -f /var/cache/debconf/*-old
# - Fonts
[[ -d /usr/share/fonts ]] && rm -R /usr/share/fonts
[[ -d /usr/share/icons ]] && rm -R /usr/share/icons
# - Stop, disable and remove not required services
local aservices=(
# - ARMbian
'firstrun'
'resize2fs'
'log2ram'
'armbian*'
# - Meveric
'cpu_governor'
)
for i in ${aservices[@]}
do
# Loop through known service locations
for j in /etc/init.d/$i /etc/systemd/system/$i.service /etc/systemd/system/$i.service.d /lib/systemd/system/$i.service /lib/systemd/system/$i.service.d
do
if [[ -e $j ]]; then
if [[ -f $j ]]; then
systemctl stop ${j##*/}
systemctl disable ${j##*/}
fi
rm -R $j
fi
done
done
systemctl daemon-reload
# - ARMbian
[[ -f /usr/local/sbin/log2ram ]] && rm /usr/local/sbin/log2ram
[[ -f /usr/bin/armbianmonitor ]] && rm /usr/bin/armbianmonitor
[[ -d /usr/lib/armbian ]] && rm -R /usr/lib/armbian
[[ -d /usr/share/armbian ]] && rm -R /usr/share/armbian
rm -f /etc/profile.d/armbian*
#rm -Rf /etc/armbian* armbian-release required for kernel package update success.
rm -Rf /etc/default/armbian*
rm -Rf /etc/update-motd.d/*armbian*
rm -Rf /etc/X11/xorg.conf.d/*armbian*
rm -f /etc/cron.*/armbian*
[[ -f /boot/armbian_first_run.txt.template ]] && rm /boot/armbian_first_run.txt.template
umount /var/log.hdd 2> /dev/null
[[ -d /var/log.hdd ]] && rm -R /var/log.hdd
# - Meveric specific
[[ -f /usr/local/sbin/setup-odroid ]] && rm /usr/local/sbin/setup-odroid
# - RPi specific https://github.com/Fourdee/DietPi/issues/1631#issuecomment-373965406
[[ -f /etc/profile.d/wifi-country.sh ]] && rm /etc/profile.d/wifi-country.sh
# - make_nas_processes_faster cron job on Rock64 + NanoPi + Pine64(?) images
[[ -f /etc/cron.d/make_nas_processes_faster ]] && rm /etc/cron.d/make_nas_processes_faster
#-----------------------------------------------------------------------------------
#Boot Logo
[[ -f /boot/boot.bmp ]] && G_RUN_CMD wget https://github.com/$GITOWNER/DietPi/raw/$GITBRANCH/.meta/images/dietpi-logo_boot.bmp -O /boot/boot.bmp
#-----------------------------------------------------------------------------------
#Bash Profiles