-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-install
executable file
·673 lines (629 loc) · 20.2 KB
/
arch-install
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
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/arch-install
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/arch-install
## https://davoudarsalani.ir
function display_help {
local cmd
cmd="
-h|--help help
-c|--connect connect to wifi
-v|--verify verify if in uefi mode
-l|--legacy legacy
-u|--uefi uefi (Ermanno Ferrari)" ## https://ermannoferrari.net/arch-linux-full-install-on-uefi-from-the-terminal-to-productivity
display_cmd "$cmd"
exit
}
function display_cmd {
printf '\e[0;49;90m%s\e[0m\n' "$@" | sed 's/^ *//g'
}
function legacy_fg {
printf '\e[0;49;34m%s\e[0m\n' "$@"
}
function uefi_fg {
printf '\e[38;5;64m%s\e[0m\n' "$@"
}
function display_mode {
"$fg_color" "$mode"
}
function not_valid {
local msg
## NOTE do NOT use (( choice == choice )) to check if choice is a number:
[ "$choice" -eq "$choice" ] 2>/dev/null && msg='out of range' || msg='not valid'
printf '%s is %s\n' "$("$fg_color" "$choice")" "$msg"
}
function read_user_choice {
local space
for ((i=0; i<"${#main_items[@]}"; i++)); {
(( i < 10 )) && space=' ' || space=' '
printf '%s%s%s\n' "$("$fg_color" "$i")" "$space" "${main_items[$i]}" | sed 's/\t/ /g'
}
read -p ">>${space}" choice
}
u='nnnn'
runnable='false'
case "$1" in
-l|--legacy ) ## {{{
mode='LEGACY'
fg_color='legacy_fg'
display_mode
main_items=(
'find fastest mirrorlist'
'partitioning'
'pacstrap'
'genfstab'
'chroot'
'locale'
'timedatectl'
'host/hosts'
'multilib'
'sync repos'
'add user'
'password'
'bash* grub'
'network*'
'reboot'
'xorg* awesome lightdm*'
'reboot'
)
read_user_choice
case "$choice" in
0 )
runnable='true'
cmd="
## reflector: ## JUMP_1
pacman -Syy
pacman -S reflector
cp /etc/pacman.d/{mirrorlist,mirrorlist.bak}
## ignore the errors in case it fails to rate some mirrors:
reflector --country Iran --age 6 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
pacman -Syy"
display_cmd "$cmd"
;;
1 )
cmd="
lsblk
cfdisk /dev/sd_ [choose 'dos']
sd_1 for / bootable
sd_2 for home
sd_3 for swap
mkfs.ext4 /dev/sd_1
mount /dev/sd_1 /mnt
mkfs.ext4 /dev/sd_2
mkdir /mnt/home
mount /dev/sd_2 /mnt/home
mkswap /dev/sd_3
swapon /dev/sd_3"
display_cmd "$cmd"
;;
2 )
## JUMP_2
runnable='true'
cmd="
pacstrap /mnt base base-devel linux-lts linux-firmware
## to be installed manually:
## cryptsetup device-mapper dhcpcd diffutils e2fsprogs inetutils jfsutils less linux linux-firmware logrotate
## lvm2 man-db man-pages mdadm nano netctl perl reiserfsprogs s-nail sysfsutils texinfo usbutils vi which xfsprogs"
display_cmd "$cmd"
;;
3 )
runnable='true'
cmd="
genfstab -U /mnt >> /mnt/etc/fstab"
display_cmd "$cmd"
;;
4 )
runnable='true'
cmd="
arch-chroot /mnt /bin/bash"
display_cmd "$cmd"
;;
5 )
## JUMP_4
runnable='true'
cmd="
sed -i 's/^#en_US\./en_US\./;s/^#fa_IR /fa_IR /' /etc/locale.gen
locale-gen
printf 'LANG=en_US.UTF-8\n' > /etc/locale.conf
export LANG=en_US.UTF-8"
display_cmd "$cmd"
;;
6 )
runnable='true'
cmd="
## list time zones:
# timedatectl list-timezones ## JUMP_3
ln -fs /usr/share/zoneinfo/Asia/Tehran /etc/localtime
hwclock --systohc --utc
timedatectl set-ntp true"
display_cmd "$cmd"
;;
7 )
## JUMP_5
runnable='true'
cmd="
printf 'acer\n' > /etc/hostname
printf '127.0.0.1 localhost\n::1 localhost\n127.0.1.1 acer.localdomain acer\n' > /etc/hosts"
display_cmd "$cmd"
;;
8 )
runnable='true'
## edit next line after pattern using sed (https://unix.stackexchange.com/questions/285160/how-to-edit-next-line-after-pattern-using-sed)
cmd="
sed -i '$!N;s/^#\(\[multilib\]\n\)#\(Include\)/\1\2/;P;D' /etc/pacman.conf"
display_cmd "$cmd"
;;
9 )
runnable='true'
cmd="
pacman -Sy"
display_cmd "$cmd"
;;
10 )
## JUMP_6
cmd="
## method 1 (recommended):
useradd -mG wheel -s /bin/bash $u
EDITOR=vim visudo
## uncomment/add this line:
# %wheel ALL=(ALL) NOPASSWD: ALL
## method 2:
useradd -m -g users -G lp -s /bin/bash $u # also -G lp,autologin,storage,wheel,power
EDITOR=vim visudo
## add '$u ALL=(ALL) NOPASSWD: ALL' under the line 'root = ALL=(ALL) ALL' (without the quotes)
## method 3 (Luke Smith version) (www.youtube.com/watch?v=nSHOb8YU9Gw):
useradd -m -g wheel $u
EDITOR=vim visudo
## add this line:
%wheel ALL=(ALL) NOPASSWD: ALL
## alternatively, you can have these two lines where you specify which commands to be run without asking for a password:
%wheel ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: COMMAND_1, COMMAND_2, COMMAND_3"
display_cmd "$cmd"
;;
11 )
cmd="
passwd
passwd $u"
display_cmd "$cmd"
;;
12 )
cmd="
pacman -S bash bash-completion grub
grub-install --recheck --debug --force /dev/sd_
grub-mkconfig -o /boot/grub/grub.cfg"
display_cmd "$cmd"
;;
13 )
cmd="
pacman -S networkmanager network-manager-applet
sudo systemctl enable NetworkManager
## enable ethernet:
sudo systemctl enable dhcpcd
# ip a
sudo systemctl enable dhcpcd@enp4s0f1"
display_cmd "$cmd"
;;
14 )
cmd="
reboot"
display_cmd "$cmd"
;;
15 )
runnable='true'
cmd="
sudo pacman -S xorg xorg-xinit xorg-server xorg-apps xorg-drivers xorg-xkill awesome
# sudo pacman -S lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings
# sudo systemctl enable lightdm.service"
display_cmd "$cmd"
;;
16 )
cmd="
reboot"
;;
* )
not_valid
;;
esac
;;
## }}}
-u|--uefi ) ## {{{
mode='UEFI (Ermanno Ferrari)'
fg_color='uefi_fg'
display_mode
main_items=(
'timedatectl and find fastest mirrorlist'
'partitioning'
'pacstrap'
'genfstab'
'chroot'
'time zone / clock'
'locale'
'host/hosts'
'root password'
'generate initramfs'
'grub xorg* awesome bash* efibootmgr networkmanager etc.'
'grub'
'enable NetworkManager'
'add user'
'user password'
'umount and reboot'
'nmtui'
)
read_user_choice
case "$choice" in
0 )
runnable='true'
cmd="
timedatectl set-ntp true
## reflector: ## JUMP_1
pacman -Syy
pacman -S reflector
cp /etc/pacman.d/{mirrorlist,mirrorlist.bak}
## ignore the errors in case it fails to rate some mirrors:
reflector --country Iran --age 6 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
pacman -Syy"
display_cmd "$cmd"
;;
1 )
cmd="
lsblk OR lsblk -f
gdisk /dev/sd_ <<< NOTE do NOT confuse 'gdisk' with 'fdisk'
## first, type g to create gpt table, then go on to create partitions
g create gpt table o create dos/mbr table n new partition
d delete partition p print status w write
a bootable flag m help
t change type (1 for efi, 19 for swap [or 82 !], 83 for linux)
## +512M for size <--,-- uefi
## ef00 for Hex[!] <--'
## 8200 for Hex[!] <-- swap
## leave Hex/GUID line blank as is <-- root
## leave Hex/GUID line blank as is <-- home
sd_1 for uefi
sd_2 for swap
sd_3 for /
sd_4 for home
mkfs.vfat /dev/sd_1 ## OR mkfs.fat -F 32 /dev/sd_1 (by Arch Wiki)
mkswap /dev/sd_2
swapon /dev/sd_2
mkfs.ext4 /dev/sd_3
mkfs.ext4 /dev/sd_4
mount /dev/sd_3 /mnt <-- mount root
mkdir /mnt/home <--,-- mount home
mount /dev/sd_4 /mnt/home <--'
mkdir -p /mnt/boot/efi <--,-- mount efi
mount /dev/sd_1 /mnt/boot/efi <--' <-- NOTE mount this last"
display_cmd "$cmd"
;;
2 )
## JUMP_2
runnable='true'
cmd="
pacstrap /mnt base base-devel linux-lts linux-firmware
## to be installed manually:
## cryptsetup device-mapper dhcpcd diffutils e2fsprogs inetutils jfsutils less linux linux-firmware logrotate
## lvm2 man-db man-pages mdadm nano netctl perl reiserfsprogs s-nail sysfsutils texinfo usbutils vi which xfsprogs"
display_cmd "$cmd"
;;
3 )
runnable='true'
cmd="
genfstab -U /mnt >> /mnt/etc/fstab"
display_cmd "$cmd"
;;
4 )
runnable='true'
cmd="
arch-chroot /mnt"
display_cmd "$cmd"
;;
5 )
runnable='true'
cmd="
## list time zones:
# timedatectl list-timezones ## JUMP_3
ln -fs /usr/share/zoneinfo/Asia/Tehran /etc/localtime
hwclock --systohc"
display_cmd "$cmd"
;;
6 )
## JUMP_4
runnable='true'
cmd="
sed -i 's/^#en_US\./en_US\./;s/^#fa_IR /fa_IR /' /etc/locale.gen
locale-gen
printf 'LANG=en_US.UTF-8\n' > /etc/locale.conf
export LANG=en_US.UTF-8"
display_cmd "$cmd"
;;
7 )
## JUMP_5
runnable='true'
cmd="
printf 'acer\n' > /etc/hostname
printf '127.0.0.1 localhost\n::1 localhost\n127.0.1.1 acer.localdomain acer\n' > /etc/hosts"
display_cmd "$cmd"
;;
8 )
cmd="
passwd"
display_cmd "$cmd"
;;
9 )
cmd="
## NOTE this was NOT mentioned by Ermanno
## Arch Wiki: Creating a new initramfs is usually not required, because mkinitcpio was run on installation of the kernel package with pacstrap.
mkinitcpio -P OR mkinitcpio -p linux-lts"
display_cmd "$cmd"
;;
10 )
runnable='true'
cmd="
pacman -S grub xorg xorg-xinit xorg-server xorg-apps xorg-drivers xorg-xkill awesome bash bash-completion efibootmgr linux-headers
pacman -S networkmanager network-manager-applet nm-connection-editor wireless_tools wpa_supplicant
# pacman -S xdg-utils xdg-user-dirs mtools dosfstools"
display_cmd "$cmd"
;;
11 )
runnable='true'
cmd="
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
## also (by Stephen): --bootloader-id=GRUB
## also (by Dwix): [no --efi-directory=/boot/efi] --bootloader-id=grub_uefi --recheck
grub-mkconfig -o /boot/grub/grub.cfg"
display_cmd "$cmd"
;;
12 )
runnable='true'
cmd="
systemctl enable NetworkManager"
display_cmd "$cmd"
;;
13 )
## JUMP_6
cmd="
## method 1 (recommended):
useradd -mG wheel -s /bin/bash $u
EDITOR=vim visudo
## uncomment/add this line:
# %wheel ALL=(ALL) NOPASSWD: ALL
## method 2:
useradd -m -g users -G lp -s /bin/bash $u # also -G lp,autologin,storage,wheel,power
EDITOR=vim visudo
## add '$u ALL=(ALL) NOPASSWD: ALL' under the line 'root = ALL=(ALL) ALL' (without the quotes)
## method 3 (Luke Smith version) (www.youtube.com/watch?v=nSHOb8YU9Gw):
useradd -m -g wheel $u
EDITOR=vim visudo
## add this line:
%wheel ALL=(ALL) NOPASSWD: ALL
## alternatively, you can have these two lines where you specify ehich commands to be run without asking for a password:
%wheel ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: COMMAND_1, COMMAND_2, COMMAND_3"
display_cmd "$cmd"
;;
14 )
cmd="
passwd $u"
display_cmd "$cmd"
;;
15 )
cmd="
exit
umount -a
reboot"
display_cmd "$cmd"
;;
16 )
cmd="
ip a
nmtui"
display_cmd "$cmd"
;;
* )
not_valid
;;
esac
;;
## }}}
-c|--connect ) ## {{{
cmd="
iwctl
## list of devices:
device list OR station list
## get available networks:
station <DEVCICE> get-networks
## connect:
station <DEVCICE> connect <SSID>
## enter password and exit
exit"
display_cmd "$cmd"
;;
## }}}
-v|--verify ) ## {{{
runnable='true'
cmd="
ls /sys/firmware/efi/efivars 2>/dev/null && printf 'UEFI mode verified: YES\n' || printf 'UEFI mode verified: NO\n'"
display_cmd "$cmd"
;;
## }}}
* )
display_help
;;
esac
if [ "$runnable" == 'true' ]; then
printf '\n'
read -p "Run [N/y]? " run_prompt
[ "${run_prompt,}" == 'y' ] && eval "$cmd"
fi
## {{{ contents of arch-legacy-installation-guide file before turning into this script (providing commands for the legacy mode):
## #!/bin/bash
##
## timedatectl set-ntp true [not sure if necessary]
## pacman -Syy
## pacman -S reflector
## reflector -c Iran -a 6 --sort rate --save /etc/pacman.d/mirrorlist
## pacman -Syy
##
## lsblk
## cfdisk /dev/sdx [choose dos]
##
## #expected outcome:
## sdx1 / bootable
## sdx2 /home
## sdx3 swap
##
## mkfs.ext4 /dev/sdx1
## mount /dev/sdx1 /mnt
##
## mkfs.ext4 /dev/sdx2
## mkdir /mnt/home
## mount /dev/sdx2 /mnt/home
##
## mkswap /dev/sdx3
## swapon /dev/sdx3
##
## pacstrap -i /mnt base base-devel
## {{{ To be installed manually (https://wiki.archlinux.org/index.php/Talk:Installation_guide#Changes_for_the_base_package):
## cryptsetup -- indirect dependency of base
## device-mapper -- indirect dependency of base
## dhcpcd
## diffutils
## e2fsprogs -- indirect dependency of base
## inetutils
## jfsutils
## less -- indirect dependency of base
## linux
## linux-firmware
## logrotate
## lvm2
## man-db
## man-pages
## mdadm
## nano
## netctl
## perl
## reiserfsprogs
## s-nail
## sysfsutils
## texinfo
## usbutils
## vi
## which
## xfsprogs
## }}}
## {{{ packages belonging to base-devel which are currently installed on machine (base base-devel was used during OS installation (installation date: 20190329172200))
## currentl date: 13990613204649, 20200903204655
## autoconf
## automake
## binutils
## bison
## fakeroot
## file
## findutils
## flex
## gawk
## gcc
## gettext
## grep
## groff
## gzip
## libtool
## m4
## make
## pacman
## patch
## pkgconf
## sed
## sudo
## texinfo
## which
## }}}
##
## genfstab -U /mnt >> /mnt/etc/fstab
##
## arch-chroot /mnt /bin/bash
##
## vim /etc/locale.gen
## #Uncomment these:
## en_US.UTF-8 UTF-8
## fa_IR UTF-8
## (save & exit)
##
## locale-gen
## echo LANG=en_US.UTF-8 > /etc/locale.conf
## export LANG=en_US.UTF-8
##
## ln -fs /usr/share/zoneinfo/Asia/Tehran /etc/localtime
## hwclock --systohc --utc
##
## echo acer > /etc/hostname
##
## vim /etc/hosts
## #write these lines in it:
## 127.0.0.1 localhost
## ::1 localhost
## 127.0.1.1 acer.localdomain acer
## (save & exit)
##
## vim /etc/pacman.conf
## #uncomment these lines:
## #[multilib]
## #Include = /etc/pacman.d/mirrorlist
## (save & exit)
##
## pacman -Sy
##
## passwd
##
## #------------------------------------
## # Add user
##
## >> method 1:
## useradd -mG wheel -s /bin/bash nnnn
## EDITOR=vim visudo
## #uncomment this line:
## # %wheel ALL=(ALL) NOPASSWD: ALL
##
## >> {{{ method 2:
## useradd -m -g users -G lp -s /bin/bash nnnn # also -G lp,autologin,storage,wheel,power
## EDITOR=vim visudo
## # add "nnnn ALL=(ALL) NOPASSWD: ALL" under the line "root = ALL=(ALL) ALL") (without the quotes)
## (save & exit)
## }}}
##
## >> {{{ method 3 (Luke version) (www.youtube.com/watch?v=nSHOb8YU9Gw):
## useradd -m -g wheel nnnn
## EDITOR=vim visudo
## # Add this line:
## %wheel ALL=(ALL) NOPASSWD: ALL
## # Alternatively, you can have these two lines where you specify the commands to be run without asking for a password:
## %wheel ALL=(ALL) ALL
## %wheel ALL=(ALL) NOPASSWD: <command1>, <command2>, <command3>
## }}}
## (save & exit)
## #------------------------------------
##
## passwd nnnn
##
## pacman -S bash bash-completion grub os-prober[only when dual-booting]
## grub-install --recheck --debug --force /dev/sdx
## grub-mkconfig -o /boot/grub/grub.cfg
##
## pacman -S networkmanager network-manager-applet
## sudo systemctl enable NetworkManager
##
## systemctl enable dhcpcd
## ip a
## systemctl enable dhcpcd@enp4s0f1
##
## exit
## reboot
##
## sudo pacman -S xorg xorg-xinit xorg-server xorg-apps
## sudo pacman -S lightdm
## sudo pacman -S lightdm-gtk-greeter lightdm-gtk-greeter-settings
## sudo systemctl enable lightdm.service
##
## reboot
## }}}