forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PREP_SYSTEM_FOR_DIETPI.sh
1547 lines (1080 loc) · 50.5 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 =)) )
# - Active eth0 connection
#------------------------------------------------------------------------------------------------
# Dev notes:
# Following items must be exported at all times, throughout this script, else, additional scripts launched will trigger incorrect results.
# - G_HW_MODEL
# - G_HW_ARCH
# - G_DISTRO
#------------------------------------------------------------------------------------------------
#Use Fourdee master branch, if unset
GIT_OWNER=${GIT_OWNER:=Fourdee}
GIT_BRANCH=${GIT_BRANCH:=master}
echo "Git branch: $GIT_OWNER/$GIT_BRANCH"
#------------------------------------------------------------------------------------------------
# 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
mkdir -p /tmp/dietpi-prep
cd /tmp/dietpi-prep
#Check/install minimal APT Pre-Reqs
a_MIN_APT_PREREQS=(
'wget' # Download DietPi-Globals...
'ca-certificates' # ...via HTTPS
'locales' # Allow ensuring en_GB.UTF-8
'whiptail' # G_WHIP...
'ncurses-bin' # ...using tput
)
# - Meveric special: https://github.com/Fourdee/DietPi/issues/1285#issuecomment-355759321
rm /etc/apt/sources.list.d/deb-multimedia.list &> /dev/null
# - APT force IPv4
echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99-dietpi-force-ipv4
apt-get clean
apt-get update
for (( i=0; i<${#a_MIN_APT_PREREQS[@]}; i++))
do
if ! dpkg --get-selections | grep -qi "^${a_MIN_APT_PREREQS[$i]}[[:space:]]"; then
apt-get install -y ${a_MIN_APT_PREREQS[$i]}
if (( $? )); then
echo -e "Error: Unable to install ${a_MIN_APT_PREREQS[$i]}, please try to install it manually:\n\t# apt-get install -y ${a_MIN_APT_PREREQS[$i]}"
exit 1
fi
fi
done
unset a_MIN_APT_PREREQS
#Setup locale
# - Remove exisiting settings that will break dpkg-reconfigure
> /etc/environment
rm /etc/default/locale &> /dev/null
# - 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 -f noninteractive locales
# - 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 (( $? )); then
echo -e 'Error: 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
# - Force en_GB Locale for rest of script. Prevents incorrect parsing with non-english locales.
export LC_ALL=en_GB.UTF-8
export LANG=en_GB.UTF-8
#------------------------------------------------------------------------------------------------
#Globals
#------------------------------------------------------------------------------------------------
#Download DietPi-Globals
# - NB: We'll have to manually handle errors, until DietPi-Globals are sucessfully loaded.
# - Wget prefer IPv4
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
wget "https://raw.githubusercontent.com/$GIT_OWNER/DietPi/$GIT_BRANCH/dietpi/func/dietpi-globals"
if (( $? )); then
echo -e 'Error: Unable to download dietpi-globals. Aborting...\n'
exit 1
fi
# - Load
. ./dietpi-globals
if (( $? )); then
echo -e 'Error: Unable to load dietpi-globals. Aborting...\n'
exit 1
fi
# Go back to tmp working dir, as loading global includes cd $HOME:
cd /tmp/dietpi-prep
rm dietpi-globals
export G_PROGRAM_NAME='DietPi-PREP'
export HIERARCHY=0
export G_DISTRO=0 # Export to dietpi-globals
export G_DISTRO_NAME='NULL' # Export to dietpi-globals
DISTRO_TARGET=0
DISTRO_TARGET_NAME=''
if grep -q 'wheezy' /etc/os-release; then
G_DISTRO=2
G_DISTRO_NAME='wheezy'
elif 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_MODEL # init from dietpi-globals
#G_HW_ARCH_DESCRIPTION # init from dietpi-globals
G_HW_ARCH_DESCRIPTION="$(uname -m)"
if [[ $G_HW_ARCH_DESCRIPTION == 'armv6l' ]]; then
export G_HW_ARCH=1
elif [[ $G_HW_ARCH_DESCRIPTION == 'armv7l' ]]; then
export G_HW_ARCH=2
elif [[ $G_HW_ARCH_DESCRIPTION == 'aarch64' ]]; then
export G_HW_ARCH=3
elif [[ $G_HW_ARCH_DESCRIPTION == 'x86_64' ]]; then
export G_HW_ARCH=10
else
G_DIETPI-NOTIFY 1 "Error: 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 systemctl is-active dietpi-ramdisk | grep -qi '^active'; then
G_DIETPI-NOTIFY 2 'DietPi system found, running pre-prep'
# - Stop services
/DietPi/dietpi/dietpi-services stop
[[ -f /etc/systemd/system/dietpi-ramlog ]] && G_RUN_CMD systemctl stop dietpi-ramlog
G_RUN_CMD systemctl stop dietpi-ramdisk
# - Delete any previous existing data
rm -R /DietPi/*
rm -R /boot/dietpi
rm -R /mnt/dietpi-backup &> /dev/null
rm -R /mnt/dietpi-sync &> /dev/null
rm -R /mnt/dietpi_userdata &> /dev/null
rm -R /etc/dietpi &> /dev/null # Pre v160
rm -R /var/lib/dietpi &> /dev/null
rm -R /var/tmp/dietpi &> /dev/null
rm /root/DietPi-Automation.log &> /dev/null
rm /boot/Automation_Format_My_Usb_Drive &> /dev/null
else
G_DIETPI-NOTIFY 2 'Non-DietPi system'
fi
#------------------------------------------------------------------------------------------------
echo ''
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
G_DIETPI-NOTIFY 0 "Step $SETUP_STEP: Initial prep to allow this script to function:"
((SETUP_STEP++))
G_DIETPI-NOTIFY 2 '-----------------------------------------------------------------------------------'
#------------------------------------------------------------------------------------------------
#Recreate dietpi logs dir, used by G_AGx
G_RUN_CMD mkdir -p /var/tmp/dietpi/logs
G_DIETPI-NOTIFY 2 'Installing core packages, required for next stage of this script:'
G_AGI apt-transport-https unzip
#------------------------------------------------------------------------------------------------
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 true
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 contanct 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'
)
LOWERCASE_TEMP="$(echo $G_WHIP_RETURNED_VALUE | tr '[:upper:]' '[:lower:]')"
for (( i=0; i<${#aDISALLOWED_NAMES[@]}; i++))
do
if [[ $LOWERCASE_TEMP == *"${aDISALLOWED_NAMES[$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
#Pre-image used/name
while true
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
#Hardware selection
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) '
'10' 'Odroid C1'
'12' 'Odroid C2'
'14' 'Odroid N1'
'13' 'Odroid U3'
'11' 'Odroid XU3/4/HC1/HC2'
'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) '
'52' 'Asus Tinker Board'
'53' 'BananaPi (sinovoip)'
'51' 'BananaPi Pro (Lemaker)'
'50' 'BananaPi M2+ (sinovoip)'
'71' 'Beagle Bone Black'
'39' 'LeMaker Guitar'
'68' 'NanoPC T4'
'67' 'NanoPi K1 Plus'
'66' 'NanoPi M1 Plus'
'65' 'NanoPi NEO 2'
'64' 'NanoPi NEO Air'
'63' 'NanoPi M1/T1'
'62' 'NanoPi M3/T3/F3'
'61' 'NanoPi M2/T2'
'60' 'NanoPi Neo'
'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 choices detected. Aborting...'
exit 0
fi
# + Export to future scripts
export G_HW_MODEL=$G_WHIP_RETURNED_VALUE
G_DIETPI-NOTIFY 2 "Setting G_HW_MODEL index of: $G_HW_MODEL"
G_DIETPI-NOTIFY 2 "CPU ARCH = $G_HW_ARCH : $G_HW_ARCH_DESCRIPTION"
echo "$G_HW_MODEL" > /etc/.dietpi_hw_model_identifier
#WiFi selection
G_DIETPI-NOTIFY 2 'WiFi selection'
G_WHIP_DEFAULT_ITEM=1
G_WHIP_MENU_ARRAY=(
'0' "I don't require WiFi, do not install."
'1' 'I require WiFi functionality, keep/install related packages.'
)
G_WHIP_MENU 'Please select an option:'
if (( ! $? && $G_WHIP_RETURNED_VALUE == 1 )); then
G_DIETPI-NOTIFY 2 'Marking WiFi as needed'
WIFI_REQUIRED=1
fi
#Distro Selection
G_WHIP_DEFAULT_ITEM=$G_DISTRO
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
DISTRO_LIST_ARRAY=(
'3' 'Jessie (oldstable, just if you need to avoid upgrade to current release)'
'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[@]} / 2 )); i++))
do
temp_distro_available=1
temp_distro_index=$(( $i + 3 ))
# - Disable downgrades
if (( $temp_distro_index < $G_DISTRO )); then
G_DIETPI-NOTIFY 2 "Disabled Distro downgrade: index $temp_distro_index"
temp_distro_available=0
fi
# - Enable option
if (( $temp_distro_available )); then
G_WHIP_MENU_ARRAY+=( "${DISTRO_LIST_ARRAY[$(( $i * 2 ))]}" "${DISTRO_LIST_ARRAY[$(( ($i * 2) + 1 ))]}" )
fi
done
#delete []
unset DISTRO_LIST_ARRAY
if [[ -z ${G_WHIP_MENU_ARRAY+x} ]]; then
G_DIETPI-NOTIFY 1 'Error: No available Distros for this system. Aborting...'
exit 1
fi
G_WHIP_MENU "Please select a distro 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 choices detected. Aborting...'
exit 0
fi
DISTRO_TARGET=$G_WHIP_RETURNED_VALUE
if (( $DISTRO_TARGET == 3 )); then
DISTRO_TARGET_NAME='jessie'
elif (( $DISTRO_TARGET == 4 )); then
DISTRO_TARGET_NAME='stretch'
elif (( $DISTRO_TARGET == 5 )); then
DISTRO_TARGET_NAME='buster'
fi
#------------------------------------------------------------------------------------------------
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/$GIT_OWNER/DietPi/archive/$GIT_BRANCH.zip"
G_CHECK_URL "$INTERNET_ADDRESS"
G_RUN_CMD wget "$INTERNET_ADDRESS" -O package.zip
[[ -d DietPi-$GIT_BRANCH ]] && l_message='Cleaning previously extracted files' G_RUN_CMD rm -R "DietPi-$GIT_BRANCH"
l_message='Extracting DietPi sourcecode' G_RUN_CMD unzip -o package.zip
rm package.zip
l_message='Creating /boot' G_RUN_CMD mkdir -p /boot
G_DIETPI-NOTIFY 2 'Moving kernel and boot configuration to /boot'
G_RUN_CMD mv "DietPi-$GIT_BRANCH/dietpi.txt" /boot/
# - HW specific config.txt, boot.ini uEnv.txt
if (( $G_HW_MODEL < 10 )); then
G_RUN_CMD mv "DietPi-$GIT_BRANCH/config.txt" /boot/
elif (( $G_HW_MODEL == 10 )); then
G_RUN_CMD mv "DietPi-$GIT_BRANCH/boot_c1.ini" /boot/boot.ini
elif (( $G_HW_MODEL == 11 )); then
G_RUN_CMD mv "DietPi-$GIT_BRANCH/boot_xu4.ini" /boot/boot.ini
elif (( $G_HW_MODEL == 12 )); then
G_RUN_CMD mv "DietPi-$GIT_BRANCH/boot_c2.ini" /boot/boot.ini
fi
G_RUN_CMD mv "DietPi-$GIT_BRANCH/README.md" /boot/
#G_RUN_CMD mv "DietPi-$GIT_BRANCH/CHANGELOG.txt" /boot/
# - Remove server_version / patch_file (downloads fresh from dietpi-update)
rm "DietPi-$GIT_BRANCH/dietpi/patch_file"
rm DietPi-"$GIT_BRANCH"/dietpi/server_version*
l_message='Move DietPi core to /boot/dietpi' G_RUN_CMD mv "DietPi-$GIT_BRANCH/dietpi" /boot/
l_message='Copy rootfs files in place' G_RUN_CMD cp -Rf DietPi-"$GIT_BRANCH"/rootfs/. /
l_message='Clean download location' G_RUN_CMD rm -R "DietPi-$GIT_BRANCH"
l_message='Set execute permissions for DietPi scripts' G_RUN_CMD chmod -R +x /boot/dietpi /etc/cron.*/dietpi /var/lib/dietpi/services
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=20m 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 'Removing conflicting /etc/apt/sources.list.d entries'
# NB: Apt sources will get overwritten during 1st run, via boot script and dietpi.txt entry
#rm /etc/apt/sources.list.d/* &> /dev/null #Probably a bad idea
#rm /etc/apt/sources.list.d/deb-multimedia.list &> /dev/null #meveric, already done above
rm /etc/apt/sources.list.d/openmediavault.list &> /dev/null #http://dietpi.com/phpbb/viewtopic.php?f=11&t=2772&p=10646#p10594
G_DIETPI-NOTIFY 2 "Setting APT sources.list: $DISTRO_TARGET_NAME $DISTRO_TARGET"
# - We need to temp export target DISTRO vars, then revert them to current, after setting sources.list
G_DISTRO_TEMP=$G_DISTRO
G_DISTRO_NAME_TEMP="$G_DISTRO_NAME"
export G_DISTRO=$DISTRO_TARGET
export G_DISTRO_NAME="$DISTRO_TARGET_NAME"
G_RUN_CMD /DietPi/dietpi/func/dietpi-set_software apt-mirror 'default'
export G_DISTRO=$G_DISTRO_TEMP
export G_DISTRO_NAME="$G_DISTRO_NAME_TEMP"
unset G_DISTRO_TEMP
unset G_DISTRO_NAME_TEMP
# - 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
G_DIETPI-NOTIFY 2 "Updating APT for $DISTRO_TARGET_NAME:"
G_RUN_CMD apt-get clean
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 installation and allow them to be autoremoved:'
# Remove any existing apt recommends settings
rm /etc/apt/apt.conf.d/*recommends* &> /dev/null
export 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_
export G_ERROR_HANDLER_EXITCODE=$?
G_ERROR_HANDLER
G_DIETPI-NOTIFY 2 'Forcing use of modified package configs'
export 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_
export 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 in ATP
'apt-utils' # Allows debconf to preconfigure APT packages before installing
'bash-completion' # Auto completes a wide list of bash commands
'bc' # Floating point calculation within bash
'bzip2' # .bz2 wrapper
'ca-certificates' # Adds known ca-certificates, necessary to practically access HTTPS sources
'console-setup' # DietPi-Config keyboard configuration
'cron' # Background job scheduler
'curl' # Web address testing, downloading, uploading etc.
'debconf' # APT package pre-configuration, e.g. "debconf-set-selections"
'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
'hfsplus' # DietPi-Drive_Manager NTS (MacOS) file system support
'htop' # System monitor
'initramfs-tools' # RAM file system initialization
'iputils-ping' # ping command + dependant of iproute2 ("ip" commands)
'isc-dhcp-client' # DHCP client
'locales' # Support locales, necessary for DietPi scripts, as we use enGB.UTF8 as default language
'nano' # Simple text editor
'ntfs-3g' # DietPi-Drive_Manager NTPS (Windows) file system support
'p7zip-full' # .7z wrapper
'parted' # DietPi-Boot + DietPi-Drive_Manager
'psmisc' # DietPi-Boot + DietPi-Software: e.g. killall
'resolvconf' # System nameserver updater
'sudo' # DietPi-Software + general use
'systemd-sysv' # Includes systemd and additional commands: poweroff, shutdown etc.
'tzdata' # Time zone data for system clock, auto summer/winter time adjustment
'unzip' # .zip unpacker
'usbutils' # DietPi-Software + DietPi-Bugreport: e.g. lsusb
'wget' # Download tool
'whiptail' # DietPi dialogs
)
if (( $WIFI_REQUIRED )); then
aPACKAGES_REQUIRED_INSTALL+=('crda') # WiFi related
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
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 related
# 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
# - 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 repo key packages: https://github.com/Fourdee/DietPi/issues/1285#issuecomment-358301273
if (( $G_HW_MODEL >= 10 )); then
G_AGI debian-archive-keyring
else
G_AGI raspbian-archive-keyring
fi
# - G_HW_MODEL specific required packages:
# VM: No network firmware necessary and hard drive power management stays at host system.
if (( $G_HW_MODEL != 20 )); then
G_AGI firmware-realtek # Eth/WiFi/BT dongle firmware
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, firmware 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
# Usually no firmware should be necessary for VMs. If user manually passes though some USB device, he might need to install the firmware then.
(( $G_HW_MODEL != 20 )) && G_AGI firmware-linux-nonfree
# Grub EFI
if dpkg --get-selections | grep -q '^grub-efi-amd64' ||
[[ -d '/boot/efi' ]]; then
G_AGI grub-efi-amd64
# Grub BIOS
else
G_AGI grub-pc
fi
# - G_HW_MODEL specific required Kernel packages
# 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 -R /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 | grep '^linux-image' | awk '{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
# RockPro64
elif (( $G_HW_MODEL == 42 )); then
G_AGI linux-rockpro64 linux-rockpro64-package
# Rock64
elif (( $G_HW_MODEL == 43 )); then
G_AGI linux-rock64-package gdisk
# BBB
elif (( $G_HW_MODEL == 71 )); then
G_AGI device-tree-compiler #Kern
# - Auto detect kernel/firmware package
else
AUTO_DETECT_KERN_PKG=$(dpkg --get-selections | grep '^linux-image' | awk '{print $1}')
if [[ $AUTO_DETECT_KERN_PKG ]]; then
# - Install kern package if it exists in cache, else, mark manual #: https://github.com/Fourdee/DietPi/issues/1651#issuecomment-376974917
if [[ $(apt-cache search ^$AUTO_DETECT_KERN_PKG) ]]; then
G_AGI $AUTO_DETECT_KERN_PKG
else
apt-mark manual $AUTO_DETECT_KERN_PKG
fi
else
G_DIETPI-NOTIFY 2 'Unable to find kernel packages for installation. Assuming non-APT/.deb kernel installation.'
fi
#ARMbian/others DTB
AUTO_DETECT_DTB_PKG=$(dpkg --get-selections | grep '^linux-dtb-' | awk '{print $1}')
if [[ $AUTO_DETECT_DTB_PKG ]]; then
G_AGI $AUTO_DETECT_DTB_PKG
fi
fi
G_DIETPI-NOTIFY 2 'Generating list of minimal packages, required for DietPi installation'
INSTALL_PACKAGES=''
for ((i=0; i<${#aPACKAGES_REQUIRED_INSTALL[@]}; i++))
do
# One line INSTALL_PACKAGES so we can use it later.
INSTALL_PACKAGES+="${aPACKAGES_REQUIRED_INSTALL[$i]} "
done
# - delete[]
unset aPACKAGES_REQUIRED_INSTALL
l_message='Marking required packages as manually installed' G_RUN_CMD apt-mark manual $INSTALL_PACKAGES
# Purging additional packages, that (in some cases) do not get autoremoved:
# - dhcpcd5: https://github.com/Fourdee/DietPi/issues/1560#issuecomment-370136642
# - dbus: Not needed 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)
export G_DISTRO=$DISTRO_TARGET
export G_DISTRO_NAME="$DISTRO_TARGET_NAME"
G_DIETPI-NOTIFY 2 'Installing core DietPi pre-req APT packages'
G_AGI $INSTALL_PACKAGES
G_AGA
# Reenable HTTPS for deb.debian.org, if system was dist-upgraded to Stretch+
if (( $G_DISTRO > 3 && $G_HW_MODEL > 9 )); then
sed -i 's/http:/https:/g' /etc/apt/sources.list
fi
#------------------------------------------------------------------------------------------------
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'
userdel -f pi &> /dev/null
userdel -f test &> /dev/null #@fourdee
userdel -f odroid &> /dev/null
userdel -f rock64 &> /dev/null
userdel -f linaro &> /dev/null #ASUS TB
userdel -f dietpi &> /dev/null #recreated below
userdel -f debian &> /dev/null #BBB
G_DIETPI-NOTIFY 2 'Removing misc files/folders/services, not required by DietPi'
rm -R /home &> /dev/null
rm -R /media &> /dev/null
rm -R /selinux &> /dev/null
# - www
rm -R /var/www/* &> /dev/null
# - sourcecode (linux-headers etc)
rm -R /usr/src/* &> /dev/null
# - root
rm -R /root/.cache/* &> /dev/null
rm -R /root/.local/* &> /dev/null
rm -R /root/.config/* &> /dev/null
# - documentation folders
rm -R /usr/share/man &> /dev/null
rm -R /usr/share/doc &> /dev/null
rm -R /usr/share/doc-base &> /dev/null
rm -R /usr/share/calendar &> /dev/null
# - Previous debconfs
rm /var/cache/debconf/*-old &> /dev/null
# - Fonts
rm -R /usr/share/fonts/* &> /dev/null
rm -R /usr/share/icons/* &> /dev/null
rm /etc/init.d/resize2fs &> /dev/null
rm /etc/update-motd.d/* &> /dev/null # ARMbian
systemctl disable firstrun &> /dev/null
rm /etc/init.d/firstrun &> /dev/null # ARMbian
# - Disable ARMbian's log2ram: https://github.com/Fourdee/DietPi/issues/781
systemctl disable log2ram &> /dev/null
systemctl stop log2ram &> /dev/null
rm /usr/local/sbin/log2ram &> /dev/null
rm /etc/systemd/system/log2ram.service &> /dev/null
systemctl daemon-reload &> /dev/null
rm /etc/cron.hourly/log2ram &> /dev/null
# - Meveric specific
rm /etc/init.d/cpu_governor &> /dev/null
rm /etc/systemd/system/cpu_governor.service &> /dev/null
rm /usr/local/sbin/setup-odroid &> /dev/null
# - Disable ARMbian's resize service (not automatically removed by ARMbian scripts...)
systemctl disable resize2fs &> /dev/null
rm /etc/systemd/system/resize2fs.service &> /dev/null
# - ARMbian-config
rm /etc/profile.d/check_first_login_reboot.sh &> /dev/null
# - RPi specific https://github.com/Fourdee/DietPi/issues/1631#issuecomment-373965406
rm /etc/profile.d/wifi-country.sh &> /dev/null
# - make_nas_processes_faster cron job on Rock64 + NanoPi + Pine64(?) images
rm /etc/cron.d/make_nas_processes_faster &> /dev/null
#-----------------------------------------------------------------------------------
# Bash Profiles
# - Pre v6.9 cleaning:
sed -i '/\/DietPi/d' /root/.bashrc
sed -i '/\/DietPi/d' /home/dietpi/.bashrc &> /dev/null
rm /etc/profile.d/99-dietpi* &> /dev/null
# - Enable /etc/bashrc.d/ support for custom interactive non-login shell scripts:
G_CONFIG_INJECT '.*/etc/bashrc\.d/.*' 'for i in /etc/bashrc\.d/\*\.sh; do \[ -r "\$i" \] \&\& \. \$i; done' /etc/bash.bashrc
# - Enable bash-completion for non-login shells:
# - NB: It is called twice on login shells then, but breaks directly if called already once.
ln -sf /etc/profile.d/bash_completion.sh /etc/bashrc.d/dietpi-bash_completion.sh
#-----------------------------------------------------------------------------------
#Create_DietPi_User
l_message='Creating DietPi User Account' G_RUN_CMD /DietPi/dietpi/func/dietpi-set_software useradd dietpi
#-----------------------------------------------------------------------------------
#UID bit for sudo
# - https://github.com/Fourdee/DietPi/issues/794
G_DIETPI-NOTIFY 2 'Configuring Sudo UID bit'
chmod 4755 $(which sudo)
#-----------------------------------------------------------------------------------
#Dir's
G_DIETPI-NOTIFY 2 'Configuring DietPi Directories'