-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·118 lines (93 loc) · 3.38 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
#!/bin/bash
# WARNING: this script will destroy data on the selected disk.
set -euEo pipefail
trap 'echo "${BASH_SOURCE:-unknown}:${LINENO:-unknown}: $BASH_COMMAND";' ERR
# Set up logging
exec 1> >(tee "stdout.log")
exec 2> >(tee "stderr.log")
REPO_URL="https://github.com/lemuelroberto/archlinux/releases/latest/download"
readonly MIRRORLIST_URL="https://archlinux.org/mirrorlist/?country=BR&protocol=http&protocol=https&use_mirror_status=on"
pacman -Sy --noconfirm pacman-contrib dialog
echo "Updating mirror list"
curl -s "$MIRRORLIST_URL" \
| sed -e 's/^#Server/Server/' -e '/^#/d' \
| rankmirrors -n 5 - > /etc/pacman.d/mirrorlist
# Get infomation from user
readonly hostname=$(dialog --stdout --inputbox "Enter hostname" 0 0) || exit 1
clear
: "${hostname:?'hostname cannot be empty'}"
readonly user=$(dialog --stdout --inputbox "Enter admin username" 0 0) || exit 1
clear
: "${user:?'user cannot be empty'}"
password=$(dialog --stdout --passwordbox "Enter admin password" 0 0) || exit 1
clear
: "${password:?'password cannot be empty'}"
password_confirmation=$(dialog --stdout --passwordbox "Enter admin password again" 0 0) || exit 1
clear
[[ "$password" == "$password_confirmation" ]] || (
echo "Passwords did not match"
exit 1
)
readonly devicelist=$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | tac)
# shellcheck disable=SC2086
readonly device=$(dialog --stdout --menu "Select installation disk" 0 0 0 ${devicelist}) || exit 1
clear
timedatectl set-ntp true
# Setup the disk and partitions
readonly efi_size=1024
readonly efi_end=$((efi_size + 1))
readonly swap_size=2048
readonly swap_end=$((swap_size + efi_size + 1))
parted --script "${device}" -- mklabel gpt \
mkpart ESP fat32 1Mib ${efi_end}MiB \
set 1 boot on \
mkpart primary linux-swap ${efi_end}MiB ${swap_end}MiB \
mkpart primary ext4 ${swap_end}MiB 100%
# Simple globbing was not enough as on one device I needed to match /dev/mmcblk0p1
# but not /dev/mmcblk0boot1 while being able to match /dev/sda1 on other devices.
# shellcheck disable=SC2010
readonly part_boot="$(ls "${device}"* | grep -E "^${device}p?1$")"
# shellcheck disable=SC2010
readonly part_swap="$(ls "${device}"* | grep -E "^${device}p?2$")"
# shellcheck disable=SC2010
readonly part_root="$(ls "${device}"* | grep -E "^${device}p?3$")"
wipefs "${part_boot}"
wipefs "${part_swap}"
wipefs "${part_root}"
mkfs.vfat -F32 "${part_boot}"
mkswap "${part_swap}"
mkfs.f2fs -f "${part_root}"
swapon "${part_swap}"
mount "${part_root}" /mnt
mkdir /mnt/boot
mount "${part_boot}" /mnt/boot
# Install and configure the basic system
cat >> /etc/pacman.conf << EOF
[lemuel]
SigLevel = Optional TrustAll
Server = $REPO_URL
EOF
pacstrap /mnt lemuel-base
genfstab -t PARTUUID /mnt >> /mnt/etc/fstab
echo "${hostname}" > /mnt/etc/hostname
cat >> /mnt/etc/pacman.conf << EOF
[lemuel]
SigLevel = Optional TrustAll
Server = $REPO_URL
EOF
arch-chroot /mnt bootctl install
cat << EOF > /mnt/boot/loader/loader.conf
default arch
EOF
cat << EOF > /mnt/boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options root=PARTUUID=$(blkid -s PARTUUID -o value "$part_root") rw
EOF
arch-chroot /mnt useradd -mU -s /bin/bash -G wheel,docker "$user"
arch-chroot /mnt chsh -s /bin/bash root
arch-chroot /mnt chsh -s /bin/bash "$user"
echo "$user:$password" | chpasswd --root /mnt
echo "root:$password" | chpasswd --root /mnt