-
Notifications
You must be signed in to change notification settings - Fork 5
/
install
executable file
·611 lines (519 loc) · 16.1 KB
/
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
#!/bin/bash
# import {{{
if [[ -f "$(pwd)/common" ]]; then
source common
else
print_error 'missing file: common'
fi
if [[ -f "$(pwd)/utilities" ]]; then
source utilities
else
print_error 'missing file: utilities'
fi
# }}}
check_firmware() { # {{{
# https://bbs.archlinux.org/viewtopic.php?id=172867
modprobe -q efivarfs
if [[ -d "/sys/firmware/efi/" ]]; then
# Mount efivarfs if it is not already mounted
if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
print_info "UEFI Mode detected"
else
print_warning 'This script do not support BIOS Mode. Consider using https://github.com/helmuthdu/aui for more customization'
enter_to_continue
exit 1
fi
}
# }}}
install_requirements() { # {{{
print_progress 'Install script dependencies'
setup_console_font
# install figlet to draw big ascii title
install_package 'figlet'
# option filter
install_package 'fzf'
}
# }}}
pre_install() { # {{{
update_pacman_db
check_connection
check_firmware
install_requirements
}
# }}}
umount_partitions() { # {{{
print_progress 'Unmounting partitions..'
local mounted_partitions
mounted_partitions="$(lsblk | grep ${MOUNTPOINT} | awk '{print $7}' | sort -r)"
swapoff -a
for i in ${mounted_partitions[@]}; do
umount $i
done
}
# }}}
create_partitions() { # {{{
# select device {{{
print_title 'PARTITIONS'
print_partitions
echo
echo 'Some suggestions in case future me get lost:'
echo " - Swap partition: ${CYAN}[Primary]${RESET} ${GREEN}8Gb${RESET} (same as RAM)"
echo " - Root partition: ${CYAN}[Primary]${RESET} ${GREEN}100Gb${RESET}"
echo " - Home partition: ${CYAN}[Primary]${RESET} ${GREEN}90Gb${RESET} (virtualbox)"
echo
print_warning 'WARNING: If Arch and Windows are dual-booting from same disk, then Arch SHOULD follow the same firmware boot mode and partitioning combination used by the installed Windows in the disk.'
echo
echo 'Select device to partition:'
devices=($(lsblk -d | awk '{print "/dev/" $1}' | grep 'sd\|hd\|vd\|nvme\|mmcblk'))
select DEVICE in "${devices[@]}"; do
if contains_element "${DEVICE}" "${devices[@]}"; then
break
else
invalid_option
fi
done
# }}}
# modify partition {{{
cfdisk "$DEVICE"
# }}}
}
# }}}
format_partitions() { # {{{
print_partition_info() { # {{{
print_title 'PARTITIONS'
print_partitions
echo
print_info 'This step will select and format the selected partitions where archlinux will be installed'
print_danger 'All data on the ROOT and SWAP partition will be LOST.'
}
# }}}
# {{{ set partition to format
local partitions partition_names format_partition_names partition_number
partitions=($(lsblk -pl | grep 'part' | awk '{print $1}'))
partition_names=(root home swap boot)
format_partition_names=(root swap) # always format these partitions
for partition_name in ${partition_names[@]}; do
if [[ ${#partitions[@]} == 0 ]]; then
break
fi
print_partition_info
echo "Select ${GREEN}${partition_name}${RESET} partition:"
select partition in "${partitions[@]}"; do
if contains_element "${partition}" "${partitions[@]}"; then
case "$partition_name" in
root)
ROOT_PARTITION="$partition"
;;
home)
HOME_PARTITION="$partition"
;;
swap)
SWAP_PARTITION="$partition"
;;
boot)
BOOT_PARTITION="$partition"
;;
esac
# get the selected number - 1
partition_number=$(($REPLY - 1))
unset partitions[${partition_number}]
partitions=(${partitions[@]}) # remove unset variable
break
else
invalid_option
fi
done
if contains_element "${partition_name}" "${format_partition_names[@]}"; then
continue
fi
echo
confirm "Format partition $partition_name"
if [[ "$OPTION" == y ]]; then
case "$partition_name" in
home)
FORMAT_HOME_PARTITION=1
;;
boot)
FORMAT_BOOT_PARTITION=1
;;
esac
fi
done
# }}}
# apply changes {{{
print_partition_info
echo
echo "${BLUE}${ROOT_PARTITION}${RESET} ${RED}(ext4)${RESET} will be formatted and mounted to ${GREEN}${MOUNTPOINT}${RESET}"
if [[ "$FORMAT_HOME_PARTITION" == 1 ]]; then
echo "${BLUE}${HOME_PARTITION}${RESET} ${RED}(ext4)${RESET} will be formatted and mounted to ${GREEN}${MOUNTPOINT}/home${RESET}"
else
echo "${BLUE}${HOME_PARTITION}${RESET} ${RED}(ext4)${RESET} will be mounted to ${GREEN}${MOUNTPOINT}/home${RESET}"
fi
echo "${BLUE}${SWAP_PARTITION}${RESET} ${RED}(swap)${RESET} will be formatted"
if [[ "$FORMAT_BOOT_PARTITION" == 1 ]]; then
echo "${BLUE}${BOOT_PARTITION}${RESET} ${RED}(vfat)${RESET} will be formatted and mounted to ${GREEN}${MOUNTPOINT}/boot${RESET}"
else
echo "${BLUE}${BOOT_PARTITION}${RESET} ${RED}(vfat)${RESET} will be mounted to ${GREEN}${MOUNTPOINT}/boot${RESET}"
fi
echo
confirm 'Confirm formatting partitions'
if [[ "$OPTION" == y ]]; then
if [[ "$FORMAT_BOOT_PARTITION" == 1 ]]; then
yes | mkfs.vfat "$BOOT_PARTITION"
fsck "$BOOT_PARTITION"
fi
yes | mkfs.ext4 "$ROOT_PARTITION"
fsck "$ROOT_PARTITION"
if [[ "$FORMAT_HOME_PARTITION" == 1 ]]; then
yes | mkfs.ext4 "$HOME_PARTITION"
fsck "$HOME_PARTITION"
fi
yes | mkswap "$SWAP_PARTITION"
mount_partitions
else
return
fi
# }}}
}
# }}}
mount_partitions() { # {{{
print_progress 'Mounting partitions..'
mount "$ROOT_PARTITION" "$MOUNTPOINT"
mkdir -p "$MOUNTPOINT/home"
mount "$HOME_PARTITION" "$MOUNTPOINT/home"
mkdir -p "$MOUNTPOINT/boot"
mount "$BOOT_PARTITION" "$MOUNTPOINT/boot"
swapon "$SWAP_PARTITION"
}
# }}}
setup_partition() { # {{{
umount_partitions
create_partitions
format_partitions
enter_to_continue
}
# }}}
install_base() { # {{{
print_title 'INSTALL BASE SYSTEM'
print_info 'Using the pacstrap script we install the base system. The base-devel package group will be installed also.'
# remove old linux image in case you reinstall arch and have boot partition
# shared with window and you do not want to format it, so you have to delete
# the old linux image manually
# see https://bbs.archlinux.org/viewtopic.php?pid=1384654#p1384654
rm "$MOUNTPOINT/boot/vmlinuz-linux" 2> /dev/null
pacstrap "$MOUNTPOINT" base base-devel
pacstrap "$MOUNTPOINT" dialog wpa_supplicant # if you use wifi in the live system, you will also need this
print_progress 'setup network for the new system'
arch_chroot "systemctl enable dhcpcd@$(wired_device).service"
enter_to_continue
}
# }}}
generate_fstab() { # {{{
print_title 'FSTAB'
print_info 'The /etc/fstab file contains static filesystem information. It defines how storage devices and partitions are to be mounted and integrated into the overall system. It is read by the mount command to determine which options to use when mounting a specific partition or partition.'
echo
print_progress 'Generating fstab file...'
genfstab -U "$MOUNTPOINT" > "$MOUNTPOINT/etc/fstab"
echo
print_info "$MOUNTPOINT/etc/fstab"
cat ${MOUNTPOINT}/etc/fstab
enter_to_continue
}
# }}}
set_locale() { # {{{
local locales
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'LOCALE'
print_info 'Locales are used by glibc and other locale-aware programs or libraries for rendering text, correctly displaying regional monetary values, time and date formats, alphabetic idiosyncrasies, and other locale-specific standards.'
echo
locales="$(cat /etc/locale.gen | grep UTF-8 | sed 's/\..*$//' | sed '/@/d' | awk '{print $1}' | uniq | sed 's/#//g')"
LOCALE="$(fuzzy_search "$locales" 'Enter locale: ')"
if [[ "$LOCALE" != '' ]]; then
confirm_yes "Confirm locale ($LOCALE)"
else
invalid_option
fi
done
}
# }}}
select_locale() { # {{{
ask_default_option "$LOCALE" set_locale
update_option 'LOCALE'
local locale_utf8
locale_utf8="${LOCALE}.UTF-8"
echo "LANG=$locale_utf8" > "${MOUNTPOINT}/etc/locale.conf"
sed -i '/^[^#]/s/^\(.*\)$/#\1/' "${MOUNTPOINT}/etc/locale.gen" # comment previous option from last run
sed -i "s/#\(${locale_utf8}\)/\1/" "${MOUNTPOINT}/etc/locale.gen"
arch_chroot 'locale-gen'
enter_to_continue
}
# }}}
set_timezone() { # {{{
local zones subzones
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'TIMEZONE'
print_info 'Select your timezone'
zones="$(timedatectl list-timezones | sed 's/\/.*$//' | uniq)"
ZONE="$(fuzzy_search "$zones" 'Enter zone: ')"
if [[ "$ZONE" != '' ]]; then
subzones="$(timedatectl list-timezones | grep "$ZONE" | sed 's|^.*\/||')"
SUBZONE="$(fuzzy_search "$subzones" 'Enter subzone: ')"
if [[ "$SUBZONE" != '' ]]; then
confirm_yes "Confirm timezone ($ZONE/$SUBZONE)"
else
invalid_option
fi
else
invalid_option
fi
done
}
# }}}
select_timezone() { # {{{
ask_default_option "$ZONE/$SUBZONE" set_timezone
update_option 'ZONE'
update_option 'SUBZONE'
arch_chroot "ln -sf /usr/share/zoneinfo/${ZONE}/${SUBZONE} /etc/localtime"
enter_to_continue
}
# }}}
set_hardware_clock() { # {{{
local hardware_clock_opts
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'HARDWARE CLOCK'
print_info 'This is set in /etc/adjtime. Set the hardware clock mode uniformly between your operating systems on the same machine. Otherwise, they will overwrite the time and cause clock shifts (which can cause time drift correction to be miscalibrated).'
echo " ${GREEN}Recommended:${RESET} Set both Arch Linux and Windows to use UTC if you dual-boot with Window"
hardware_clock_opts=('UTC' 'Localtime')
select opt in "${hardware_clock_opts[@]}"; do
if contains_element "${opt}" "${hardware_clock_opts[@]}"; then
HARDWARE_CLOCK="$opt"
break
else
invalid_option
fi
done
confirm_yes "Confirm hardware clock ($HARDWARE_CLOCK)"
done
}
# }}}
configure_hardware_clock() { # {{{
ask_default_option "$HARDWARE_CLOCK" set_hardware_clock
update_option 'HARDWARE_CLOCK'
case "$HARDWARE_CLOCK" in
UTC)
arch_chroot 'hwclock --systohc --utc'
;;
Localtime)
arch_chroot 'hwclock --systohc --localtime'
;;
esac
enter_to_continue
}
# }}}
set_keymap() { # {{{
local keymaps
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'KEYMAP'
print_info 'Select your keyboard layout. Default is US'
keymaps="$(find /usr/share/kbd/keymaps -name '*.map.gz' | sed 's|^.*\/||' | sed 's/\.map\.gz$//')"
KEYMAP="$(fuzzy_search "$keymaps" 'Enter layout: ')"
if [[ "$KEYMAP" != '' ]]; then
confirm_yes "Confirm keyboard layout ($KEYMAP)"
else
invalid_option
fi
done
}
# }}}
select_keyboard_layout() { # {{{
ask_default_option "$KEYMAP" set_keymap
update_option 'KEYMAP'
# loadkeys "$KEYMAP"
echo "KEYMAP=$KEYMAP" > ${MOUNTPOINT}/etc/vconsole.conf
enter_to_continue
}
# }}}
create_hostname() { # {{{
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'HOSTNAME'
print_info 'A host name is a unique name created to identify a machine on a network. Host names are restricted to alphanumeric characters. The hyphen (-) can be used, but a host name cannot start or end with it. Length is restricted to 63 characters.'
echo
read_input 'Enter host name: '
if [[ "$OPTION" != '' ]]; then
HOSTNAME="$OPTION"
confirm_yes "Confirm host name ($HOSTNAME)"
else
invalid_option
fi
done
}
# }}}
configure_hostname() { # {{{
ask_default_option "$HOSTNAME" create_hostname
update_option 'HOSTNAME'
echo "$HOSTNAME" > "${MOUNTPOINT}/etc/hostname"
echo '# <ip-address> <hostname> <optional-alias>' > "${MOUNTPOINT}/etc/hosts"
echo ' 127.0.0.1 localhost' >> "${MOUNTPOINT}/etc/hosts"
echo ' ::1 localhost' >> "${MOUNTPOINT}/etc/hosts"
echo " 127.0.1.1 $HOSTNAME.localhost $HOSTNAME" >> "${MOUNTPOINT}/etc/hosts"
enter_to_continue
}
# }}}
create_root_password() { # {{{
print_title 'ROOT PASSWORD'
print_info 'Create password for root account'
echo
arch_chroot 'passwd'
enter_to_continue
}
# }}}
configure_mkinitcpio() { # {{{
print_title 'MKINITCPIO'
print_info 'mkinitcpio is a Bash script used to create an initial ramdisk environment.'
print_info 'Creating a new initramfs is usually not required, because mkinitcpio was run on installation of the linux package with pacstrap.'
print_info 'For special configurations, modify the /etc/mkinitcpio.conf file and recreate the initramfs image:'
echo -e "\t${GREEN}mkinitcpio -p linux${RESET}"
echo
print_progress 'Create the initramfs image...'
arch_chroot 'mkinitcpio -p linux'
enter_to_continue
}
# }}}
setup_bootloader_theme() { # {{{
print_progress 'Install theme for grub'
git clone 'https://github.com/NearHuscarl/grub2-themes' /tmp/grub2-themes
cp -rd /tmp/grub2-themes/grub-theme-vimix/Vimix "${MOUNTPOINT}/boot/grub/themes"
rm -rd /tmp/grub2-themes
}
# }}}
setup_bootloader() { # {{{
local boot_id='arch_grub'
print_title 'BOOTLOADER'
print_info 'A Linux-capable boot loader must be installed in order to boot Arch Linux.'
echo
print_progress 'Download necessary files for installation...'
# Note: for bios: pacman -Syu grub-bios os-prober
pacstrap ${MOUNTPOINT} grub efibootmgr os-prober
print_progress 'Install grub'
# arch_chroot "grub-install $DEVICE"
arch_chroot "grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=$boot_id --recheck"
setup_bootloader_theme
if [[ ! -f "${MOUNTPOINT}/etc/default/grub.aui" ]]; then
cp -v "${MOUNTPOINT}/etc/default/grub" "${MOUNTPOINT}/etc/default/grub.aui"
# fix the spamming pcie bus error https://askubuntu.com/questions/771899/pcie-bus-error-severity-corrected
sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/s/="\(.*\)"/="\1 pci=nomsi"/' "${MOUNTPOINT}/etc/default/grub"
sed -i '/GRUB_THEME=/s/^.*/GRUB_THEME="\/boot\/grub\/themes\/Vimix\/theme.txt"/' "${MOUNTPOINT}/etc/default/grub"
fi
print_progress 'Generate the main configuration file'
print_warning 'Remember that grub.cfg has to be re-generated after any change to /etc/default/grub or files in /etc/grub.d/'
arch_chroot 'grub-mkconfig -o /boot/grub/grub.cfg'
# fix a bug when install arch in EFI mode with virtualbox
# https://wiki.archlinux.org/index.php/VirtualBox#Installation_in_EFI_mode
# https://www.youtube.com/watch?v=q87bWzKym5g
if is_in_virtualbox; then
mkdir "${MOUNTPOINT}/boot/EFI/boot"
cp "${MOUNTPOINT}/boot/EFI/$boot_id/grubx64.efi" "${MOUNTPOINT}/boot/EFI/boot/bootx64.efi"
fi
enter_to_continue
}
# }}}
finish() { # {{{
print_title "INSTALL COMPLETED"
print_warning "\nA copy of the AUI will be placed in /root directory of your new system"
cp -r "$(pwd)" "$MOUNTPOINT/root"
confirm_yes 'Reboot system'
if [[ "$OPTION" != n ]]; then
umount_partitions
reboot
fi
exit 0
}
# }}}
install() { # {{{
local checklist
checklist=(0 0 0 0 0 0 0 0 0 0 0 0 0)
while true; do
print_title 'ARCHLINUX INSTALLER'
echo " 1. $(mainmenu_item "${checklist[0]}" 'Partition the disks')"
echo " 2. $(mainmenu_item "${checklist[1]}" 'Install base')"
echo " 3. $(mainmenu_item "${checklist[2]}" 'Generate fstab')"
echo " 4. $(mainmenu_item "${checklist[3]}" 'Select locale' "$LOCALE")"
echo " 5. $(mainmenu_item "${checklist[4]}" 'Select timezone' "$ZONE/$SUBZONE")"
echo " 6. $(mainmenu_item "${checklist[5]}" 'Configure hardware clock' "$HARDWARE_CLOCK")"
echo " 7. $(mainmenu_item "${checklist[6]}" 'Select keyboard layout' "$KEYMAP")"
echo " 8. $(mainmenu_item "${checklist[7]}" 'Configure hostname' "$HOSTNAME")"
echo " 9. $(mainmenu_item "${checklist[8]}" 'Configure root password')"
echo " 10. $(mainmenu_item "${checklist[9]}" 'Configure mkinitcpio')"
echo " 11. $(mainmenu_item "${checklist[10]}" 'Setup bootloader')"
echo " 12. $(mainmenu_item "${checklist[11]}" 'Finish')"
echo
read -p "Enter option (1-13): " OPTION
case "$OPTION" in
1)
setup_partition
checklist[0]=1
;;
2)
install_base
checklist[1]=1
;;
3)
generate_fstab
checklist[2]=1
;;
4)
select_locale
checklist[3]=1
;;
5)
select_timezone
checklist[4]=1
;;
6)
configure_hardware_clock
checklist[5]=1
;;
7)
select_keyboard_layout
checklist[6]=1
;;
8)
configure_hostname
checklist[7]=1
;;
9)
create_root_password
checklist[8]=1
;;
10)
configure_mkinitcpio
checklist[9]=1
;;
11)
setup_bootloader
checklist[10]=1
;;
12)
finish
checklist[11]=1
;;
*)
invalid_option
;;
esac
done
}
# }}}
main() { # {{{
pre_install
install
}
# }}}
main