-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchlinux-base
executable file
·218 lines (194 loc) · 4.92 KB
/
archlinux-base
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
#!/bin/bash
# From installer, run:
# pacman-key --init
# pacman -Sy git
# git clone https://github.com/user/repoWithThisScript
username=sysadmin
userpw=password123
hostname=archlinux
zone=America
subzone=Detroit
set -e
arch_chroot() {
arch-chroot /mnt /bin/bash -c "${1}"
}
update_system_clock() {
timedatectl set-ntp true
}
check_boot_mode() {
modprobe -q efivarfs
if [[ -d "/sys/firmware/efi/" ]]; then
if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
uefi=1
echo "UEFI Mode detected"
else
uefi=0
echo "BIOS Mode detected"
fi
echo ""
sleep 1
}
create_partitions() {
echo "==> Creating partitions..."
if [[ $uefi -eq 1 ]]; then
parted -s -a optimal /dev/sda 'mklabel gpt mkpart ESP fat32 1MiB 513MiB set 1 boot on mkpart primary ext4 513MiB 100%'
else
parted -s -a optimal /dev/sda 'mklabel msdos mkpart primary ext4 1MiB 500MiB set 1 boot on mkpart primary ext4 500MiB 100%'
fi
echo ""
sleep 1
}
format_partitions() {
echo "==> Formatting partitions..."
if [[ $uefi -eq 1 ]]; then
mkfs.fat -F32 /dev/sda1
mkfs.ext4 /dev/sda2
else
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda2
fi
sleep 1
}
mount_partitions() {
echo "==> Mounting partitions..."
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
echo ""
sleep 1
}
configure_mirrorlist() {
echo "==> Configuring mirrorlist..."
local url="https://archlinux.org/mirrorlist/?country=US&protocol=http&protocol=https&ip_version=4"
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
curl -so /etc/pacman.d/mirrorlist "${url}"
sed -i '0,/#Server/s//Server/' /etc/pacman.d/mirrorlist
pacman -Syy --noconfirm
echo ""
sleep 1
}
install_base_system() {
echo "==> Installing base system..."
pacstrap -K /mnt base base-devel linux linux-firmware dhcpcd openssh sudo vi /
atool /
docker /
docker-compose /
lsof /
man-db /
neovim /
net-tools /
speedtest-cli /
tmux /
traceroute /
vifm /
vim /
zsh
wireless_device=$(ip link | grep wl | awk '{print $2}'| sed 's/://' | sed '1!d')
if [[ -n $wireless_device ]]; then
pacstrap /mnt iw wireless_tools wpa_supplicant dialog
else
wired_device=$(ip link | grep "ens\|eno\|enp" | awk '{print $2}'| sed 's/://' | sed '1!d')
if [[ -n $wired_device ]]; then
arch_chroot "systemctl enable dhcpcd@${wired_device}.service"
fi
fi
arch_chroot "systemctl enable sshd.service"
arch_chroot "systemctl enable docker.service"
echo ""
sleep 1
}
configure_fstab() {
echo "==> Configuring /mnt/etc/fstab..."
genfstab -U /mnt >> /mnt/etc/fstab
sleep 1
}
configure_vconsole() {
echo "==> Configuring /mnt/etc/vconsole.conf..."
echo "FONT=Lat2-Terminus16" > /mnt/etc/vconsole.conf
sleep 1
}
configure_hostname() {
echo "==> Configuring /mnt/etc/hostname..."
echo "${hostname}" > /mnt/etc/hostname
sleep 1
}
configure_hosts() {
echo "==> Configuring /mnt/etc/hosts..."
echo "" >> /mnt/etc/hosts
echo "127.0.0.1 localhost" >> /mnt/etc/hosts
echo "::1 localhost" >> /mnt/etc/hosts
echo "127.0.1.1 ${hostname}.localdomain ${hostname}" >> /mnt/etc/hosts
sleep 1
}
configure_timezone() {
echo "==> Configuring timezone..."
arch_chroot "ln -sf /usr/share/zoneinfo/${zone}/${subzone} /etc/localtime"
sleep 1
}
configure_hardwareclock() {
echo "==> Configuring hardware clock..."
arch_chroot "hwclock --systohc --utc"
echo ""
sleep 1
}
configure_locale() {
echo 'LANG="en_US.UTF-8"' > /mnt/etc/locale.conf
echo "LC_COLLATE=C" >> /mnt/etc/locale.conf
echo "en_US.UTF-8 UTF-8" >> /mnt/etc/locale.gen
arch_chroot "locale-gen"
echo ""
sleep 1
}
configure_pacman() {
echo "==> Configuring '/etc/pacman.conf'..."
arch_chroot "sed -i '/Color/s/^#//' /etc/pacman.conf"
sleep 1
}
install_bootloader() {
echo "==> Installing bootloader..."
if [[ $uefi -eq 1 ]]; then
pacstrap /mnt grub efibootmgr
arch_chroot "grub-install --target=x86_64-efi --efi-directory=esp --bootloader-id=GRUB"
else
pacstrap /mnt grub
arch_chroot "grub-install --target=i386-pc /dev/sda"
fi
arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg"
echo ""
sleep 1
}
create_user() {
echo "==> Creating user ${username}..."
arch_chroot "useradd -m -G docker ${username}"
arch_chroot "echo '${username}:${userpw}' | chpasswd"
sleep 1
}
configure_sudo() {
echo "==> Configuring sudo for ${username}..."
echo "${username} ALL=(ALL) NOPASSWD: ALL" > /mnt/etc/sudoers.d/"${username}"
echo ""
}
main() {
update_system_clock
check_boot_mode
create_partitions
format_partitions
mount_partitions
configure_mirrorlist
install_base_system
configure_fstab
configure_vconsole
configure_hostname
configure_hosts
configure_timezone
configure_hardwareclock
configure_locale
configure_pacman
install_bootloader
create_user
configure_sudo
echo "Installation complete!"
}
main "$@"