-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-installer.sh
executable file
·484 lines (440 loc) · 12.1 KB
/
arch-installer.sh
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
#!/usr/bin/env bash
red=$(tput setaf 1)
green=$(tput setaf 2)
blue=$(tput setaf 6)
normal=$(tput sgr0)
input_drive() {
local drive
lsblk >&2
read -p "Enter drive (Ex. - /dev/sda): " drive
cfdisk $drive >&2
echo "$drive"
}
input_linux_part() {
local linux
lsblk >&2
read -p "Enter the Linux Partition (Ex. - /dev/sda2): " linux
echo "$linux"
}
input_efi_part() {
local efi
read -p "Enter EFI partition (Ex. - /dev/sda2): " efi
echo "$efi"
}
input_host() {
local hostname
while true :; do
read -p "Enter the hostname: " hostname
if [[ "${hostname}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]]; then
break
fi
echo -e "${red}Incorrect Hostname!${normal}" >&2
done
echo "$hostname"
}
input_user() {
local username
while true :; do
read -p "Enter username: " username
if [[ "${username}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]]; then
break
fi
echo -e "${red}Incorrect Username!${normal}" >&2
done
echo "$username"
}
input_pass() {
local pass1 pass2
while true :; do
read -sp "Enter password: " pass1
echo "" >&2
read -sp "Re-enter password: " pass2
if [[ "${pass1}" = "${pass2}" ]]; then
break
fi
echo -e "\n${red}Passwords don't match.${normal}" >&2
done
echo "$pass1"
}
input_nvidia() {
local nvidia
echo -e "\nAmd and Intel Drivers will automatically work with the mesa package. The option below is only for Nvidia Graphics Card users." >&2
read -p "Enter which graphics driver you use [Enter \"1\" for Nvidia or \"2\" for Legacy Nvidia Drivers (Driver 390)]: " nvidia
echo "$nvidia"
}
create_subvol() {
local drive="$1"
echo -e "${cyan}CREATING SUBVOLUMES${normal}"
mkfs.btrfs -fL Linux "$drive"
mount "$drive" /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@swap
btrfs subvolume create /mnt/@var
btrfs subvolume create /mnt/@tmp
umount /mnt
}
mount_subvol() {
local drive="$1"
echo -e "${cyan}MOUNTING SUBVOLUMES${normal}"
mount -o noatime,discard=async,compress=zstd:2,subvol=@ "$drive" /mnt
mkdir /mnt/{home,swap,var,tmp}
mount -o noatime,compress=zstd:2,subvol=@home "$drive" /mnt/home
mount -o nodatacow,subvol=@swap "$drive" /mnt/swap
mount -o nodatacow,subvol=@var "$drive" /mnt/var
mount -o noatime,compress=zstd:2,subvol=@tmp "$drive" /mnt/tmp
}
create_swap() {
echo -e "${cyan}CREATING SWAP${normal}"
btrfs filesystem mkswapfile --size 2G /mnt/swap/swapfile
swapon /mnt/swap/swapfile
}
create_efi() {
local efi="$1"
echo -e "${cyan}CREATING UEFI PARTITION${normal}"
mkfs.fat -F 32 "$efi"
mkdir /mnt/boot
mount "$efi" /mnt/boot
}
install_base_pkg() {
echo -e "${cyan}INSTALLING BASIC PACKAGES${normal}"
local packages=(
base
base-devel
linux-zen
linux-zen-headers
linux-firmware
btrfs-progs
intel-ucode
grub
networkmanager
git
libvirt
reflector
rsync
xdg-user-dirs
xdg-utils
zsh
bluez
bluez-utils
blueman
xorg-server
xorg-xinit
libxft
libxinerama
ufw
)
pacstrap /mnt "${packages[@]}"
genfstab -U /mnt >>/mnt/etc/fstab
}
conf_pacman() {
echo -e "${green}PACMAN CONFIG${normal}"
sed -i "s/^#ParallelDownloads = 5$/ParallelDownloads = 10/" /mnt/etc/pacman.conf
grep -q "ILoveCandy" /mnt/etc/pacman.conf || sed -i "/#VerbosePkgLists/a ILoveCandy" /mnt/etc/pacman.conf
sed -i "/^#ParallelDownloads/s/=.*/= 5/;s/^#Color$/Color/" /mnt/etc/pacman.conf
sed -i "/\[multilib\]/,/Include/"'s/^#//' /mnt/etc/pacman.conf
}
conf_locale_hosts() {
local hostname="$1"
arch-chroot /mnt ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
arch-chroot /mnt hwclock --systohc
echo "en_US.UTF-8 UTF-8" >>/mnt/etc/locale.gen
arch-chroot /mnt locale-gen
echo "LANG=en_US.UTF-8" >>/mnt/etc/locale.conf
echo "$hostname" >/mnt/etc/hostname
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
}
install_grub() {
local efi="$1"
local drive="$2"
echo -e "${green}GRUB${normal}"
case "$efi" in
/dev/*)
arch-chroot /mnt pacman -Sy --noconfirm efibootmgr
arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
;;
*)
arch-chroot /mnt grub-install --target=i386-pc $drive
;;
esac
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
}
create_user() {
local username="$1"
echo -e "${green}USER CREATION${normal}"
arch-chroot /mnt systemctl enable NetworkManager libvirtd paccache.timer bluetooth ufw.service
arch-chroot /mnt useradd -mG wheel -s /bin/zsh $username
arch-chroot /mnt usermod -aG libvirt $username
}
pass_user() {
local username="$1"
local pass="$2"
arch-chroot /mnt bash -c "echo $username:$pass | chpasswd"
}
setup_ufw() {
arch-chroot /mnt <<EOF
ufw enable
ufw logging off
ufw default deny
ufw allow from 192.168.0.0/24
ufw allow 443
ufw allow 80
ufw limit 22
ufw limit ssh
EOF
}
setup_dotfiles() {
local username="$1"
echo -e "${blue}DOTFILES${normal}"
arch-chroot /mnt sudo -i -u $username bash <<EOF
cd
git clone --depth=1 --separate-git-dir=.dots https://github.com/ghoulboii/dotfiles tmpdotfiles
git --git-dir=.dots --work-tree=~ remote set-url origin [email protected]:ghoulboii/dotfiles
git --git-dir=.dots --work-tree=~ config --local status.showUntrackedFiles no
rsync --recursive --verbose --exclude '.git' tmpdotfiles/ .
rm -rf tmpdotfiles
mkdir ~/{dl,doc,pics}
xdg-user-dirs-update
echo 'ZDOTDIR="${XDG_CONFIG_HOME:-$HOME/.config}/zsh"' > /etc/zsh/zshenv #TODO Check if this works
EOF
}
setup_paru() {
local username="$1"
arch-chroot /mnt sudo -i -u "$username" bash <<EOF
echo -e "${blue}PARU${normal}"
git clone --depth=1 https://aur.archlinux.org/paru-bin.git ~/.local/src/paru
cd ~/.local/src/paru
makepkg --noconfirm -rsi
rm -rf ~/.local/src/paru
EOF
}
setup_dwm() {
local username="$1"
arch-chroot /mnt sudo -i -u "$username" bash <<EOF
echo -e "${blue}DWM${normal}"
git clone --depth=1 https://github.com/ghoulboii/dwm ~/.local/src/dwm
git --git-dir=~/.local/src/dwm/.git --work-tree=~/.local/dwm/st remote set-url origin [email protected]:$(whoami)/dwm
sudo make -sC ~/.local/src/dwm install
EOF
}
setup_dwmblocks() {
local username="$1"
arch-chroot /mnt sudo -i -u "$username" bash <<EOF
echo -e "${blue}DWMBLOCKS${normal}"
git clone --depth=1 https://github.com/ghoulboii/dwmblocks ~/.local/src/dwmblocks
git --git-dir=~/.local/src/dwmblocks/.git --work-tree=~/.local/src/dwmblocks remote set-url origin [email protected]:$(whoami)/dwmblocks
sudo make -sC ~/.local/src/dwmblocks install
EOF
}
setup_st() {
local username="$1"
arch-chroot /mnt sudo -i -u "$username" bash <<EOF
echo -e "${blue}ST${normal}"
git clone --depth=1 https://github.com/ghoulboii/st ~/.local/src/st
git --git-dir=~/.local/src/st/.git --work-tree=~/.local/src/st remote set-url origin [email protected]:$(whoami)/st
sudo make -sC ~/.local/src/st install
EOF
}
setup_dmenu() {
local username="$1"
arch-chroot /mnt sudo -i -u "$username" bash <<EOF
echo -e "${blue}DMENU${normal}"
git clone --depth=1 https://github.com/ghoulboii/dmenu ~/.local/src/dmenu
git --git-dir=~/.local/src/dmenu/.git --work-tree=~/.local/src/dmenu remote set-url origin [email protected]:$(whoami)/dmenu
sudo make -sC ~/.local/src/dmenu install
EOF
}
setup_neovim() {
local username="$1"
arch-chroot /mnt sudo -i -u "$username" bash <<EOF
echo -e "${blue}NEOVIM${normal}"
git clone --depth=1 https://github.com/ghoulboii/nvim ~/.config/nvim
git --git-dir=~/.config/nvim/.git --work-tree=~/.config/nvim remote set-url origin [email protected]:$(whoami)/nvim
EOF
}
install_packages() {
local username="$1"
echo -e "\${blue}PACKAGES\${normal}"
# FIX: Add a new gtk theme, need more testing
# package_array=($(echo "$packages"))
#
# paru -S "${package_array[@]}"
local packages=(
acpi
bat
btop
easyeffects
# eza
fastfetch
# fd
feh
firefox
fzf
gamemode
gparted
lf
libqalculate
libreoffice-fresh
man-db
mesa
mpv
mpv-mpris
ncdu
neovim
newsboat
noto-fonts
noto-fonts-emoji
obs-studio
openssh
os-prober # TODO: make dual boot function
pavucontrol
pacman-contrib
pcmanfm-gtk3 # TODO: checkout other file managers
pipewire
pipewire-pulse
playerctl
prismlauncher
python-pywal
qbittorrent
qt5-styleplugins
qt6gtk2
reflector
ripgrep
rose-pine-gtk-theme
socat
sxhkd
tgpt
tldr
tmux
trash-cli
ttf-firacode-nerd
ttf-ms-fonts
unclutter
udiskie
ueberzugpp
webkit2gtk
wget
wine-staging
winetricks
wireplumber
xclip
xdg-desktop-portal-gtk
xdotool
xf86-input-libinput
xorg-xev
xorg-xinput
xorg-xrandr
xorg-xset
xsel
yt-dlp
zoxide
zsh-autosuggestions
zsh-completions
zsh-fast-syntax-highlighting
zsh-history-substring-search
zstd
)
arch-chroot /mnt sudo -i -u "$username" paru -Sy --noconfirm --needed "${packages[@]}"
}
install_nvidia() {
local nvidia="$1"
local username="$2"
case "$nvidia" in
1)
echo -e "${blue}NVIDIA DRIVERS${normal}"
arch-chroot /mnt sudo -i -u "$username" paru -S --noconfirm nvidia-dkms nvidia-utils lib32-nvidia-utils
;;
2)
echo -e "${blue}NVIDIA DRIVERS${normal}"
arch-chroot /mnt sudo -i -u "$username" paru -S --noconfirm nvidia-390xx-dkms nvidia-390xx-utils lib32-nvidia-390xx-utils
;;
esac
}
post_install_cleanup() {
local username="$1"
sed -i '$d' /mnt/etc/sudoers
rm -rf /mnt/home/"$username"/.bash*
}
main() {
clear
cat <<"EOF"
_nnnn_
dGGGGMMb ,""""""""""""""""".
@p~qp~~qMb | i use arch btw! |
M|@||@) M| _;.................'
@,----.JM| -'
JS^\__/ qKL
dZP qKRb
dZP qKKb
fZP SMMb
HZM MMMM
FqM MMMM
__| ". |\dS"qML
| `. | `' \Zq
_) \.___.,| .'
\____ )MMMMMM| .'
`-' `--'
EOF
echo -e "${blue}Ksh's Arch Installer${normal}"
echo -e "${blue}Script will take 15-30 min to run so sit back and enjoy a cup of coffee :)${normal}"
echo -e "${blue}Part 1: Partition Setup${normal}"
local drive=$(input_drive)
local linux=$(input_linux_part)
if [[ -d "/sys/firmware/efi" ]]; then
local efi=$(input_efi_part)
fi
local hostname=$(input_host)
local username=$(input_user)
local pass=$(input_pass)
local nvidia=$(input_nvidia)
sed -i "s/^#ParallelDownloads = 5$/ParallelDownloads = 10/" /etc/pacman.conf
pacman --noconfirm -Sy archlinux-keyring
reflector -c $(curl https://ifconfig.co/country-iso) --sort rate -a 24 -f 5 -p https --save /etc/pacman.d/mirrorlist
timedatectl set-ntp true
umount -A --recursive /mnt
create_subvol "$linux"
mount_subvol "$linux"
create_swap
case $efi in
/dev/*)
create_efi "$efi"
esac
echo -ne "${green}Successful! Moving to Part 2${normal}"
for i in {1..5}; do
echo -n .
sleep 1
done
echo -e "${blue}Part 2: Base System${normal}"
install_base_pkg
conf_pacman
conf_locale_hosts "$hostname"
install_grub "$efi" "$drive"
create_user "$username"
pass_user "root" "$pass"
pass_user "$username" "$pass"
setup_ufw
echo -ne "${green}Successful! Moving to Part 3${normal}"
for i in {1..5}; do
echo -n .
sleep 1
done
echo -e "${blue}Part 3: Graphical Interface${normal}"
echo -e "$username ALL=(ALL) NOPASSWD: ALL\n%wheel ALL=(ALL) NOPASSWD: ALL\n" >>/mnt/etc/sudoers
nc=$(grep -c ^processor /proc/cpuinfo)
sed -i "s/#MAKEFLAGS=\"-j2\"/MAKEFLAGS=\"-j$nc\"/g" /mnt/etc/makepkg.conf
sed -i "s/COMPRESSXZ=(xz -c -z -)/COMPRESSXZ=(xz -c -T $nc -z -)/g" /mnt/etc/makepkg.conf
setup_dotfiles "$username"
setup_paru "$username"
setup_dwm "$username"
setup_dwmblocks "$username"
setup_st "$username"
setup_dmenu "$username"
setup_neovim "$username"
install_packages "$username"
install_nvidia "$nvidia" "$username"
post_install_cleanup "$username"
echo -e "${green}Script finished without errors! Reboot now and enjoy ^_^${normal}"
}
main "$@"