-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-build.sh
executable file
·834 lines (716 loc) · 26.1 KB
/
arch-build.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
#!/bin/bash
# Version 2.12
# Arch Linux INSTALL SCRIPT
GITURL="https://raw.githubusercontent.com/matty-r/lazy-arch/"
GITBRANCH="master"
# Detect if we have been piped
# if so, close it and reopen to standard input
if [ ! -t 0 ]; then
tmpcfg=$(cat -)
exec 0<&- # close current pipeline input
exec 0</dev/tty # reopen input fd with standard input
fi
#Exit on error
#set -e
# Check what params this has been launched with.
# Unattended install is default.
# -d or --dry-run will *NOT* make any changes to your system - used to export the settings and
# show what *WOULD* be done
# -p or --prompt will ask the user to input settings
while [[ "$#" -gt 0 ]]; do
case $1 in
-d | --dry-run)
DRYRUN=1
;;
-p | --prompt)
PROMPT=1
;;
--rootpwd)
ROOTPWD="$2"
shift
;;
--userpwd)
USERPWD="$2"
shift
;;
*)
echo "Unknown parameter passed: $1"
exit 1
;;
esac
shift
done
# User Variables array
declare -A USERVARIABLES
# Script Variables. DO NOT CHANGE THESE
SCRIPTPATH=$(readlink -m "$(type -p "$0")")
SCRIPTROOT=${SCRIPTPATH%/*}
BOOTDEVICE=""
ROOTDEVICE=""
EFIPATH="/sys/firmware/efi/efivars"
BOOTTYPE=""
NETINT=""
CPUTYPE=""
GPUBUNDLE=""
INSTALLSTAGE=""
checkISOVersion() {
echo "Checking ISO versions..."
LATESTVERSION=$(curl -s https://gitlab.archlinux.org/api/v4/projects/10190/releases/ | grep -Po '(?<=version ).*?(?=\))' | head -n 1)
if [ $? -ne 0 ]; then
echo "Error: Failed to retrieve the latest version of the Arch Linux ISO. Check your internet connection and try again."
exit 1
fi
LOCALVERSION=$(cat /run/archiso/airootfs/version)
if [[ $(echo "${LATESTVERSION}" | wc -w) != 0 ]] && [[ $(echo "${LOCALVERSION}" | wc -w) != 0 ]]; then
shopt -s nocasematch
ANSWER="Y"
if [[ "$LOCALVERSION" != "$LATESTVERSION" ]]; then
echo "$(tput setaf 0)$(tput setab 3) **You're not running the latest Arch Linux ISO which could cause problems.** $(tput sgr0)"
CONTINUEPLZ=""
read -p "$(tput setaf 0)$(tput setab 3)Continue anyway?$(tput sgr0)($DEFAULTANSWER/n): " CONTINUEPLZ
CONTINUEPLZ=${CONTINUEPLZ:-$ANSWER}
if [[ "$CONTINUEPLZ" != "$ANSWER" ]]; then
exit 1
else
echo "$(tput setaf 7)$(tput setab 1)Alrighty then, you're the boss! Let's do this..$(tput sgr0)"
fi
else
echo "Running the latest version ($LOCALVERSION) of the Arch Linux ISO."
fi
shopt -u nocasematch
else
echo "$(tput setaf 0)$(tput setab 3)Unable to verify your ISO with the latest release.. continuing anyway..$(tput sgr0)"
fi
}
checkISOVersion
if [ ! -f "$SCRIPTROOT"/bundleConfigurators.sh ]; then
echo "$(tput setaf 2)$(tput setab 0) **Downloading bundleConfigurators.sh..** $(tput sgr0)"
curl -s -SLO "$GITURL""$GITBRANCH"/bundleConfigurators.sh
fi
if [ ! -f "$SCRIPTROOT"/softwareBundles.sh ]; then
echo "$(tput setaf 2)$(tput setab 0) **Downloading softwareBundles.sh..** $(tput sgr0)"
curl -s -SLO "$GITURL""$GITBRANCH"/softwareBundles.sh
fi
if [ ! -f "$SCRIPTROOT"/softwareBundles.sh ] || [ ! -f "$SCRIPTROOT"/softwareBundles.sh ]; then
echo "$(tput setaf 7)$(tput setab 1) **Check internet access. Unable to download required files.** $(tput sgr0)"
exit 1
fi
if [ ! -f "$SCRIPTROOT"/settings.conf ]; then
echo "$(tput setaf 2)$(tput setab 0) **Downloading settings.conf..** $(tput sgr0)"
curl -s -SLO "$GITURL""$GITBRANCH"/settings.conf
echo "$(tput setaf 0)$(tput setab 3) **First run? Be sure to change the settings.conf file before continuing.** $(tput sgr0)"
exit 1
fi
#Prompt User for settings
promptSettings() {
for variable in "${!USERVARIABLES[@]}"; do
read -rp "$variable?:" answer
USERVARIABLES[$variable]=$answer
done
}
# Print out the settings
printSettings() {
for variable in "${!USERVARIABLES[@]}"; do
echo "$variable = ${USERVARIABLES[$variable]}"
done
}
getDevice() {
USERPARTITION=$1
DEVICES=($(lsblk -no PATH))
for DEVICE in "${DEVICES[@]}"; do
if [ ${#DEVICE} -lt ${#USERPARTITION} ]; then
if [[ "$USERPARTITION" =~ $DEVICE ]]; then
echo "$DEVICE"
fi
fi
done
}
importSettings() {
IMPORTTYPE=$1
echo "Importing ${IMPORTTYPE} Settings.."
if [[ $IMPORTTYPE == "all" ]] || [[ $IMPORTTYPE == "script" ]]; then
SCRIPTPATH=$(retrieveSettings 'SCRIPTPATH')
SCRIPTROOT=$(retrieveSettings 'SCRIPTROOT')
BOOTDEVICE=$(retrieveSettings 'BOOTDEVICE')
ROOTDEVICE=$(retrieveSettings 'ROOTDEVICE')
EFIPATH=$(retrieveSettings 'EFIPATH')
BOOTTYPE=$(retrieveSettings 'BOOTTYPE')
NETINT=$(retrieveSettings 'NETINT')
CPUTYPE=$(retrieveSettings 'CPUTYPE')
GPUBUNDLE=$(retrieveSettings 'GPUBUNDLE')
INSTALLSTAGE=$(retrieveSettings 'INSTALLSTAGE')
fi
if [[ $IMPORTTYPE == "all" ]] || [[ $IMPORTTYPE == "user" ]]; then
USERVARIABLES[BUNDLES]=$(retrieveSettings 'BUNDLES')
USERVARIABLES[USERNAME]=$(retrieveSettings 'USERNAME')
USERVARIABLES[HOSTNAME]=$(retrieveSettings 'HOSTNAME')
USERVARIABLES[DESKTOP]=$(retrieveSettings 'DESKTOP')
USERVARIABLES[KERNEL]=$(retrieveSettings 'KERNEL')
USERVARIABLES[BOOTPART]=$(retrieveSettings 'BOOTPART')
USERVARIABLES[BOOTMODE]=$(retrieveSettings 'BOOTMODE')
USERVARIABLES[ROOTFILE]=$(retrieveSettings 'ROOTFILE')
USERVARIABLES[ENCRYPT]=$(retrieveSettings 'ENCRYPT')
USERVARIABLES[ROOTPART]=$(retrieveSettings 'ROOTPART')
USERVARIABLES[ROOTMODE]=$(retrieveSettings 'ROOTMODE')
fi
}
# Export out the settings used/selected to settings.conf
generateSettings() {
exportSettings "USERNAME" "${USERVARIABLES[USERNAME]}"
exportSettings "HOSTNAME" "${USERVARIABLES[HOSTNAME]}"
exportSettings "DESKTOP" "${USERVARIABLES[DESKTOP]}"
exportSettings "ROOTPART" "${USERVARIABLES[ROOTPART]}"
exportSettings "BOOTPART" "${USERVARIABLES[BOOTPART]}"
exportSettings "BOOTMODE" "${USERVARIABLES[BOOTMODE]}"
exportSettings "ROOTMODE" "${USERVARIABLES[ROOTMODE]}"
exportSettings "ROOTFILE" "${USERVARIABLES[ROOTFILE]}"
exportSettings "ENCRYPT" "${USERVARIABLES[ENCRYPT]}"
# Grab the device chosen for the boot part
BOOTDEVICE=$(getDevice "${USERVARIABLES[BOOTPART]}")
exportSettings "BOOTDEVICE" "$BOOTDEVICE"
# Grab the device chosen for the root part
ROOTDEVICE=$(getDevice "${USERVARIABLES[ROOTPART]}")
exportSettings "ROOTDEVICE" "$ROOTDEVICE"
exportSettings "SCRIPTPATH" "$SCRIPTPATH"
exportSettings "SCRIPTROOT" "$SCRIPTROOT"
# Find the currently used interface - used to enable dhcpcd on that interface
AVAILABLEINTERFACES=($(ip route | grep default | grep -Po '(?<=dev ).*(?= proto)'))
for EXTERNALINTERFACE in "${AVAILABLEINTERFACES[@]}"; do
echo "Testing interface ${EXTERNALINTERFACE}."
ping -c4 -I "$EXTERNALINTERFACE" archlinux.org >/dev/null 2>&1
PINGRESULT=$?
if [ "$PINGRESULT" = 0 ]; then
NETINT="$EXTERNALINTERFACE"
echo "${NETINT} looks good, lets use that."
break
fi
done
exportSettings "NETINT" "${NETINT}"
exportSettings "KERNEL" "${USERVARIABLES[KERNEL]}"
# Determine if it's an EFI install or not
if [ -d "$EFIPATH" ]; then
BOOTTYPE="EFI"
exportSettings "EFIPATH" "$EFIPATH"
else
BOOTTYPE="BIOS"
fi
exportSettings "BOOTTYPE" "$BOOTTYPE"
#set comparison to ignore case temporarily
shopt -s nocasematch
#Detect platform type. Add the appropriate packages to install.
PLATFORM=$(hostnamectl | grep Chassis | cut -f2,2 -d':' | xargs)
if [[ $PLATFORM =~ 'vm' ]]; then
VMTYPE=$(hostnamectl | grep Virtualization | cut -f2,2 -d':' | xargs)
case $VMTYPE in
'kvm')
PLATFORM="qemuGuest"
;;
'vmware')
PLATFORM="esxiGuest"
;;
'microsoft')
PLATFORM="hyperGuest"
;;
'oracle')
PLATFORM="vboxGuest"
;;
esac
if [[ ! "${USERVARIABLES[BUNDLES]}" =~ $PLATFORM ]]; then
USERVARIABLES[BUNDLES]+=" $PLATFORM"
fi
elif [[ $PLATFORM =~ 'laptop' ]]; then
USERVARIABLES[BUNDLES]+=" $PLATFORM"
fi
#Add the selected desktop to the bundles - if it isn't there already
if [[ ! "${USERVARIABLES[DESKTOP]}" =~ ${USERVARIABLES[BUNDLES]} ]]; then
echo "Adding ${USERVARIABLES[DESKTOP]} to bundles."
# Add it to the front so that it's installed before any other bundles
USERVARIABLES[BUNDLES]="${USERVARIABLES[DESKTOP]} ${USERVARIABLES[BUNDLES]}"
fi
#Detect CPU type. Used for setting the microcode (ucode) on the boot loader
CPUTYPE=$(lscpu | grep Vendor)
if [[ $CPUTYPE =~ "AMD" ]]; then
CPUTYPE="amd"
elif [[ $CPUTYPE =~ "Intel" ]]; then
CPUTYPE="intel"
fi
exportSettings "CPUTYPE" "$CPUTYPE"
#Detect GPU type. Add the appropriate packages to install.
VGACONTROLLER=$(echo "$(lspci -vnn | grep VGA)" | tr '[:upper:]' '[:lower:]')
GFXCONTROLLER=$(echo "$(lspci -vnn | grep 3D)" | tr '[:upper:]' '[:lower:]')
if [[ ${GFXCONTROLLER} =~ "nvidia" && ${VGACONTROLLER} =~ "intel" ]] || [[ ${VGACONTROLLER} =~ "nvidia" && ${VGACONTROLLER} =~ "intel" ]]; then
GPUBUNDLE="nvidia nvidiaPrime"
elif [[ ${VGACONTROLLER} =~ "nvidia" ]]; then
GPUBUNDLE="nvidia"
elif [[ ${VGACONTROLLER} =~ "amd" ]]; then
GPUBUNDLE="amdgpu"
elif [[ ${VGACONTROLLER} =~ "intelgpu" ]]; then
GPUBUNDLE="intelgpu"
else
GPUBUNDLE="vm"
fi
USERVARIABLES[BUNDLES]+=" $GPUBUNDLE"
exportSettings "GPUBUNDLE" "$GPUBUNDLE"
exportSettings "BUNDLES" "${USERVARIABLES[BUNDLES]}"
#reset comparisons
shopt -u nocasematch
}
driver() {
importSettings "user"
if [ ! -f "$SCRIPTROOT"/softwareBundles.sh ] || [ ! -r "$SCRIPTROOT"/softwareBundles.sh ]; then
echo "Error: softwareBundles.sh does not exist or is not readable. Make sure the file exists and has the correct permissions."
exit 1
fi
if [ ! -f "$SCRIPTROOT"/bundleConfigurators.sh ] || [ ! -r "$SCRIPTROOT"/bundleConfigurators.sh ]; then
echo "Error: bundleConfigurators.sh does not exist or is not readable. Make sure the file exists and has the correct permissions."
exit 1
fi
#Available Software Bundles
# shellcheck source=softwareBundles.sh
source "$SCRIPTROOT/softwareBundles.sh"
#Addtional configurations needed for selected bundles
# shellcheck source=bundleConfigurators.sh
source "$SCRIPTROOT/bundleConfigurators.sh"
if [[ $PROMPT -eq 1 ]]; then
promptSettings
fi
#Check if stage file exists
if [[ -f "$SCRIPTROOT/stage.cfg" ]]; then
INSTALLSTAGE=$(cat "$SCRIPTROOT/stage.cfg")
else
INSTALLSTAGE=""
fi
case $INSTALLSTAGE in
"FIRST" | "")
echo "FIRST INSTALL STAGE"
firstInstallStage
;;
"SECOND")
echo "SECOND INSTALL STAGE"
secondInstallStage
;;
"THIRD")
echo "THIRD INSTALL STAGE"
thirdInstallStage
;;
"FOURTH")
echo "LAST INSTALL STAGE"
finalInstallStage
;;
esac
}
firstInstallStage() {
echo "0. Set passwords"
if [[ $DRYRUN -ne 1 ]]; then
ROOTPWD=""
read -sp 'ROOT Password: ' ROOTPWD
echo
USERPWD=""
read -sp "${USERVARIABLES[USERNAME]} Password: " USERPWD
echo
if [[ $ROOTPWD == "" ]] || [[ $USERPWD == "" ]]; then
echo "$(tput setaf 7)$(tput setab 1) **Passwords are required. Exiting..** $(tput sgr0)"
exit 1
fi
fi
echo "1. Generate Settings"
generateSettings
echo "2. System Clock"
systemClock
echo "3. Partition Disks"
partDisks
echo "4. Format Partitions"
formatParts
echo "5. Mount partitions"
mountParts
echo "6. Install Arch Linux base packages"
installArchLinuxBase
echo "7. Making the FSTAB"
makeFstab
echo "8. Setup chroot."
chrootTime
# If a dryrun, then just run the functions as is. Don't bother running it in the chroot environment (It doesn't exist yet).
if [[ $DRYRUN -eq 1 ]]; then
secondInstallStage
thirdInstallStage
else
#Go into chroot. Should start at secondInstallStage
arch-chroot /mnt ./home/"${USERVARIABLES[USERNAME]}"/arch-build.sh --rootpwd "$ROOTPWD" --userpwd "$USERPWD"
#Go into chroot as new user. Should start at thirdInstallStage as new user.
arch-chroot /mnt su "${USERVARIABLES[USERNAME]}" ./home/"${USERVARIABLES[USERNAME]}"/arch-build.sh
fi
echo "Done. Perform reboot when ready."
}
secondInstallStage() {
echo "10. chroot: Import Settings"
importSettings "all"
echo "11. chroot: Set root password"
rootPassword
echo "12. chroot: Create new user"
createUser
echo "13. chroot: Set Time"
setTime
echo "14. chroot: Generate locales"
genLocales
echo "15. chroot: Apply HostName"
applyHostname
echo "16. chroot: Add hosts file entries"
addHosts
echo "17. chroot: Generate mkinitcpio"
genInit
echo "18. chroot: Getting ready to boot"
readyForBoot
}
thirdInstallStage() {
importSettings "all"
echo "20. chroot: Install yay - AUR package manager"
makeYay
echo "21. chroot: Enable lib32"
enableMultilibPackages
echo "22. chroot: Install selected bundles"
runCommand installSoftwareBundles "${USERVARIABLES[BUNDLES]}"
echo "23. chroot: Run the file system packages "
if [[ "${USERVARIABLES[ROOTFILE]}" = "BTRFS" ]]; then
runCommand btrfsPackages-Config
elif [[ "${USERVARIABLES[ROOTFILE]}" = "F2FS" ]]; then
runCommand f2fsPackages-Config
fi
echo "24. Readying final boot"
runCommand grubPackages-Config
readyFinalBoot
}
exportSettings() {
SETTINGNAME=$1
SETTING=$2
# echo "Exporting $1=$2" 1>&2
EXPORTPARAM="${SETTINGNAME}=${SETTING}"
CURRENTSETTING=$(grep "^${SETTINGNAME}=" "$SCRIPTROOT/settings.conf")
if [[ "${CURRENTSETTING}" == "" ]]; then
printf "\n%s" "${EXPORTPARAM}" | tee -a "$SCRIPTROOT/settings.conf" >/dev/null
else
# replace any previously matching settings
sed -i "s%^${SETTINGNAME}=.*%${EXPORTPARAM}%" "$SCRIPTROOT/settings.conf"
fi
}
#retrieveSettings 'SETTINGNAME'
retrieveSettings() {
if [[ $DRYRUN -eq 1 ]]; then
SETTINGSPATH="./settings.conf"
else
SETTINGSPATH="$SCRIPTROOT/settings.conf"
fi
SETTINGNAME=$1
SETTING=$(grep "^${SETTINGNAME}=" "$SETTINGSPATH" | cut -f2,2 -d'=')
echo "$SETTING"
}
runCommand() {
if [[ $DRYRUN -eq 1 ]]; then
printf '%q ' "$@"
printf '\n'
else
"$@"
fi
}
# Update the system clock
systemClock() {
runCommand timedatectl set-ntp true
}
# PARTITION DISKS
partDisks() {
if [[ $BOOTTYPE = "EFI" ]]; then
case ${USERVARIABLES[BOOTMODE]} in
"LEAVE" | "FORMAT")
echo "Leaving the boot partition..."
;;
"CREATE")
echo "EFI: Boot partition will be created. Whole disk will be destroyed!"
runCommand parted -s "$BOOTDEVICE" -- mklabel gpt mkpart "ARCH_BOOT" fat32 0% 256MiB
;;
esac
fi
case ${USERVARIABLES[ROOTMODE]} in
"LEAVE" | "FORMAT")
echo "Leaving the root partition..."
;;
"CREATE")
if [[ $BOOTTYPE = "EFI" ]]; then
#If the root device matches the boot device, don't setup device label
if [ "$BOOTDEVICE" = "$ROOTDEVICE" ]; then
echo "EFI: Root partition will be created."
runCommand parted -s "$ROOTDEVICE" -- mkpart "ARCH_ROOT" ext4 256MiB 100%
else
echo "EFI: Root partition will be created. Whole disk will be destroyed!"
runCommand parted -s "$ROOTDEVICE" -- mklabel gpt mkpart "ARCH_ROOT" ext4 0% 100%
fi
else
#BIOS system. If boot device matches root device, then make root part the same as boot part
if [ "$BOOTDEVICE" = "$ROOTDEVICE" ]; then
USERVARIABLES[ROOTPART]="${USERVARIABLES[BOOTPART]}"
fi
echo "BIOS: Root partition will be created. Whole disk will be destroyed!"
runCommand parted -s "$ROOTDEVICE" -- mklabel msdos mkpart primary ext4 0% 100% set 1 boot on
fi
;;
esac
}
# FORMAT PARTITIONS
formatParts() {
FMTROOTPART="${USERVARIABLES[ROOTPART]}"
if [[ "$BOOTTYPE" = "EFI" ]]; then
if [ "${USERVARIABLES[BOOTMODE]}" = "CREATE" ] || [ "${USERVARIABLES[BOOTMODE]}" = "FORMAT" ]; then
runCommand mkfs.fat -F32 "${USERVARIABLES[BOOTPART]}"
fi
if [ "${USERVARIABLES[ROOTMODE]}" = "CREATE" ] || [ "${USERVARIABLES[ROOTMODE]}" = "FORMAT" ]; then
if [[ "${USERVARIABLES[ENCRYPT]}" = "YES" ]]; then
echo "Set up encryption for ${USERVARIABLES[ROOTPART]}"
runCommand cryptsetup -q -y -v --cipher=aes-xts-plain64 --key-size 512 --hash=sha512 luksFormat "${USERVARIABLES[ROOTPART]}"
runCommand cryptsetup luksOpen "${USERVARIABLES[ROOTPART]}" luks
FMTROOTPART="/dev/mapper/luks"
else
echo "no encryption"
fi
if [[ "${USERVARIABLES[ROOTFILE]}" = "EXT4" ]]; then
echo "Make ext4 on root $FMTROOTPART"
runCommand mkfs.ext4 -L ARCH_ROOT -F -F $FMTROOTPART
elif [[ "${USERVARIABLES[ROOTFILE]}" = "BTRFS" ]]; then
echo "Make btrfs on root $FMTROOTPART"
runCommand mkfs.btrfs -L ARCH_ROOT -f -f $FMTROOTPART
elif [[ "${USERVARIABLES[ROOTFILE]}" = "F2FS" ]]; then
echo "Make btrfs on root $FMTROOTPART"
runCommand mkfs.f2fs -O extra_attr,inode_checksum,sb_checksum,compression -l ARCH_ROOT -f -f $FMTROOTPART
fi
fi
else
if [ "${USERVARIABLES[ROOTMODE]}" = "CREATE" ] || [ "${USERVARIABLES[ROOTMODE]}" = "FORMAT" ]; then
if [[ "${USERVARIABLES[ROOTFILE]}" = "EXT4" ]]; then
echo "Make ext4 on root $FMTROOTPART"
runCommand mkfs.ext4 -L ARCH_ROOT -F -F $FMTROOTPART
elif [[ "${USERVARIABLES[ROOTFILE]}" = "BTRFS" ]]; then
echo "Make btrfs on root $FMTROOTPART"
runCommand mkfs.btrfs -L ARCH_ROOT -f -f $FMTROOTPART
fi
fi
fi
}
# Mount the file systems
mountParts() {
FMTROOTPART="${USERVARIABLES[ROOTPART]}"
if [[ "${USERVARIABLES[ENCRYPT]}" = "YES" ]]; then
FMTROOTPART="/dev/mapper/luks"
fi
if [[ "${USERVARIABLES[ROOTFILE]}" = "BTRFS" ]]; then
#mount encrypted partition instead
echo "Mount root partition... (BTRFS)"
runCommand mount -o compress=zstd $FMTROOTPART /mnt
#btrfs sub volumes
runCommand cd /mnt
runCommand btrfs subvolume create @
runCommand btrfs subvolume create @home
runCommand btrfs subvolume create @log
runCommand btrfs subvolume create @srv
runCommand btrfs subvolume create @pkg
runCommand btrfs subvolume create @tmp
runCommand btrfs subvolume create @snapshots
runCommand cd ~
runCommand umount /mnt
runCommand mount -o compress=zstd,subvol=@ $FMTROOTPART /mnt
runCommand cd /mnt
runCommand mkdir -p {home,srv,var/{log,cache/pacman/pkg},tmp,.snapshots}
runCommand mount -o compress=zstd,subvol=@home $FMTROOTPART home
runCommand mount -o compress=zstd,subvol=@log $FMTROOTPART var/log
runCommand mount -o compress=zstd,subvol=@pkg $FMTROOTPART var/cache/pacman/pkg
runCommand mount -o compress=zstd,subvol=@srv $FMTROOTPART srv
runCommand mount -o compress=zstd,subvol=@tmp $FMTROOTPART tmp
runCommand mount -o compress=zstd,subvol=@snapshots $FMTROOTPART .snapshots
elif [[ "${USERVARIABLES[ROOTFILE]}" = "EXT4" ]]; then
echo "Mount root partition... (EXT4)"
runCommand mount $FMTROOTPART /mnt
elif [[ "${USERVARIABLES[ROOTFILE]}" = "F2FS" ]]; then
echo "Mount root partition... (F2FS)"
runCommand mount $FMTROOTPART /mnt
fi
if [[ "$BOOTTYPE" = "EFI" ]]; then
runCommand mkdir /mnt/boot
runCommand mount "${USERVARIABLES[BOOTPART]}" /mnt/boot
else
runCommand mount "${USERVARIABLES[ROOTPART]}" /mnt
fi
}
setLocalMirrors() {
GEOLOCATE=$(curl -sX GET "http://ip-api.com/json/$(curl -s icanhazip.com)")
COUNTRYCODE=$(echo "$GEOLOCATE" | grep -Po '(?<="countryCode":").*?(?=")')
echo "MIRRORS will be retrieved from $COUNTRYCODE"
if [[ $DRYRUN -eq 1 ]]; then
echo "Write Local Mirrors to /etc/pacman.d/mirrorlist"
else
runCommand curl -s "https://archlinux.org/mirrorlist/?country=${COUNTRYCODE}&protocol=https&use_mirror_status=on" | sed "s/#Server/Server/" >/etc/pacman.d/mirrorlist
runCommand sed -i '/options/a ParallelDownloads = 5' /etc/pacman.conf
fi
}
## Install the base packages
installArchLinuxBase() {
setLocalMirrors
runCommand pacstrap /mnt "${archBasePackages[@]}"
}
## Generate an fstab file
makeFstab() {
if [[ $DRYRUN -eq 1 ]]; then
echo "Generate fstab at /mnt/etc/fstab"
else
runCommand genfstab -U /mnt >>/mnt/etc/fstab
fi
}
## Change root into the new system:
chrootTime() {
if [[ $DRYRUN -eq 1 ]]; then
echo "Write SECOND to $SCRIPTROOT/stage.cfg"
else
runCommand echo "SECOND" >"$SCRIPTROOT"/stage.cfg
fi
##re-export the settings for the new stages (in chroot)
exportSettings "SCRIPTPATH" "/home/${USERVARIABLES[USERNAME]}/arch-build.sh"
exportSettings "SCRIPTROOT" "/home/${USERVARIABLES[USERNAME]}"
runCommand mkdir /mnt/home/"${USERVARIABLES[USERNAME]}"
runCommand cp "$SCRIPTROOT"/stage.cfg /mnt/home/"${USERVARIABLES[USERNAME]}"
runCommand cp "$SCRIPTPATH" /mnt/home/"${USERVARIABLES[USERNAME]}"
runCommand cp "$SCRIPTROOT"/softwareBundles.sh /mnt/home/"${USERVARIABLES[USERNAME]}"
runCommand cp "$SCRIPTROOT"/bundleConfigurators.sh /mnt/home/"${USERVARIABLES[USERNAME]}"
runCommand cp "$SCRIPTROOT"/settings.conf /mnt/home/"${USERVARIABLES[USERNAME]}"
runCommand cp /etc/pacman.conf /mnt/etc/
runCommand cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/
}
## Set the time zone
setTime() {
GEOLOCATE=$(curl -sX GET "http://ip-api.com/json/$(curl -s icanhazip.com)")
TIMEZONE=$(echo "$GEOLOCATE" | grep -Po '(?<="timezone":").*?(?=",)')
echo "TIMEZONE will be set to $TIMEZONE"
runCommand ln -sf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
runCommand hwclock --systohc
}
## Uncomment en_US.UTF-8 UTF-8 and other needed locales in /etc/locale.gen
genLocales() {
GEOLOCATE=$(curl -sX GET "http://ip-api.com/json/$(curl -s icanhazip.com)")
COUNTRYCODE=$(echo "$GEOLOCATE" | grep -Po '(?<="countryCode":").*?(?=")')
COUNTRYINFO=$(curl -sX GET "https://gist.githubusercontent.com/matty-r/13233057c539807a4177bd01cdd35545/raw/72b1746b651e03a9cce31c03e56cc38a0a811a5e/countries.txt" | tr -d '\n' | tr -d ' ')
LANGUAGES=$(echo "$COUNTRYINFO" | grep -Po '(?<='"$COUNTRYCODE"':{).*?(?=})' | grep -Po '(?<=languages:\[).*?(?=\])')
#LANGUAGES=$(echo $LANGUAGES | grep -oP '(?<=").*?(?=")' | head -n 1)
readarray -t LANGARRAY < <(echo "$LANGUAGES" | grep -oP "(?<=').*?(?=')")
declare -p LANGARRAY
for LANGUAGE in "${LANGARRAY[@]}"; do
LANGCODE="${LANGUAGE}_${COUNTRYCODE}.UTF-8"
if grep -q "${LANGCODE}" /etc/locale.gen; then
echo "found - ${LANGCODE}"
break
fi
done
echo "LANGUAGE CODE will be set to $LANGCODE"
runCommand sed -i "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen
runCommand sed -i "s/#$LANGCODE UTF-8/$LANGCODE UTF-8/" /etc/locale.gen
runCommand locale-gen
runCommand echo "LANG=$LANGCODE" >>/etc/locale.conf
}
## Create the hostname file:
applyHostname() {
if [[ $DRYRUN -eq 1 ]]; then
echo "Write ${USERVARIABLES[HOSTNAME]} to /etc/hostname"
else
runCommand echo "${USERVARIABLES[HOSTNAME]}" >>/etc/hostname
fi
}
## ADD HOSTS ENTRIES
addHosts() {
if [[ $DRYRUN -eq 1 ]]; then
echo "Write Localinfo to /etc/hosts"
else
{
echo "127.0.0.1 localhost"
echo "::1 localhost"
echo "127.0.1.1 ${USERVARIABLES[HOSTNAME]}.mydomain ${USERVARIABLES[HOSTNAME]}"
} >>/etc/hosts
fi
}
## GENERATE INITRAMFS
genInit() {
if [[ "${USERVARIABLES[ENCRYPT]}" = "YES" ]]; then
runCommand sudo sed -i "s/^HOOKS=(base udev autodetect modconf block filesystems keyboard fsck).*/HOOKS=(base udev autodetect modconf block encrypt filesystems keyboard fsck shutdown)/" /etc/mkinitcpio.conf
else
runCommand sudo sed -i "s/^HOOKS=(base udev autodetect modconf block filesystems keyboard fsck).*/HOOKS=(base udev autodetect modconf block filesystems keyboard fsck shutdown)/" /etc/mkinitcpio.conf
fi
runCommand mkinitcpio -P
}
## ROOT PASSWORD
rootPassword() {
if [[ $DRYRUN -eq 1 ]]; then
echo "Set root password to $ROOTPWD"
else
echo "root:$ROOTPWD" | chpasswd
echo
fi
}
## INSTALL BOOTLOADER AND MICROCODE
readyForBoot() {
if [[ "$BOOTTYPE" = "EFI" ]]; then
runCommand pacman -S --noconfirm grub "$CPUTYPE"'-ucode' os-prober efibootmgr
runCommand grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --recheck
runCommand grub-mkconfig -o /boot/grub/grub.cfg
else
runCommand pacman -S --noconfirm grub "$CPUTYPE"'-ucode' os-prober
runCommand grub-install --target=i386-pc "$ROOTDEVICE"
runCommand grub-mkconfig -o /boot/grub/grub.cfg
fi
}
# Create the new user and add them to the wheel group.
# Disable the password requirement to run sudo. Will be re-enabled in the final stages of arch-build.
createUser() {
runCommand useradd -m "${USERVARIABLES[USERNAME]}"
runCommand gpasswd -a "${USERVARIABLES[USERNAME]}" wheel
# set user password
runCommand echo "Set password for ${USERVARIABLES[USERNAME]}"
if [[ $DRYRUN -eq 1 ]]; then
echo "Set User password to $USERPWD"
else
echo "${USERVARIABLES[USERNAME]}:$USERPWD" | chpasswd
fi
# enable wheel group for sudoers
runCommand sed -i "s/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/" /etc/sudoers
# enable wheel group for sudoers - no password. TEMPORARY
runCommand sed -i "s/# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers
if [[ $DRYRUN -eq 1 ]]; then
echo "Write THIRD to /home/${USERVARIABLES[USERNAME]}/stage.cfg"
else
runCommand echo "THIRD" >/home/"${USERVARIABLES[USERNAME]}"/stage.cfg
fi
# SET OWNERSHIP OF SCRIPT FILES
runCommand chown "${USERVARIABLES[USERNAME]}":"${USERVARIABLES[USERNAME]}" "$SCRIPTROOT" --recursive
}
enableMultilibPackages() {
runCommand sudo sed -i '/#\[multilib\]/a Include = \/etc\/pacman.d\/mirrorlist' /etc/pacman.conf
runCommand sudo sed -i "s/#\[multilib\]/[multilib]/" /etc/pacman.conf
runCommand sudo pacman -Syyu --noconfirm
}
# make yay
makeYay() {
if [[ $(pacman -Ss "yay-bin") ]]; then
echo "yay-bin found custom repo.. install direct"
runCommand sudo pacman -S yay-bin --noconfirm
else
runCommand cd /home/"${USERVARIABLES[USERNAME]}"
runCommand git clone https://aur.archlinux.org/yay-bin.git
runCommand cd yay-bin
runCommand makepkg -sri --noconfirm
runCommand cd /home/"${USERVARIABLES[USERNAME]}"
fi
}
# enable network manager/disable dhcpcd
readyFinalBoot() {
runCommand sudo systemctl enable NetworkManager
if [[ $DRYRUN -eq 1 ]]; then
echo "Write DONE to $SCRIPTROOT/stage.cfg"
else
runCommand echo "DONE" >"$SCRIPTROOT"/stage.cfg
fi
# Remove no password for sudoers
runCommand sudo sed -i "s/%wheel ALL=(ALL) NOPASSWD: ALL/# %wheel ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers
}
#Start the script
driver