-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaarch
More file actions
executable file
·1992 lines (1776 loc) · 70.7 KB
/
aarch
File metadata and controls
executable file
·1992 lines (1776 loc) · 70.7 KB
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
# shellcheck disable=SC2320
# $KYAULabs: aarch,v 2.6.6 2023/04/09 03:52:31 kyau Exp $
# ▄▄▄▄ ▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
# █ ▄▄ ▄ ▄▄ ▄ ▄▄▄▄ ▄▄ ▄ ▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄ ▀
# █ ██ █ ██ █ ██ █ ██ █ ██ ██ █ ██ █ ██▀ █
# ■ ██▄▀ ██▄█ ██▄█ ██ █ ▀▀ ██ ██▄█ ██▄▀ ▀██▄ ■
# █ ██ █ ▄▄ █ ██ █ ██ █ ██▄▄ ██ █ ██ █ ▄██ █
# ▄ ▀▀ ▀ ▀▀▀▀ ▀▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀ ▀ ▀▀▀▀ ▀▀▀ █
# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀
#
# Automated Arch Linux (KYAU Labs Edition)
# Copyright (C) 2024 KYAU Labs (https://kyaulabs.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -u
IFS=$'\n\t'
# Default Functions {{{
function print_logo() {
printf " [0;1;30m▄▄▄▄ ▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄[0m▄▄▄[1m▄▄\\n"
printf " [30m█ [36m▄▄ ▄ ▄▄ ▄ ▄▄▄▄ ▄▄ ▄ [37m▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄ [47m▀[40m\\n"
printf " [30m█ [36m██ █ ██ █ ██ █ ██ █ [37m██ ██ █ ██ █ ██▀ [30m█\\n"
printf " ■ [36m██▄▀ ██▄█ ██▄█ ██ █ [31;41m▀▀[1C[37;40m██ ██▄█ ██▄▀ ▀██▄ [30m■\\n"
printf " █ [46m [36;40m█ █ [0;36m▄[1m▄ █ [46m [40m█ █ [46m [40m█ █ [47m [37m█[40m▄▄ [47m [40m█ █ [47m [40m█ █ [0m▄[1m██ [30m█\\n"
printf " [37;47m▄[1C[0;36m▀▀ ▀ ▀▀▀▀ ▀▀ ▀ ▀▀▀▀ [37m▀▀▀▀ ▀▀ ▀ ▀▀▀▀ ▀▀▀ [1;30m█\\n"
printf " [37m▀▀[0m▀▀▀[1;30m▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀[0m\\n\\n"
printf " Automated \e[1;37mArch \e[0;36mLinux\\n"
printf " \e[0;38;5;8m- KYAU Labs Edition\\n\\n"
}
function desc() {
>&2 printf "\\x1b[0;36m\\u25ab\\x1b[1;36m\\u25aa \\x1b[1;37m%s\\x1b[0m" "${1}"
}
function validate() {
# if failure else success
if [[ "$1" -ne 0 ]]; then
>&2 printf "\\n \\x1b[31mx\\x1b[0m %s\\n\\n" "${_AA_CMD}"
if [[ -z ${2+x} ]]; then
exit 1
fi
else
>&2 printf " \\x1b[1;32m\\u221a\\x1b[0m"
fi
}
# }}}
# MODULI Verification {{{
if [ ! -f moduli ]; then
print_logo
printf " \\x1b[38;5;124m‼ Missing non elliptic-curve primes (moduli)\\n\\n\\x1b[0m Run the following command to generate:\\n"
printf " \\x1b[38;5;235m#\\x1b[38;5;244m ssh-keygen -G mtmp -b 2048 && ssh-keygen -T moduli -f mtmp && rm mtmp\\n\\n"
exit 1
fi
# }}}
# Variables: Load/Prompt {{{
# Load Machine Template
for file in *.aa; do
if [ -f "$file" ]; then
# shellcheck disable=SC1090,SC1091
source "$file"
break
fi
done
# Machine Role
if [ -z ${AA_MACHINEROLE+x} ]; then
printf "Machine Role (dekstop/laptop/server/vm) [default: vm]: "
read -r AA_MACHINEROLE
if [ -z "$AA_MACHINEROLE" ]; then
AA_MACHINEROLE="vm"
fi
fi
# Machine Type
if [ -z ${AA_MACHINETYPE+x} ]; then
printf "Machine Type (mbr/uefi) [default: uefi]: "
read -r AA_MACHINETYPE
if [ -z "$AA_MACHINETYPE" ]; then
AA_MACHINETYPE="uefi"
fi
fi
# Full Disk Encryption
if [ -z ${AA_ENCRYPT+x} ]; then
printf "Full Disk Encryption (0/1) [default: 0]: "
read -r AA_ENCRYPT
if [ -z "$AA_ENCRYPT" ]; then
AA_ENCRYPT=0
fi
fi
# Xorg
if [ -z ${AA_XORG+x} ]; then
printf "Xorg (0-2) [default: 0]: "
read -r AA_XORG
if [ -z "$AA_XORG" ]; then
AA_XORG=0
fi
fi
# Installation Disk
if [ -z ${AA_DISK+x} ]; then
printf "Disk to use for install [default: /dev/sda]: "
read -r AA_DISK
if [ -z "$AA_DISK" ]; then
AA_DISK="/dev/sda"
fi
fi
# Hostname
if [ -z ${AA_HOSTNAME+x} ]; then
printf "Hostname [default: arch.local]: "
read -r AA_HOSTNAME
if [ -z "$AA_HOSTNAME" ]; then
AA_HOSTNAME="arch.local"
fi
AA_HOST=${AA_HOSTNAME%%.*}
else
AA_HOST=${AA_HOSTNAME%%.*}
fi
# Timezone
if [ -z ${AA_TZ+x} ]; then
printf "Timezone [default: America/Los_Angeles]: "
read -r AA_TZ
if [ -z "$AA_TZ" ]; then
AA_TZ="America/Los_Angeles"
fi
fi
# Swap
if [ -z ${AA_SWAP+x} ]; then
printf "Swap Size (in GB) [default: 4]: "
read -r AA_SWAP
if [ -z "$AA_SWAP" ]; then
AA_SWAP="4"
fi
fi
# Username
if [ -z ${AA_USERNAME+x} ]; then
printf "Username [default: kyau]: "
read -r AA_USERNAME
if [ -z "$AA_USERNAME" ]; then
AA_USERNAME="kyau"
fi
fi
# Root Password
if [ -z ${AA_PASSWD+x} ]; then
printf "Root/User password [default: moo]: "
read -r AA_PASSWD
if [ -z "$AA_PASSWD" ]; then
AA_PASSWD="moo"
fi
fi
# SSID
if [ -z ${AA_WIFI_SSID+x} ]; then
printf "WiFi SSID [default: SSID]: "
read -r AA_WIFI_SSID
if [ -z "$AA_WIFI_SSID" ]; then
AA_WIFI_SSID="SSID"
fi
fi
# WiFi Password
if [ -z ${AA_WIFI_PASSWD+x} ]; then
printf "WiFi password [default: moo]: "
read -r AA_WIFI_PASSWD
if [ -z "$AA_WIFI_PASSWD" ]; then
AA_WIFI_PASSWD="moo"
fi
fi
# IP Address
if [ -z ${AA_IPADDR+x} ]; then
printf "IP Address (DHCP if Blank): "
read -r AA_IPADDR
fi
if [ -n "$AA_IPADDR" ]; then
# Gateway
if [ -z ${AA_GATEWAY+x} ]; then
printf "Gateway [default: 10.0.42.1]: "
read -r AA_GATEWAY
if [ -z "$AA_GATEWAY" ]; then
AA_GATEWAY="10.0.42.1"
fi
fi
# DNS
if [ -z ${AA_DNS+x} ]; then
printf "DNS [default: 1.1.1.1]: "
read -r AA_DNS
if [ -z "$AA_DNS" ]; then
AA_DNS="1.1.1.1"
fi
fi
fi
# SSH Key
if [ -z ${AA_SSH_KEY+x} ]; then
printf "SSH Key [default: https://raw.githubusercontent.com/kyau/dotfiles/master/ssh/authorized_keys]: "
read -r AA_SSH_KEY
if [ -z "$AA_SSH_KEY" ]; then
AA_SSH_KEY="https://raw.githubusercontent.com/kyau/dotfiles/master/ssh/authorized_keys"
fi
fi
# Set Hidden Variables
if [ "${AA_MACHINEROLE^^}" = "VM" ]; then
AA_UCODE=""
fi
if [ -z "${AA_PKGMAN}" ]; then
AA_PKGMAN="pikaur"
fi
# }}}
# Variables: Summary {{{
print_logo
p_sshkey=${AA_SSH_KEY##*/}
s_passwd=""
if [ -n "${AA_WIFI_PASSWD}" ]; then
s_passwd=$(head -c ${#AA_WIFI_PASSWD} < /dev/zero | tr '\0' '*')
fi
p_passwd=$(head -c ${#AA_PASSWD} < /dev/zero | tr '\0' '*')
if [ -n "${AA_TLP_CONFIG}" ]; then
p_tlp=${AA_TLP_CONFIG##*/}
fi
if [ -n "${AA_TFAN_CONFIG}" ]; then
p_tfan=${AA_TFAN_CONFIG##*/}
fi
printf " \\x1b[38;5;255m┌\\x1b[38;5;242m────\\x1b[38;5;235m─·\\x1b[38;5;242m─\x1b[38;5;235m─·─────────────────────────────────────────────────┐\\n"
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mDisk: \\x1b[38;5;240m%-10s \\x1b[38;5;244mSwap: \\x1b[38;5;240m%-2sGB %-21s \\x1b[38;5;237m░░░·\\x1b[0m\\n" "${AA_DISK}" "${AA_SWAP}" " "
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mHost: \\x1b[38;5;240m%-10s \\x1b[38;5;244mHostname: \\x1b[38;5;240m%-24s\\x1b[0m \\x1b[38;5;237m░\\x1b[38;5;242m:\\x1b[0m\\n" "${AA_HOST}" "${AA_HOSTNAME}"
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mUsername: \\x1b[38;5;240m%-42s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${AA_USERNAME}"
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mPassword: \\x1b[38;5;240m%-42s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${p_passwd}"
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mMachine Role: \\x1b[38;5;240m%-38s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${AA_MACHINEROLE^^}"
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mMachine Type: \\x1b[38;5;240m%-38s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${AA_MACHINETYPE^^}"
if [ -n "${AA_WIFI_SSID}" ]; then
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mWiFi SSID: \\x1b[38;5;240m%-16s \\x1b[38;5;244mPassword: \\x1b[38;5;240m%-14s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${AA_WIFI_SSID}" "${s_passwd}"
fi
if [ -n "${AA_IPADDR}" ]; then
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mIP Address: \\x1b[38;5;240m%-15s \\x1b[38;5;244mGateway: \\x1b[38;5;240m%-15s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${AA_IPADDR}" "${AA_GATEWAY}"
else
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mIP Address: \\x1b[38;5;240m%-15s \\x1b[38;5;244mGateway: \\x1b[38;5;240m%-15s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "DHCP" "auto"
fi
TXT_DNS="auto"
if [ -n "${AA_DNS}" ]; then
TXT_DNS=${AA_DNS}
fi
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mDNS: \\x1b[38;5;240m%-47s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${TXT_DNS}"
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mTimezone: \\x1b[38;5;240m%-42s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${AA_TZ}"
if [ -n "${AA_TFAN_CONFIG}" ]; then
printf " \\x1b[38;5;242m│\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mThinkfan Config: \\x1b[38;5;240m%-35s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${p_tfan}"
fi
if [ -n "${AA_TLP_CONFIG}" ]; then
printf " \\x1b[38;5;235m·\\x1b[38;5;237m░\\x1b[0m \\x1b[38;5;244mTLP Config: \\x1b[38;5;240m%-40s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${p_tlp}"
fi
printf " \\x1b[38;5;235m│\\x1b[38;5;237m░░░ \\x1b[38;5;244mSSH Key: \\x1b[38;5;240m%-43s \\x1b[38;5;237m░\\x1b[38;5;242m│\\x1b[0m\\n" "${p_sshkey}"
printf " \\x1b[38;5;235m└─────────────────────────────────────────────·─\\x1b[38;5;242m─\\x1b[1;39m·─\\x1b[38;5;242m─\\x1b[1;39m─\\x1b[38;5;242m──────\\x1b[38;5;255m┘\\x1b[0m\\n"
# }}}
# Prereq: Internet Status {{{
echo -e
desc "Internet Status"
_AA_CMD="Internet Check"
/usr/bin/wget -q --tries=10 --timeout=20 --spider http://www.archlinux.org >/dev/null 2>&1
validate "$?"
printf "\\n"
# }}}
# Prereq: Disk Partition {{{
desc "Prereq: [0mDisk Partition"
if /usr/bin/mount | /usr/bin/grep /mnt > /dev/null; then
_AA_CMD="${AA_DISK}: Unmount All"
/usr/bin/umount -R /mnt >/dev/null 2>&1
validate "$?"
fi
_AA_CMD="${AA_DISK}: Erase (block-level wipe)"
/usr/bin/dd if=/dev/zero of="${AA_DISK}" bs=1k count=2048 >/dev/null 2>&1
validate "$?"
_AA_CMD="${AA_DISK}: Erase (filesystem signature)"
/usr/bin/wipefs -af "${AA_DISK}" >/dev/null 2>&1
validate "$?"
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_AA_CMD="${AA_DISK}: Erase (MBR/GPT data structs)"
/usr/bin/sgdisk -Z -o "${AA_DISK}" >/dev/null 2>&1
validate "$?"
fi
_AA_CMD="${AA_DISK}: Partition"
if [ "${AA_ENCRYPT}" -eq "1" ]; then
if [ "${AA_MACHINEROLE^^}" = "LAPTOP" ]; then
/usr/bin/sgdisk -n 1:0:256M -n 2:0:+50G -n 3:0:+50G -n 4:0:-0 -t 1:ef00 -t 2:8e00 -t 3:0700 -t 4:8e00 "${AA_DISK}" >/dev/null 2>&1
else
/usr/bin/sgdisk -n 1:0:256M -n 2:0:-0 -t 1:ef00 -t 2:8e00 "${AA_DISK}" >/dev/null 2>&1
fi
else
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
/usr/bin/sgdisk -n 1:0:256M -n 2:0:-0 -t 1:ef00 -t 2:8e00 "${AA_DISK}" >/dev/null 2>&1
else
echo -e "n\np\n\n\n+256M\nn\np\n\n\n\nt\n2\n8e\na\n1\nw\n" | /usr/bin/fdisk "${AA_DISK}" >/dev/null 2>&1
fi
fi
validate "$?"
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_AA_CMD="${AA_DISK}: Labels"
if [ "${AA_MACHINEROLE^^}" = "LAPTOP" ]; then
/usr/bin/sgdisk -c 1:"uefi" -c 2:"arch" -c 3:"win10" -c 4:"kali" "${AA_DISK}" >/dev/null 2>&1
else
/usr/bin/sgdisk -c 1:"uefi" -c 2:"arch" "${AA_DISK}" >/dev/null 2>&1
fi
validate "$?"
fi
# }}}
# Prereq: LUKS2 {{{
AA_DISKO="${AA_DISK}"
LASTCHAR="${AA_DISK: -1}"
re='^[0-9]+$'
if [[ $LASTCHAR =~ $re ]] ; then
AA_DISK="${AA_DISK}p" # modify variable if it ends in a number
fi
if [ "${AA_ENCRYPT}" -eq "1" ]; then
printf "\\n"
desc "Prereq: [0mLUKS2"
_AA_CMD="LUKS2: Clear Metadata"
/usr/bin/dmsetup remove_all >/dev/null 2>&1
/usr/bin/pvremove -y -ff "${AA_DISK}"* >/dev/null 2>&1
validate "$?"
_AA_CMD="LUKS2: Encrypting Partition ${AA_DISK}2"
printf "\n\x1b[38;5;6m ≡ WARNING:\x1b[0m encryption password will be needed at every boot\n"
/usr/bin/cryptsetup --type luks2 -q -c aes-xts-plain64 -l 512 -h sha512 --pbkdf argon2i --pbkdf-force-iterations 4 --pbkdf-memory 1048576 --pbkdf-parallel 1 --label archlinux --subsystem "" --use-random luksFormat "${AA_DISK}2"
validate "$?"
_AA_CMD="LUKS2: Decrypting Partition ${AA_DISK}2"
printf "\n"
/usr/bin/cryptsetup open --type luks2 "${AA_DISK}2" cryptlvm
validate "$?"
else
_AA_CMD="LVM: Clear Metadata"
/usr/bin/pvremove -y -ff "${AA_DISK}"* >/dev/null 2>&1
/usr/bin/dmsetup remove_all >/dev/null 2>&1
validate "$?"
fi
printf "\\n"
# }}}
# Prereq: LVM {{{
desc "Prereq: [0mLVM"
_AA_CMD="LVM: Initialize Physical Volume"
if [ "${AA_ENCRYPT}" -eq "1" ]; then
/usr/bin/pvcreate --yes -ff /dev/mapper/cryptlvm >/dev/null 2>&1
else
/usr/bin/pvcreate --yes -ff "${AA_DISK}2" >/dev/null 2>&1
fi
validate "$?"
_AA_CMD="LVM: Create Volume Group"
if [ "${AA_ENCRYPT}" -eq "1" ]; then
/usr/bin/vgcreate --yes "${AA_HOST}" /dev/mapper/cryptlvm >/dev/null 2>&1
else
/usr/bin/vgcreate --yes "${AA_HOST}" "${AA_DISK}2" >/dev/null 2>&1
fi
validate "$?"
if [ "${AA_SWAP}" -ne "0" ]; then
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-swap)"
/usr/bin/lvcreate --yes -L "${AA_SWAP}G" "${AA_HOST}" --name swap >/dev/null 2>&1
validate "$?"
fi
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-root)"
/usr/bin/lvcreate --yes -L 512M "${AA_HOST}" --name root >/dev/null 2>&1
validate "$?"
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-usr)"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
/usr/bin/lvcreate --yes -L 5G "${AA_HOST}" --name usr >/dev/null 2>&1
else
/usr/bin/lvcreate --yes -L 8G "${AA_HOST}" --name usr >/dev/null 2>&1
fi
validate "$?"
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-var)"
/usr/bin/lvcreate --yes -L 512M "${AA_HOST}" --name var >/dev/null 2>&1
validate "$?"
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-var_cache)"
if [ "${AA_MACHINEROLE^^}" = "VM" ]; then
/usr/bin/lvcreate --yes -L 1G "${AA_HOST}" --name var_cache >/dev/null 2>&1
else
/usr/bin/lvcreate --yes -L 2G "${AA_HOST}" --name var_cache >/dev/null 2>&1
fi
validate "$?"
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-var_log)"
/usr/bin/lvcreate --yes -L 512M "${AA_HOST}" --name var_log >/dev/null 2>&1
validate "$?"
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-var_log_audit)"
/usr/bin/lvcreate --yes -L 512M "${AA_HOST}" --name var_log_audit >/dev/null 2>&1
validate "$?"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-home)"
/usr/bin/lvcreate --yes -L 1G "${AA_HOST}" --name home >/dev/null 2>&1
validate "$?"
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-srv)"
/usr/bin/lvcreate --yes -l +100%FREE "${AA_HOST}" --name srv >/dev/null 2>&1
validate "$?"
else
_AA_CMD="LVM: Create Logical Volume (${AA_HOST}-home)"
/usr/bin/lvcreate --yes -l +100%FREE "${AA_HOST}" --name home >/dev/null 2>&1
validate "$?"
fi
printf "\\n"
# }}}
# Prereq: Filesystems {{{
desc "Prereq: [0mFilesystems"
_AA_CMD="Format: Ext4 (${AA_HOST}-root)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/root" >/dev/null 2>&1
validate "$?"
_AA_CMD="Format: Ext4 (${AA_HOST}-usr)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/usr" >/dev/null 2>&1
validate "$?"
_AA_CMD="Format: Ext4 (${AA_HOST}-var)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/var" >/dev/null 2>&1
validate "$?"
_AA_CMD="Format: Ext4 (${AA_HOST}-var_cache)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/var_cache" >/dev/null 2>&1
validate "$?"
_AA_CMD="Format: Ext4 (${AA_HOST}-var_log)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/var_log" >/dev/null 2>&1
validate "$?"
_AA_CMD="Format: Ext4 (${AA_HOST}-var_log_audit)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/var_log_audit" >/dev/null 2>&1
validate "$?"
_AA_CMD="Format: Ext4 (${AA_HOST}-home)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/home" >/dev/null 2>&1
validate "$?"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_AA_CMD="Format: Ext4 (${AA_HOST}-srv)"
/usr/bin/mkfs.ext4 -O metadata_csum "/dev/${AA_HOST}/srv" >/dev/null 2>&1
validate "$?"
fi
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_AA_CMD="Format: FAT32 (${AA_DISK}1)"
/usr/bin/mkfs.fat -F32 "${AA_DISK}1" >/dev/null 2>&1
validate "$?"
else
_AA_CMD="Format: Ext4 (${AA_DISK}1)"
/usr/bin/mkfs.ext4 -O metadata_csum "${AA_DISK}1" >/dev/null 2>&1
validate "$?"
fi
if [ "${AA_SWAP}" -ne "0" ]; then
_AA_CMD="Swap: Create"
/usr/bin/mkswap "/dev/${AA_HOST}/swap" >/dev/null 2>&1
validate "$?"
_AA_CMD="Swap: Enable"
/usr/bin/swapon "/dev/${AA_HOST}/swap" >/dev/null 2>&1
validate "$?"
fi
_AA_CMD="Mount: ${AA_HOST}-root => /mnt"
/usr/bin/mount -o defaults,noatime,journal_checksum "/dev/${AA_HOST}/root" /mnt >/dev/null 2>&1
validate "$?"
_AA_CMD="Create Directory Structure"
_ADD_DIR=""
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_ADD_DIR="/mnt/srv"
fi
/usr/bin/mkdir -p /mnt/boot /mnt/home /mnt/usr /mnt/var ${_ADD_DIR} >/dev/null 2>&1
validate "$?"
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_AA_CMD="Mount: UEFI => /mnt/boot"
/usr/bin/mount "${AA_DISK}1" /mnt/boot >/dev/null 2>&1
validate "$?"
else
_AA_CMD="Mount: ${AA_DISK}2 => /mnt/boot"
/usr/bin/mount "${AA_DISK}1" /mnt/boot >/dev/null 2>&1
validate "$?"
fi
_AA_CMD="Mount: ${AA_HOST}-home => /mnt/home"
/usr/bin/mount -o defaults,noatime,nodev,nosuid,journal_checksum "/dev/${AA_HOST}/home" /mnt/home >/dev/null 2>&1
validate "$?"
_AA_CMD="Mount: ${AA_HOST}-usr => /mnt/usr"
/usr/bin/mount -o defaults,noatime,journal_checksum "/dev/${AA_HOST}/usr" /mnt/usr >/dev/null 2>&1
validate "$?"
_AA_CMD="Mount: ${AA_HOST}-var => /mnt/var"
/usr/bin/mount -o defaults,noatime,nosuid,journal_checksum "/dev/${AA_HOST}/var" /mnt/var >/dev/null 2>&1
validate "$?"
_AA_CMD="Create Directory Structure: /var"
/usr/bin/mkdir -p /mnt/var/cache /mnt/var/log >/dev/null 2>&1
validate "$?"
_AA_CMD="Mount: ${AA_HOST}-var_cache => /mnt/var/cache"
/usr/bin/mount -o defaults,noatime,nodev,nosuid,journal_checksum "/dev/${AA_HOST}/var_cache" /mnt/var/cache >/dev/null 2>&1
validate "$?"
_AA_CMD="Mount: ${AA_HOST}-var_log => /mnt/var/log"
/usr/bin/mount -o defaults,noatime,nodev,noexec,nosuid,journal_checksum "/dev/${AA_HOST}/var_log" /mnt/var/log >/dev/null 2>&1
validate "$?"
_AA_CMD="Mount: ${AA_HOST}-var_log_audit => /mnt/var/log/audit"
/usr/bin/mkdir -p /mnt/var/log/audit >/dev/null 2>&1
/usr/bin/mount -o defaults,noatime,nodev,noexec,nosuid,journal_checksum "/dev/${AA_HOST}/var_log_audit" /mnt/var/log/audit >/dev/null 2>&1
validate "$?"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_AA_CMD="Mount: ${AA_HOST}-srv => /mnt/srv"
/usr/bin/mount -o defaults,noatime,nodev,nosuid,journal_checksum "/dev/${AA_HOST}/srv" /mnt/srv >/dev/null 2>&1
validate "$?"
fi
printf "\\n"
# }}}
# Installation {{{
desc "Installation"
# packages to remove after installation
_PACSTRAP_REMOVE=(linux pyalpm)
_PACSTRAP=(base base-devel haveged libpwquality linux-hardened rkhunter sysstat)
# packages that used to be in base
_PACSTRAP+=(linux-firmware logrotate lvm2 man-db man-pages)
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_PACSTRAP+=(apparmor usbguard)
fi
# bootloader
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_PACSTRAP+=(gptfdisk)
else
_PACSTRAP+=(grub)
fi
# filesystem
_PACSTRAP+=(rsync)
if [ ! "${AA_MACHINEROLE^^}" = "VM" ]; then
# ROLE=VM: nfs-utils is not auto-installed (security risk)
_PACSTRAP+=(nfs-utils)
fi
# networking / services
_PACSTRAP+=(bind-tools cronie nftables openssh)
# pacman / aur helper
_PACSTRAP+=(pacman-contrib pyalpm reflector)
# common
_PACSTRAP+=(arch-audit fish git sudo tmux vim wget)
_PACSTRAP+=(bc dateutils htop iotop inetutils)
# compression
_PACSTRAP+=(p7zip unrar)
#_PACSTRAP=(arch-audit base base-devel bc bind-tools cronie dateutils fish gptfdisk git htop iotop lsof nfs-utils nftables openssh p7zip pacman-contrib pyalpm refind-efi reflector sudo tmux unrar unzip vim zip)
if [ "${AA_UCODE^^}" = "INTEL" ]; then
_PACSTRAP+=(intel-ucode)
elif [ "${AA_UCODE^^}" = "AMD" ]; then
_PACSTRAP+=(amd-ucode)
fi
if [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_PACSTRAP+=(qemu-guest-agent)
else
_PACSTRAP+=(lm_sensors)
fi
if [ "${AA_XORG}" -ne "0" ]; then
_PACSTRAP+=(alsa-utils pulseaudio-alsa xorg-server xorg-xinit xorg-apps)
if [ "${AA_MACHINEROLE^^}" = "VM" ]; then
if [ "${AA_XORG}" -eq "1" ]; then
_PACSTRAP+=(spice-vdagent xf86-video-qxl)
fi
else
if [ "${AA_XORG}" -eq "1" ]; then
_PACSTRAP+=(libva-intel-driver libvdpau-va-gl mesa-vdpau vdpauinfo vulkan-intel)
elif [ "${AA_XORG}" -eq "2" ]; then
_PACSTRAP+=(mesa-vdpau nvidia-dkms nvidia-settings vdpauinfo)
fi
fi
fi
if [ -n "${AA_TFAN_CONFIG}" ]; then
_PACSTRAP+=(boost cmake libatasmart yaml-cpp)
_PACSTRAP_REMOVE+=(boost cmake)
fi
if [ -n "${AA_TLP_CONFIG}" ]; then
_PACSTRAP+=(tlp)
fi
if [ -n "${AA_WIFI_SSID}" ]; then
_PACSTRAP+=(wpa_supplicant)
fi
_AA_CMD="Pacstrap Installation Script"
/usr/bin/pacstrap "-K" "/mnt" "${_PACSTRAP[@]}" >/dev/null 2>&1
validate "$?"
printf "\\n"
# }}}
# Config: Mount Points {{{
desc "Config: [0mMount Points"
_AA_CMD="Generate: /etc/fstab"
/usr/bin/genfstab -pU /mnt >> /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /boot"
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
/usr/bin/sed -i 's/rw,relatime,fmask/ro,noatime,nodev,noexec,nosuid,fmask/' /mnt/etc/fstab
else
/usr/bin/sed -i 's/rw,relatime,stripe=4/ro,noatime,nodev,noexec,nosuid,stripe=4/' /mnt/etc/fstab
fi
validate "$?"
_AA_CMD="Fstab: Secure /"
/usr/bin/sed -i 's/rw,noatime\t0 1/defaults,noatime\t0 1/' /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /var"
/usr/bin/sed -i 's/\/var[\t ]*ext4[\t ]*rw/\/var\t\text4\t\trw,nodev/' /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /dev & /dev/shm"
echo -e "# /dev: device nodes\ndevtmpfs\t/dev\tdevtmpfs\tdefaults,noexec,nosuid\t0 0\n\n# /dev/shm: shared application memory\ntmpfs\t/dev/shm\ttmpfs\tdefaults,noatime,nodev,nosuid,noexec,size=1024M,mode=1770,uid=root,gid=shm\t0 0\n" >> /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /tmp"
echo -e "# /tmp: temporary files\ntmpfs\t/tmp\t\ttmpfs\tdefaults,noatime,nodev,noexec,nosuid,size=8192M,mode=1777\t0 0\n" >> /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /var/tmp"
echo -e "# /var/tmp: temporary files (preserved)\n/tmp\t/var/tmp\tnone\tdefaults,noatime,nodev,noexec,nosuid,bind\t0 0\n" >> /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /var/cache/makepkg"
echo -e "# /var/cache/makepkg: temporary build dir\ntmpfs\t/var/cache/makepkg\t\ttmpfs\tdefaults,noatime,nodev,nosuid,size=4096M,mode=1770,uid=root,gid=wheel\t0 0\n" >> /mnt/etc/fstab
validate "$?"
_AA_CMD="Fstab: Secure /proc"
if [ "${AA_XORG}" -ne "0" ]; then
echo -e "# /proc: kernel and process information\nproc\t/proc\t\tproc\tnodev,noexec,nosuid,gid=wheel\t0 0" >> /mnt/etc/fstab
else
echo -e "# /proc: kernel and process information\nproc\t/proc\t\tproc\tnodev,noexec,nosuid,hidepid=2,gid=wheel\t0 0" >> /mnt/etc/fstab
fi
validate "$?"
echo -en "\n# vim: ft=fstab sts=4 sw=4 ts=4 noet:\n" >> /mnt/etc/fstab
printf "\\n"
# }}}
# Config: User Accounts {{{
desc "Config: [0mUser Accounts"
_AA_CMD="Enforce Strong Passwords"
/usr/bin/cat > /mnt/etc/pam.d/passwd << EOF
#%PAM-1.0
password required pam_pwquality.so retry=2 difok=6 minlen=12 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1 maxrepeat=2 maxsequence=4 reject_username
password required pam_unix.so use_authtok shadow sha512 rounds=65535
EOF
_AA_CMD="Enforce Password Rotation (4 years)"
/usr/bin/sed -i -e 's/^PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t1460/' -e 's/^PASS_MIN_DAYS\t0/PASS_MIN_DAYS\t1/' /mnt/etc/login.defs
validate "$?"
_AA_CMD="Enforce Password Rounds (SHA512)"
/usr/bin/cat >> /mnt/etc/login.defs << EOF
SHA_CRYPT_MIN_ROUNDS=655360
SHA_CRYPT_MAX_ROUNDS=655360
EOF
validate "$?"
_AA_CMD="Modify: Superuser Password"
/usr/bin/arch-chroot /mnt chpasswd <<< "root:${AA_PASSWD}" >/dev/null 2>&1
validate "$?"
_AA_CMD="Create: User Account ${AA_USERNAME}"
/usr/bin/arch-chroot /mnt useradd -m -G wheel,systemd-journal -s /bin/bash "${AA_USERNAME}"
validate "$?"
_AA_CMD="Modify: User Password ${AA_USERNAME}"
/usr/bin/arch-chroot /mnt chpasswd <<< "${AA_USERNAME}:${AA_PASSWD}" >/dev/null 2>&1
validate "$?"
_AA_CMD="Create: /etc/sudoers.d/kyaulabs"
/usr/bin/cat > /mnt/etc/sudoers.d/kyaulabs << EOF
Defaults editor=/usr/bin/rvim
Defaults env_keep += "SSH_AUTH_SOCK"
%wheel ALL=(ALL:ALL) ALL
%wheel ALL=(ALL:ALL) NOPASSWD:/usr/sbin/checkupdates
EOF
validate "$?"
_AA_CMD="Permissions: /etc/sudoers.d/kyaulabs"
/usr/bin/chmod 600 /mnt/etc/sudoers.d/kyaulabs
validate "$?"
_AA_CMD="Groupadd: ssh"
/usr/bin/arch-chroot /mnt groupadd ssh
/usr/bin/arch-chroot /mnt gpasswd -a "${AA_USERNAME}" ssh >/dev/null 2>&1
validate "$?"
_AA_CMD="Groupadd: shm"
/usr/bin/arch-chroot /mnt groupadd shm
/usr/bin/arch-chroot /mnt gpasswd -a "${AA_USERNAME}" shm >/dev/null 2>&1
validate "$?"
printf "\\n"
# }}}
# Config: Bootloader {{{
desc "Config: [0mBootloader"
if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_AA_CMD="Install: systemd-boot"
/usr/bin/arch-chroot /mnt bootctl install >/dev/null 2>&1
validate "$?"
_AA_CMD="Create: systemd-boot Pacman Hook"
/usr/bin/mkdir -p /mnt/etc/pacman.d/hooks/
/usr/bin/cat > /mnt/etc/pacman.d/hooks/00-systemd-boot.hook << EOF
[Trigger]
Type = Package
Operation = Upgrade
Target = systemd
[Action]
Description = Updating systemd-boot
When = PostTransaction
Exec = /usr/bin/bootctl update
EOF
validate "$?"
_AA_CMD="Modify: /boot/loader/loader.conf"
/usr/bin/cat > /mnt/boot/loader/loader.conf << EOF
default arch.conf
timeout 5
console-mode max
editor no
EOF
_AA_CMD="Modify: /boot/loader/entries/arch.conf"
_ROOT="root=/dev/${AA_HOST}/root"
_OPTIONS="rw add_efi_memmap zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=20 zswap.zpool=z3fold"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_OPTIONS="${_OPTIONS} apparmor=1 security=apparmor lsm=landlock,lockdown,yama,integrity,apparmor,bpf audit=1"
fi
if [ ! "${AA_MACHINEROLE^^}" = "VM" ]; then
if [ "${AA_XORG}" -eq "1" ]; then
_OPTIONS="${_OPTIONS} i915.enable_fbc=1 i915.enable_guc=2 i915.fastboot=1"
elif [ "${AA_XORG}" -eq "2" ]; then
_OPTIONS="${_OPTIONS} nvidia-drm.modeset=1 nvidia.NVreg_UsePageAttributeTable=1"
fi
fi
if [ "${AA_ENCRYPT}" -eq "1" ]; then
_UUID_LUKS=$(blkid -s UUID -o value "${AA_DISK}2")
_ROOT="rd.luks.name=${_UUID_LUKS}=cryptlvm rd.luks.options=discard root=/dev/${AA_HOST}/root resume=/dev/${AA_HOST}/swap"
fi
if [ "${AA_UCODE^^}" = "AMD" ]; then
_OPTIONS="initrd /amd-ucode.img\ninitrd /initramfs-linux-hardened.img\noptions ${_ROOT} ${_OPTIONS}"
elif [ "${AA_UCODE^^}" = "INTEL" ]; then
_OPTIONS="initrd /intel-ucode.img\ninitrd /initramfs-linux-hardened.img\noptions ${_ROOT} ${_OPTIONS}"
else
_OPTIONS="initrd /initramfs-linux-hardened.img\noptions ${_ROOT} ${_OPTIONS}"
fi
/usr/bin/echo -e "title Arch Linux\nlinux /vmlinuz-linux-hardened\n${_OPTIONS}" > /mnt/boot/loader/entries/arch.conf
validate "$?"
else
_AA_CMD="Install: GRUB2"
/usr/bin/partprobe "${AA_DISKO}"
/usr/bin/arch-chroot /mnt grub-install --target=i386-pc "${AA_DISKO}" >/dev/null 2>&1
validate "$?"
_AA_CMD="Secure: GRUB2"
GRUB_PASSWD=$(echo -e "${AA_PASSWD}\n${AA_PASSWD}\n" | /mnt/usr/sbin/grub-mkpasswd-pbkdf2 | tail -n 1 | cut -d ' ' -f 7)
/usr/bin/cat > /mnt/etc/grub.d/05_superusers << EOL
cat << EOF
set superusers="${AA_USERNAME}"
password_pbkdf2 ${AA_USERNAME} ${GRUB_PASSWD}
EOF
EOL
chmod 0700 /mnt/etc/grub.d/05_superusers
validate "$?"
_AA_CMD="Secure: GRUB2 Menu Entries"
/usr/bin/sed -i "s/ \${CLASS} / \${CLASS} --users \'\' /" /mnt/etc/grub.d/10_linux
validate "$?"
_AA_CMD="Config: GRUB2 Kernel Parameters"
_OPTIONS="zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=20 zswap.zpool=z3fold"
_TIMEOUT="10"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_TIMEOUT="3"
_OPTIONS="${_OPTIONS} apparmor=1 security=apparmor lsm=landlock,lockdown,yama,integrity,apparmor,bpf audit=1"
fi
if [ "${AA_UCODE^^}" = "AMD" ]; then
_OPTIONS="${_OPTIONS} initrd=/amd-ucode.img"
elif [ "${AA_UCODE^^}" = "INTEL" ]; then
_OPTIONS="${_OPTIONS} initrd=/intel-ucode.img"
fi
if [ ! "${AA_MACHINEROLE^^}" = "VM" ]; then
if [ "${AA_XORG}" -eq "1" ]; then
_OPTIONS="${_OPTIONS} i915.enable_fbc=1 i915.enable_guc=2 i915.fastboot=1"
elif [ "${AA_XORG}" -eq "2" ]; then
_OPTIONS="${_OPTIONS} nvidia-drm.modeset=1 nvidia.NVreg_UsePageAttributeTable=1"
fi
fi
/usr/bin/sed -i -e "s/GRUB_TIMEOUT=5/GRUB_TIMEOUT=${_TIMEOUT}/" -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\"loglevel=3 quiet\"/GRUB_CMDLINE_LINUX_DEFAULT=\"${_OPTIONS}\"/" /mnt/etc/default/grub
validate "$?"
if [ "${AA_ENCRYPT}" -eq "1" ]; then
_AA_CMD="Config: GRUB2 LUKS Support"
/usr/bin/sed -i 's/#GRUB_ENABLE_CRYPT/GRUB_ENABLE_CRYPT/' /mnt/etc/default/grub
validate "$?"
fi
_AA_CMD="Config: GRUB2"
/usr/bin/arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg >/dev/null 2>&1
validate "$?"
fi
_AA_CMD="Install: Console Font"
/usr/bin/wget https://gitlab.com/kyaulabs/refind-aarch/raw/master/fonts/agave-r.psf.gz -O /mnt/usr/share/kbd/consolefonts/agave-r.psf.gz >/dev/null 2>&1
validate "$?"
printf "\\n"
# }}}
# Config: Kernel {{{
desc "Config: [0mKernel"
_AA_CMD="Modify: /etc/mkinitcpio.conf"
_MODULES="crc32_generic crc32c-intel fuse lz4 lz4_compress"
if [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_MODULES="${_MODULES} virtio virtio_blk virtio_pci virtio_net"
else
if [ "${AA_XORG}" -eq "1" ]; then
_MODULES="${_MODULES} i915"
elif [ "${AA_XORG}" -eq "2" ]; then
_MODULES="${_MODULES} nvidia nvidia_modeset nvidia_uvm nvidia_drm"
fi
fi
if [ "${AA_MACHINEROLE^^}" = "SERVER" ]; then
_MODULES="acpi_ipmi ${_MODULES}"
fi
_STRING=("-i" "-e" "s/^MODULES=()/MODULES=(${_MODULES})/")
if [ "${AA_ENCRYPT}" -eq "1" ]; then
_STRING+=("-e" "s/base udev autodetect modconf kms keyboard keymap consolefont block filesystems/systemd keyboard sd-vconsole autodetect modconf kms keymap block sd-encrypt lvm2 filesystems/")
else
#if [ "${AA_MACHINETYPE^^}" = "UEFI" ]; then
_STRING+=("-e" "s/base udev autodetect modconf kms keyboard keymap consolefont block filesystems/systemd keyboard sd-vconsole autodetect modconf kms keymap block lvm2 filesystems/")
#else
#_STRING+=("-e" "s/base udev autodetect modconf kms block filesystems keyboard/base udev keyboard consolefont autodetect modconf kms block lvm2 filesystems/")
#fi
fi
/usr/bin/sed "${_STRING[@]}" /mnt/etc/mkinitcpio.conf >/dev/null 2>&1
validate "$?"
_AA_CMD="Config: /etc/vconsole.conf"
/usr/bin/cat > /mnt/etc/vconsole.conf <<EOF
FONT=agave-r
MAP=8859-2
EOF
validate "$?"
_AA_CMD="Generate: Initial Ramdisk Environment"
/usr/bin/arch-chroot /mnt mkinitcpio -P >/dev/null 2>&1
validate "$?"
if [ "${AA_XORG}" -eq "2" ]; then
_AA_CMD="Create: NVIDIA Pacman Hook"
/usr/bin/mkdir -p /mnt/etc/pacman.d/hooks/
/usr/bin/cat > /mnt/etc/pacman.d/hooks/nvidia.conf << EOF
[Trigger]
Operation=Install
Operation=Upgrade
Operation=Remove
Type=Package
Target=nvidia-dkms
Target=linux-hardened
# Change the linux part above and in the Exec line if a different kernel is used
[Action]
Description=Update Nvidia module in initcpio
Depends=mkinitcpio
When=PostTransaction
NeedsTargets
Exec=/bin/sh -c 'while read -r trg; do case \$trg in linux) exit 0; esac; done; /usr/bin/mkinitcpio -P'
EOF
validate "$?"
fi
_AA_CMD="Security: Kernel Runtime Parameters"
/usr/bin/cat > /mnt/etc/sysctl.d/50-security.conf << EOF
dev.tty.ldisc_autoload=0
fs.protected_fifos=2
fs.protected_regular=2
fs.suid_dumpable=0
kernel.dmesg_restrict=1
kernel.kptr_restrict=2
kernel.sysrq=0
kernel.unprivileged_bpf_disabled=1
net.ipv4.conf.all.log_martians=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.log_martians=1
net.ipv4.conf.default.secure_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_rfc1337=1
EOF
if [ ! "${AA_MACHINEROLE^^}" = "SERVER" ]; then
/usr/bin/cat >> /mnt/etc/sysctl.d/50-security.conf << EOF
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_redirects=0
net.ipv6.conf.all.accept_redirects=0
net.ipv6.conf.default.accept_redirects=0
EOF
fi
validate "$?"
if [ "${AA_MACHINEROLE^^}" = "SERVER" ] || [ "${AA_MACHINEROLE^^}" = "VM" ]; then
_AA_CMD="Blacklist Kernel Modules"
/usr/bin/cat > /mnt/etc/modprobe.d/blacklist.conf << EOF
install affs /bin/false
install befs /bin/false
#install cifs /bin/false
install coda /bin/false
install cramfs /bin/false
install dccp /bin/true
install firewire-core /bin/false
install hfs /bin/false
install hfsplus /bin/false
install ip_tables /bin/false
install jfs /bin/false
install jffs2 /bin/false
install kafs /bin/false
install mtd /bin/false
install nilfs2 /bin/false
install ocfs2 /bin/false
install omfs /bin/false
install orangefs /bin/false
install overlay /bin/false
#install reiserfs /bin/false
install rds /bin/true
install romfs /bin/false
install sctp /bin/true
install squashfs /bin/false
install tipc /bin/true
install ubifs /bin/false
install udf /bin/false
install usb-storage /bin/false
blacklist dccp
blacklist sctp
blacklist rds
blacklist tipc
EOF
validate "$?"
fi
_AA_CMD="Symlink: /etc/localtime"
/usr/bin/arch-chroot /mnt ln -sf "/usr/share/zoneinfo/${AA_TZ}" /etc/localtime
validate "$?"
_AA_CMD="Sync: Hardware Clock"
/usr/bin/arch-chroot /mnt hwclock --systohc
validate "$?"
_AA_CMD="Modify: /etc/locale.gen"
/usr/bin/sed -i 's/^#en_US\.UTF/en_US\.UTF/' /mnt/etc/locale.gen >/dev/null 2>&1
validate "$?"
_AA_CMD="Generate: Locale"
/usr/bin/arch-chroot /mnt locale-gen >/dev/null 2>&1
validate "$?"
_AA_CMD="Modify: /etc/locale.conf"
echo "LANG=en_US.UTF-8" > /mnt/etc/locale.conf
validate "$?"
printf "\\n"
# }}}
# Config: Security Defaults {{{
desc "Config: [0mSecurity Defaults"
_AA_CMD="Modify: Root \$EDITOR"
echo -e "EDITOR=/usr/bin/rvim\nSUDO_EDITOR=/usr/bin/rvim" >> /mnt/root/.bashrc
validate "$?"
_AA_CMD="Create: /etc/issue"
/usr/bin/cat > /mnt/etc/issue << EOF
Unauthorized access to this system is prohibited
Press <Ctrl-D> if you are not an authorized user
EOF
/usr/bin/cp -f /mnt/etc/issue /mnt/etc/issue.net >/dev/null 2>&1
/usr/bin/chmod 644 /mnt/etc/issue /mnt/etc/issue.net
validate "$?"