Arch-Linux-Installer/install.sh

425 lines
9.2 KiB
Bash
Raw Normal View History

2022-02-13 16:18:55 +01:00
#!/bin/bash
2023-03-26 22:08:58 +02:00
# https://wizardzines.com/comics/bash-errors/bash-errors.png
2024-05-05 18:57:37 +02:00
set -euo pipefail
2023-03-26 22:08:58 +02:00
2022-12-12 21:19:56 +01:00
exec >> >(tee -i /tmp/install.log)
exec 2>&1
2022-12-12 14:00:59 +01:00
clear
2022-02-14 00:37:10 +01:00
# Friendly introduction.
2024-05-05 18:55:37 +02:00
echo "0. WELCOME"
2022-02-14 00:37:10 +01:00
echo "Welcome to the Arch Linux installation script!"
2022-02-14 14:48:27 +01:00
echo "This script will ERASE ALL DATA on the partition you will choose next!"
2022-02-14 00:37:10 +01:00
echo
read -p "Do you want to continue? Type [Y]es or [N]o. " -n 1 -r
2022-12-12 21:30:55 +01:00
echo
2024-08-23 16:29:51 +02:00
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
2022-02-14 00:37:10 +01:00
fi
2024-05-05 18:55:37 +02:00
clear
2022-02-14 15:37:22 +01:00
# Selecting disk.
2022-02-15 18:00:02 +01:00
echo "1. PARTITIONING"
2022-02-13 16:18:55 +01:00
echo "Please select a disk to partition:"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Don't separate values by space.
IFS=$'\n'
# Set variable containing name and size of all disks.
2024-08-23 16:29:51 +02:00
declare -a dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') )
2022-02-13 16:18:55 +01:00
# Select value on array.
2024-08-23 16:29:51 +02:00
select dev in "${dsks[@]}"
2022-02-13 16:18:55 +01:00
do
2022-02-14 15:40:42 +01:00
break
done
2022-02-15 18:00:02 +01:00
echo
2022-02-14 15:40:42 +01:00
2022-02-14 15:37:22 +01:00
# Separate values by spaces.
IFS=' '
# Create new variable of selection.
2024-10-08 21:17:17 +02:00
array=(${dev})
2022-02-14 15:37:22 +01:00
dev="${array[0]}"
2024-05-05 18:55:37 +02:00
clear
2022-02-15 18:00:02 +01:00
echo "2. ENCRYPTION"
echo
2022-02-14 15:37:22 +01:00
# Setting encryption password.
2022-02-14 14:48:27 +01:00
echo "Choose a strong password for encrypting the primary partition:"
2024-05-05 18:55:37 +02:00
pwcr=""
2024-08-23 16:29:51 +02:00
while [[ -z "${pwcr}" ]]; do
echo "Please enter a password: "
read -rs pwfr
read -rs -p "Retype a password: " pwsc
if [[ "${pwfr}" == "${pwsc}" ]];
then
pwcr="${pwfr}"
echo
echo "Both passwords are the same. Continuing.."
break
else
echo
echo "You have entered different passwords. Try again.."
echo
fi
2022-02-14 15:40:42 +01:00
done
2024-05-05 18:55:37 +02:00
clear
2022-02-14 15:40:42 +01:00
2022-02-15 18:00:02 +01:00
echo "3. HOSTNAME"
echo
2022-02-14 15:37:22 +01:00
# Setting hostname.
echo "Before installing the system, please enter a hostname:"
2024-08-23 16:29:51 +02:00
read -r host
2024-05-05 18:55:37 +02:00
clear
2022-02-14 14:48:27 +01:00
2022-02-15 18:00:02 +01:00
echo "4. ROOT PASSWORD"
echo
2022-02-14 15:37:22 +01:00
# Setting root password.
2022-02-14 16:10:49 +01:00
echo "Choose a password for the root account:"
2024-05-05 18:55:37 +02:00
pwr=""
2024-08-23 16:29:51 +02:00
while [[ -z "${pwr}" ]]; do
echo "Please enter a password: "
read -rs pwfr
read -rs -p "Retype a password: " pwsc
if [[ "${pwfr}" == "${pwsc}" ]]; then
pwrt="${pwfr}"
echo
echo "Both passwords are the same. Continuing.."
break
else
echo
echo "You have entered different passwords. Try again.."
echo
fi
2022-02-14 15:40:42 +01:00
done
2024-05-05 18:55:37 +02:00
clear
2022-02-13 16:18:55 +01:00
2022-02-15 18:00:02 +01:00
echo "4. USER"
echo
2022-02-14 15:37:22 +01:00
# Setting username
2022-02-15 18:00:02 +01:00
echo "Please enter a username:"
2024-08-23 16:29:51 +02:00
read -r user
2022-02-14 15:37:22 +01:00
echo
# Setting user password.
2022-02-14 16:10:49 +01:00
echo "Also please choose a password for your user:"
2024-05-05 18:55:37 +02:00
pwu=""
2024-08-23 16:29:51 +02:00
while [[ -z "${pwu}" ]]; do
echo "Please enter a password: "
read -rs pwfr
read -rs -p "Retype a password: " pwsc
if [[ "${pwfr}" == "${pwsc}" ]];
then
pwur="${pwfr}"
echo
echo "Both passwords are the same. Continuing.."
break
else
echo
echo "You have entered different passwords. Try again.."
echo
fi
2022-02-14 15:40:42 +01:00
done
2024-05-05 18:55:37 +02:00
clear
2022-02-14 15:37:22 +01:00
2022-02-15 18:00:02 +01:00
echo "5. INSTALLING SYSTEM.."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Starting partitioning.
2024-08-23 16:29:51 +02:00
echo "Partitioning /dev/${dev}.."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Clearing partition table of selected disk.
echo "Clearing existing partitioning table."
2024-08-23 16:29:51 +02:00
sgdisk -Z "/dev/${dev}"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating boot partition.
2024-01-31 14:04:55 +01:00
echo "Creating boot partition of 512 MB."
2024-08-23 16:29:51 +02:00
sgdisk -n 1:0:+512M "/dev/${dev}"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Setting type for EFI.
2022-12-12 21:44:41 +01:00
echo "Setting partition type."
2024-08-23 16:29:51 +02:00
sgdisk -t 1:ef00 "/dev/${dev}"
2022-12-12 21:44:41 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating system partition.
2022-04-26 17:52:51 +02:00
echo "Creating system partition."
2024-08-23 16:29:51 +02:00
sgdisk -n 2:0:0 "/dev/${dev}"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Print partitions.
echo "This is your new partition table:"
2024-08-23 16:29:51 +02:00
lsblk | grep "${dev}"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-02-14 14:48:27 +01:00
# Get new variable.
2024-08-23 16:29:51 +02:00
if [[ "${dev}" = "nvme0n1" ]]; then
main="${dev}p2"
else
main="${dev}2"
2024-05-03 00:16:36 +02:00
fi
2022-02-13 16:18:55 +01:00
# Encrypting partition.
2022-02-14 00:37:10 +01:00
echo "Encrypting system partition. This might take a while."
echo
2024-08-23 16:29:51 +02:00
echo -en "${pwcr}\n${pwcr}" | cryptsetup -c aes-xts-plain -s 512 luksFormat /dev/$main
2022-02-13 16:18:55 +01:00
echo "Partition successfully encrypted."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-04-26 17:52:51 +02:00
# Opening encrypted partition and mounting at /dev/mapper/main.
2022-02-14 00:37:10 +01:00
echo "Decrypting.. This also might take a while."
echo
2024-08-23 16:29:51 +02:00
echo -en "${pwcr}\n${pwcr}" | cryptsetup luksOpen "/dev/${main}" main
2022-02-14 00:37:10 +01:00
echo "Partition successfully opened."
echo
2022-02-13 16:18:55 +01:00
2024-08-23 16:29:51 +02:00
lsblk | grep "${dev}"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
echo "Creating the filesystem."
2024-05-03 00:16:36 +02:00
2024-08-23 16:29:51 +02:00
if [ "${dev}" = "nvme0n1" ]; then
boot="${dev}p1"
else
boot="${dev}1"
2024-05-03 00:16:36 +02:00
fi
2024-08-23 16:29:51 +02:00
mkfs.fat -F 32 -n UEFI "/dev/${boot}"
2022-02-13 16:18:55 +01:00
echo "Filesystem for boot successfully created."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-04-26 17:52:51 +02:00
# Creating btrfs partition.
2024-08-23 16:29:51 +02:00
mkfs.btrfs "/dev/mapper/main"
2022-04-26 17:52:51 +02:00
2024-08-23 16:29:51 +02:00
mount "/dev/mapper/main" "/mnt"
2022-04-26 17:52:51 +02:00
2024-08-23 16:29:51 +02:00
btrfs subvolume create "/mnt/root"
btrfs subvolume create "/mnt/home"
2022-04-26 17:52:51 +02:00
2024-08-23 16:29:51 +02:00
umount "/mnt"
2022-10-18 16:34:45 +02:00
echo
2022-04-26 17:52:51 +02:00
2024-08-23 16:29:51 +02:00
echo "Mounting.."
mount -o autodefrag,compress=zstd:3,subvol=root "/dev/mapper/main" "/mnt"
2024-10-08 21:23:21 +02:00
mkdir "/mnt/home"
2024-08-23 16:29:51 +02:00
mount -o autodefrag,compress=zstd:3,subvol=home "/dev/mapper/main" "/mnt/home"
mkdir "/mnt/boot"
mount "/dev/${boot}" "/mnt/boot"
echo "Mounting complete."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2024-08-23 16:29:51 +02:00
lsblk -a
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-02-13 16:25:31 +01:00
# Updating mirrors using reflector.
echo "Updating mirrors.."
2024-08-23 16:29:51 +02:00
reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
2024-08-23 16:29:51 +02:00
# Check if keyring is up-to-date
if checkupdates | grep -q archlinux-keyring; then
echo "Updating keyring.."
pacman -Sy archlinux-keyring --noconfirm
echo "Done."
fi
2022-04-26 17:59:46 +02:00
echo
2022-02-13 16:25:31 +01:00
# Installing base system.
echo "Installing basic packages.."
2024-08-23 16:29:51 +02:00
pacstrap "/mnt" base btrfs-progs firefox konsole linux linux-firmware linux-zen nano networkmanager plasma-desktop sddm sddm-kcm sudo xorg-xwayland
2022-02-13 16:25:31 +01:00
echo "Base system installed."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:25:31 +01:00
# Generating fstab.
2022-10-18 16:34:45 +02:00
echo "Generating fstab.."
2024-08-23 16:29:51 +02:00
genfstab -Up "/mnt" > "/mnt/etc/fstab"
2022-04-26 17:59:46 +02:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
# Setting hostname.
2022-10-18 16:34:45 +02:00
echo "Setting hostname.."
2024-08-23 16:29:51 +02:00
echo "${host}" > "/mnt/etc/hostname"
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
# Setting locale.
2022-10-18 16:34:45 +02:00
echo "Setting and generating locale.."
2024-08-23 16:29:51 +02:00
cat << EOF > "/mnt/etc/locale.gen"
2022-02-13 16:25:31 +01:00
en_US.UTF-8 UTF-8
EOF
2022-10-26 13:42:12 +02:00
2022-02-13 20:12:42 +01:00
#echo "${localegen}" >>/mnt/etc/locale.gen
2024-08-23 16:29:51 +02:00
arch-chroot "/mnt" locale-gen
echo "LANG=en_US.UTF-8" > "/mnt/etc/locale.conf"
echo "KEYMAP=de-latin1" > "/mnt/etc/vconsole.conf"
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
2022-02-15 23:24:43 +01:00
# Set X locale and keyboard alyout.
echo "Setting locale and keyboard layout."
2022-10-26 13:42:12 +02:00
2024-08-23 16:29:51 +02:00
#arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys
systemd-firstboot --root=/mnt --keymap=de-latin1-nodeadkeys
2022-02-15 23:24:43 +01:00
2024-08-23 16:29:51 +02:00
cat << EOF > "/mnt/etc/X11/xorg.conf.d/00-keyboard.conf"
2022-02-15 23:24:43 +01:00
# 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"
Option "XkbLayout" "de"
Option "XkbModel" "pc105"
Option "XkbVariant" "deadgraveacute"
EndSection
EOF
echo "Done."
echo
2022-02-13 16:25:31 +01:00
# Editing mkinitcpio.conf.
2022-10-18 16:34:45 +02:00
echo "Editing /etc/mkinitcpio.conf.."
2024-08-23 16:29:51 +02:00
sed -i '55s/.*/HOOKS=(base udev autodetect microcode modconf kms block keyboard keymap encrypt filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
2024-05-05 19:45:46 +02:00
# Editing taskbar.
2024-05-05 19:56:14 +02:00
#sed -i '65s/.*/launchers=applications:systemsettings.desktop,applications:org.kde.konsole.desktop,applications:firefox.desktop/' /mnt/home/${user}/.config/plasma-org.kde.plasma.desktop-appletsrc
2024-05-05 19:45:46 +02:00
2022-02-13 16:25:31 +01:00
# Creating inital ramdisk.
2022-10-18 16:34:45 +02:00
echo "Creating inital ramdisk for linux-zen.."
2024-08-23 16:29:51 +02:00
arch-chroot /mnt mkinitcpio -p linux-zen
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
# Enable network and display manager.
2022-10-18 16:34:45 +02:00
echo "Enabling Networkmanager and display manager (sddm).."
2024-08-23 16:29:51 +02:00
arch-chroot "/mnt" systemctl enable NetworkManager sddm
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
2022-02-14 16:10:49 +01:00
# Set root password
2022-10-18 16:34:45 +02:00
echo "Setting root password.."
2024-08-23 16:29:51 +02:00
echo -en "${pwrt}\n${pwrt}" | arch-chroot "/mnt" passwd
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-14 16:10:49 +01:00
# Install bootloader.
2022-10-18 16:34:45 +02:00
echo "Installing systemd-boot.."
2024-08-23 16:29:51 +02:00
arch-chroot "/mnt" bootctl --path=/boot install
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-12-12 14:00:34 +01:00
# Get UUID for primary partition
2024-08-23 16:29:51 +02:00
uuid=$(ls -l /dev/disk/by-uuid | grep "${main}" | awk '{print $9}')
2022-12-12 14:00:34 +01:00
2022-02-14 16:10:49 +01:00
# Set bootloader entry.
2022-10-18 16:34:45 +02:00
echo "Setting up bootloader.."
2024-08-23 16:29:51 +02:00
cat << EOF > "/mnt/boot/loader/entries/arch.conf"
2022-02-13 16:25:31 +01:00
title Arch Linux
linux /vmlinuz-linux-zen
#initrd /amd-ucode.img
#initrd /intel-ucode.img
initrd /initramfs-linux-zen.img
2024-08-23 16:29:51 +02:00
options cryptdevice=UUID=${uuid}:main
2022-04-26 17:52:51 +02:00
options root=/dev/mapper/main rw
2022-11-29 23:26:20 +01:00
options rootflags=subvol=root
2022-02-13 16:25:31 +01:00
options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd
EOF
2022-02-14 16:10:49 +01:00
# Set bootloader fallback entry.
2024-08-23 16:29:51 +02:00
cat << EOF > "/mnt/boot/loader/entries/arch-fallback.conf"
2022-02-13 16:25:31 +01:00
title Arch Linux Fallback
linux /vmlinuz-linux
initrd /initramfs-linux-fallback.img
2024-08-23 16:29:51 +02:00
options cryptdevice=UUID=${uuid}:main
2022-04-26 17:52:51 +02:00
options root=/dev/mapper/main rw
2022-11-29 23:26:20 +01:00
options rootflags=subvol=root
2022-02-13 16:25:31 +01:00
options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd
EOF
2022-02-14 16:10:49 +01:00
# Set bootloader.
2024-08-23 16:29:51 +02:00
echo "timeout 1" >> "/mnt/boot/loader/loader.conf"
echo "default arch.conf" >> "/mnt/boot/loader/loader.conf"
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-15 18:00:02 +01:00
# Set username, password and group.
2022-10-18 16:34:45 +02:00
echo "Adding user.."
2024-08-23 16:29:51 +02:00
arch-chroot /mnt useradd -m "${user}"
echo -en "${pwur}\n${pwur}" | arch-chroot /mnt passwd "${user}"
arch-chroot /mnt gpasswd -a "${user}" wheel
2022-04-26 17:52:51 +02:00
sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-15 18:00:02 +01:00
# Enabling sddm auto-login.
2022-10-18 16:34:45 +02:00
echo "Enabling auto-login.."
2024-08-23 16:29:51 +02:00
mkdir /mnt/etc/sddm.conf.d
2022-02-15 18:00:02 +01:00
cat << EOF > /mnt/etc/sddm.conf.d/autologin.conf
[Autologin]
2024-08-23 16:29:51 +02:00
User=${user}
2022-02-15 18:00:02 +01:00
Session=plasma
EOF
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-12-12 21:19:56 +01:00
# Adding sddm config.
cat << EOF > /mnt/etc/sddm.conf.d/kde_settings.conf
[Autologin]
Relogin=false
2024-05-03 00:04:55 +02:00
Session=plasma
2024-08-23 16:29:51 +02:00
User=${user}
2022-12-12 21:19:56 +01:00
[General]
HaltCommand=/usr/bin/systemctl poweroff
RebootCommand=/usr/bin/systemctl reboot
[Theme]
Current=breeze
[Users]
MaximumUid=60513
MinimumUid=1000
EOF
2022-02-15 18:00:02 +01:00
# Unmounting and rebooting.
2022-10-18 16:34:45 +02:00
echo "Unmounting system.."
2024-08-23 16:29:51 +02:00
umount "/mnt/boot"
umount "/mnt"
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-04-01 00:02:10 +02:00
clear
echo "Installation finished!"
2022-12-16 18:22:15 +01:00
#read -p "Do you want to read the log? Type [Y]es or [N]o. " -n 1 -r
#echo
#if [[ ! $REPLY =~ ^[Yy]$ ]]
#then
2023-03-07 23:11:53 +01:00
# less /tmp/install.log
2022-12-16 18:22:15 +01:00
#fi
#echo
2022-12-16 16:43:42 +01:00
2022-10-18 16:34:45 +02:00
#echo "Press [Enter] to shut down, then remove the installation media and start your system."
2024-08-23 16:29:51 +02:00
#poweroff