-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch_install.sh
274 lines (233 loc) · 9.37 KB
/
arch_install.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
#!/usr/bin/env -S bash -e
# iwctl --passphrase PASSPHRASE station DEVICE connect SSID
#Cleaning
clear
read -r -p "Please insert the keymap you use: " keymap
loadkeys $keymap
# Selecting display drivers.
display_drivers_selector () {
echo "List of display drivers:"
echo "1) intel"
echo "2) nvidia"
echo "3) nouveau"
read -r -p "Insert the number of the corresponding display drivers: " choice
case $choice in
1 ) DISPLAY_DRIVER="intel"
MKINITCPICO_KMS_MODULES="i915"
arch-chroot /mnt pacman -Syu --noconfirm --needed mesa
arch-chroot /mnt pacman -Syu --noconfirm --needed lib32-mesa
arch-chroot /mnt pacman -Syu --noconfirm --needed intel-media-driver
echo "options i915 enable_fbc=1 fastboot=1" > /mnt/etc/modprobe.d/i915.conf
;;
2 ) DISPLAY_DRIVER="nvidia"
arch-chroot /mnt pacman -Syu --noconfirm --needed mesa
arch-chroot /mnt pacman -Syu --noconfirm --needed nvidia-dkms
arch-chroot /mnt pacman -Syu --noconfirm --needed nvidia-utils
MKINITCPICO_KMS_MODULES="nvidia nvidia_modeset nvidia_uvm nvidia_drm"
;;
* ) echo "You did not enter a valid selection."
display_drivers_selector
esac
}
# ------------------ STARTING ----------------------------------------------------------------
exec > >(tee -a build.log)
exec 2> >(tee -a build.log >&2)
set -o xtrace
#Configure time
timedatectl set-timezone Europe/London
timedatectl set-ntp true
# Selecting the target for the installation.
PS3="Select the disk where Arch Linux is going to be installed: "
select ENTRY in $(lsblk -dpnoNAME|grep -P "/dev/sd|nvme|vd");
do
DISK=$ENTRY
echo "Installing Arch Linux on $DISK."
break
done
# Deleting old partition scheme.
read -r -p "This will delete the current partition table on $DISK. Do you agree [y/N]? " response
response=${response,,}
if [[ "$response" =~ ^(yes|y)$ ]]
then
wipefs -af "$DISK" &>/dev/null
sgdisk -Zo "$DISK" &>/dev/null
else
echo "Quitting."
exit
fi
# Creating a new partition scheme.
echo "Creating new partition scheme on $DISK."
parted -s "$DISK" \
mklabel gpt \
mkpart "ESP" fat32 1MiB 513MiB \
mkpart "swap" linux-swap 513MiB 7513MiB \
mkpart "root" ext4 7513MiB 100% \
set 1 esp on
ESP="/dev/disk/by-partlabel/ESP"
swap="/dev/disk/by-partlabel/swap"
root="/dev/disk/by-partlabel/root"
# Informing the Kernel of the changes.
echo "Informing the Kernel about the disk changes."
partprobe "$DISK"
# Formatting the EFI as FAT32.
echo "Formatting the EFI Partition as FAT32."
mkfs.fat -n ESP -F32 $ESP
# Formatting the swap as FAT32.
echo "Formatting the swap Partition."
mkswap $swap
# Formatting the ESP as FAT32.
echo "Formatting the root Partition as ext4."
mkfs.ext4 $root
# Mounting.
mount $root /mnt
mkdir -p /mnt/boot/efi
mount $ESP /mnt/boot/efi
swapon $swap
UUID_BOOT=$(blkid -s PARTUUID -o value $ESP)
UUID_ROOT=$(blkid -s PARTUUID -o value $root)
UUID_SWAP=$(blkid -s PARTUUID -o value $swap)
# Installation.
echo "Server = https://mirrors.kernel.org/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
sed -i 's/#Color/Color/' /etc/pacman.conf
sed -i 's/#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
pacstrap /mnt base linux-zen linux-zen-headers base-devel linux-firmware
sed -i 's/#Color/Color/' /mnt/etc/pacman.conf
sed -i 's/#ParallelDownloads/ParallelDownloads/' /mnt/etc/pacman.conf
echo "" >> /mnt/etc/pacman.conf
echo "[multilib]" >> /mnt/etc/pacman.conf
echo "Include = /etc/pacman.d/mirrorlist" >> /mnt/etc/pacman.conf
echo "" >> /mnt/etc/pacman.conf
# Setting Timezone and localisation.
read -r -p "Please insert the region and city you use (format: Region/City): " region_city
arch-chroot /mnt ln -s -f /usr/share/zoneinfo/$region_city /etc/localtime
arch-chroot /mnt hwclock --systohc
read -r -p "Please insert the locale you use (format: xx_XX): " locale
echo "$locale.UTF-8 UTF-8" > /etc/locale.gen
echo "$locale.UTF-8 UTF-8" > /mnt/etc/locale.gen
echo "LANG=$locale.UTF-8" > /mnt/etc/locale.conf
locale-gen
arch-chroot /mnt locale-gen
echo "KEYMAP=$keymap" > /mnt/etc/vconsole.conf
arch-chroot /mnt mkdir -p "/etc/X11/xorg.conf.d/"
cat <<EOT > /mnt/etc/X11/xorg.conf.d/00-keyboard.conf
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
$OPTIONS
EndSection
EOT
arch-chroot /mnt localectl set-keymap --no-convert $keymap
arch-chroot /mnt timedatectl set-ntp true
# Setting swappiness.
echo "vm.swappiness=10" > /mnt/etc/sysctl.d/99-sysctl.conf
# Setting hostname and password.
read -r -p "Please enter your desired hostname: " hostname
echo "$hostname" > /mnt/etc/hostname
read -r -p "Please enter your desired root password: " password
printf "$password\n$password" | arch-chroot /mnt passwd
# Generating /etc/fstab.
echo "Generating a new fstab."
genfstab -U /mnt >> /mnt/etc/fstab
# Setting hosts file.
echo "Setting hosts file."
cat > /mnt/etc/hosts <<EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 $hostname.localdomain $hostname
EOF
# Installing display drivers.
echo "Installing display drivers."
display_drivers_selector
# Creating personal user and groups.
echo "Creating personal user and groups."
read -r -p "Please enter your desired username: " username
read -r -p "Please enter your desired password: " user_password
arch-chroot /mnt useradd -m -G "wheel,storage,optical" -s /bin/bash $username
printf "$user_password\n$user_password" | arch-chroot /mnt passwd $username
arch-chroot /mnt sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
# Bootloader
CPU=$(grep vendor_id /proc/cpuinfo)
if [[ $CPU == *"AuthenticAMD"* ]]; then
arch-chroot /mnt pacman -Syu --noconfirm --needed amd-ucode
REFIND_MICROCODE="initrd=\amd-ucode.img"
else
arch-chroot /mnt pacman -Syu --noconfirm --needed intel-ucode
REFIND_MICROCODE="initrd=\intel-ucode.img"
fi
case "$DISPLAY_DRIVER" in "nvidia"|"nvidia-dkms"|"nvidia-390xx"|"nvidia-390xx-lts")
CMDLINE_LINUX="nvidia-drm.modeset=1"
;;
esac
SILENT_PARAMS="quiet loglevel=3 rd.systemd.show_status=auto rd.udev.log_level=3"
RESUME="resume=PARTUUID=$UUID_SWAP"
CMDLINE_LINUX="$CMDLINE_LINUX $KERNELS_PARAMETERS $SILENT_PARAMS $RESUME"
# Configuring /etc/mkinitcpio.conf
echo "Configuring /etc/mkinitcpio.conf"
HOOKS="base systemd keyboard autodetect filesystems block"
arch-chroot /mnt sed -i "s/^HOOKS=(.*)/HOOKS=($HOOKS)/" /etc/mkinitcpio.conf
arch-chroot /mnt sed -i "s/^MODULES=(.*)/MODULES=($MKINITCPICO_KMS_MODULES)/" /etc/mkinitcpio.conf
# Setting mkinitcpio.
echo "Setting mkinitcpio."
cat <<EOT > "/mnt/etc/mkinitcpio.d/linux-zen.preset"
# mkinitcpio preset file for the 'linux-zen' package
cp -af "/boot/vmlinuz-linux-zen" "/boot/efi/" 2>/dev/null
cp -af "/boot/intel-ucode.img" "/boot/efi/" 2>/dev/null
cp -af "/boot/amd-ucode.img" "/boot/efi" 2>/dev/null
ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/efi/vmlinuz-linux-zen"
PRESETS=('default')
#default_config="/etc/mkinitcpio.conf"
default_image="/boot/efi/initramfs-linux-zen"
#default_options=""
EOT
# Setting mkinitcpio.
echo "Setting mkinitcpio."
arch-chroot /mnt mkinitcpio -P
# Clearing up mkinitpcio files.
arch-chroot /mnt rm -f /boot/*
# Refind
arch-chroot /mnt pacman -Syu --noconfirm --needed gdisk
arch-chroot /mnt pacman -Syu --noconfirm --needed refind
arch-chroot /mnt refind-install
arch-chroot /mnt sed -i "s/^use_graphics_for.*/use_graphics_for linux,windows/" /boot/efi/EFI/refind/refind.conf
arch-chroot /mnt sed -i "s/^#scan_all_linux_kernels.*/scan_all_linux_kernels false/" /boot/efi/EFI/refind/refind.conf
arch-chroot /mnt sed -i "s/^timeout.*/timeout -1/" /boot/efi/EFI/refind/refind.conf
arch-chroot /mnt sed -i "s/^#default_selection 1/default_selection vmlinuz-linux-zen/" /boot/efi/EFI/refind/refind.conf
cat <<EOT >> "/mnt/boot/efi/EFI/refind/refind.conf"
menuentry "Arch Linux (zen)" {
volume $UUID_BOOT
loader \vmlinuz-linux-zen
initrd \initramfs-linux-zen
icon \EFI\refind\icons\os_arch.png
options "root=PARTUUID=$UUID_ROOT $REFIND_MICROCODE rw $CMDLINE_LINUX"
}
EOT
arch-chroot /mnt rm /boot/refind_linux.conf
# Installing custom shell.
echo "Installing custom shell."
arch-chroot /mnt pacman -Syu --noconfirm --needed zsh
CUSTOM_SHELL_PATH="/usr/bin/zsh"
arch-chroot /mnt chsh -s "/usr/bin/zsh" "root"
arch-chroot /mnt chsh -s "/usr/bin/zsh" $username
# Installing WM/DE.
echo "Installing WM/DE."
arch-chroot /mnt pacman -Syu --noconfirm --needed i3-gaps i3blocks i3lock i3status dmenu rxvt-unicode lightdm lightdm-gtk-greeter xorg-server xorg-apps xorg-xinit
arch-chroot /mnt systemctl enable lightdm.service
arch-chroot /mnt systemctl set-default graphical.target
# Installing bare bones packages
arch-chroot /mnt pacman -Syu --noconfirm --needed neovim man-db man-pages texinfo elinks git
# Enabling Network
echo "Installing network."
arch-chroot /mnt pacman -Syu --noconfirm --needed networkmanager
arch-chroot /mnt systemctl enable NetworkManager.service
arch-chroot /mnt systemctl enable systemd-resolved.service
arch-chroot /mnt systemctl disable systemd-networkd.service
if [[ $CPU != *"AuthenticAMD"* ]]; then
cat <<EOT >> "/mnt/boot/home/$username/.Xresources"
Xft.dpi: 176
URxvt.font: xft:Source Code Pro: size=15
EOT
fi