Files

487 lines
11 KiB
Bash
Raw Permalink Normal View History

2022-02-13 15:18:55 +00:00
#!/bin/bash
2024-05-05 16:57:37 +00:00
set -euo pipefail
2023-03-26 20:08:58 +00:00
# Write log
2022-12-12 20:19:56 +00:00
exec >> >(tee -i /tmp/install.log)
exec 2>&1
2026-07-01 18:48:12 +02:00
function cleanup() {
umount /mnt/boot
umount /mnt/home
umount /mnt
cryptsetup close /dev/mapper/main
}
trap cleanup EXIT
2022-12-12 13:00:59 +00:00
clear
# Friendly introduction
2024-05-05 16:55:37 +00:00
echo "0. WELCOME"
2022-02-13 23:37:10 +00:00
echo "Welcome to the Arch Linux installation script!"
2022-02-14 13:48:27 +00:00
echo "This script will ERASE ALL DATA on the partition you will choose next!"
2022-02-13 23:37:10 +00:00
echo
read -p "Do you want to continue? Type [Y]es or [N]o. " -n 1 -r
2022-12-12 20:30:55 +00:00
echo
2024-08-23 16:29:51 +02:00
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
2022-02-13 23:37:10 +00:00
fi
2024-05-05 16:55:37 +00:00
clear
2022-02-14 14:37:22 +00:00
##########
# Selecting disk
2022-02-15 17:00:02 +00:00
echo "1. PARTITIONING"
2022-02-13 15:18:55 +00:00
echo "Please select a disk to partition:"
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Don't separate values by space
2022-02-13 15:18:55 +00:00
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 15:18:55 +00:00
# Select value on array
select dev in "${dsks[@]}"; do
break
2022-02-14 14:40:42 +00:00
done
2022-02-15 17:00:02 +00:00
echo
2022-02-14 14:40:42 +00:00
# Separate values by spaces
2022-02-14 14:37:22 +00:00
IFS=' '
# Create new variable of selection
2024-10-08 21:17:17 +02:00
array=(${dev})
2022-02-14 14:37:22 +00:00
dev="${array[0]}"
2024-05-05 16:55:37 +00:00
clear
##########
2022-02-15 17:00:02 +00:00
echo "2. ENCRYPTION"
echo
2022-02-14 14:37:22 +00:00
# Setting encryption password.
2022-02-14 13:48:27 +00:00
echo "Choose a strong password for encrypting the primary partition:"
2024-05-05 16:55:37 +00: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 14:40:42 +00:00
done
2024-05-05 16:55:37 +00:00
clear
2022-02-14 14:40:42 +00:00
##########
2022-02-15 17:00:02 +00:00
echo "3. HOSTNAME"
echo
2022-02-14 14:37:22 +00: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 16:55:37 +00:00
clear
2022-02-14 13:48:27 +00:00
##########
2022-02-15 17:00:02 +00:00
echo "4. ROOT PASSWORD"
echo
2022-02-14 14:37:22 +00:00
# Setting root password.
2022-02-14 15:10:49 +00:00
echo "Choose a password for the root account:"
2024-05-05 16:55:37 +00: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 14:40:42 +00:00
done
2024-05-05 16:55:37 +00:00
clear
2022-02-14 13:48:27 +00:00
2022-02-15 17:00:02 +00:00
echo "4. USER"
echo
2022-02-14 14:37:22 +00:00
# Setting username
2022-02-15 17:00:02 +00:00
echo "Please enter a username:"
2024-08-23 16:29:51 +02:00
read -r user
2022-02-14 14:37:22 +00:00
echo
2022-02-14 13:48:27 +00:00
# Setting user password
2022-02-14 15:10:49 +00:00
echo "Also please choose a password for your user:"
2024-05-05 16:55:37 +00: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 14:40:42 +00:00
done
2024-05-05 16:55:37 +00:00
clear
2022-02-13 15:18:55 +00:00
##########
2022-02-15 17:00:02 +00:00
echo "5. INSTALLING SYSTEM.."
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Starting partitioning
2024-08-23 16:29:51 +02:00
echo "Partitioning /dev/${dev}.."
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Clearing partition table of selected disk
2022-02-13 15:18:55 +00:00
echo "Clearing existing partitioning table."
2024-08-23 16:29:51 +02:00
sgdisk -Z "/dev/${dev}"
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Creating boot partition
2024-01-31 13:04:55 +00: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-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Setting type for EFI
2022-12-12 20:44:41 +00:00
echo "Setting partition type."
2024-08-23 16:29:51 +02:00
sgdisk -t 1:ef00 "/dev/${dev}"
2022-12-12 20:44:41 +00:00
echo
2022-02-13 15:18:55 +00:00
# Creating system partition
2022-04-26 15:52:51 +00:00
echo "Creating system partition."
2024-08-23 16:29:51 +02:00
sgdisk -n 2:0:0 "/dev/${dev}"
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Print partitions
2022-02-13 15:18:55 +00:00
echo "This is your new partition table:"
2024-08-23 16:29:51 +02:00
lsblk | grep "${dev}"
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00: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-02 22:16:36 +00:00
fi
2022-02-13 15:18:55 +00:00
# Encrypting partition
2022-02-13 23:37:10 +00:00
echo "Encrypting system partition. This might take a while."
echo
2026-05-31 17:00:23 +02:00
# https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode
echo -en "${pwcr}\n${pwcr}" | cryptsetup -s 512 luksFormat /dev/$main
2022-02-13 15:18:55 +00:00
echo "Partition successfully encrypted."
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Opening encrypted partition and mounting at /dev/mapper/main
2022-02-13 23:37:10 +00: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-13 23:37:10 +00:00
echo "Partition successfully opened."
2026-07-04 11:25:11 +02:00
clear
2022-02-13 15:18:55 +00:00
##########
2022-02-13 15:18:55 +00:00
echo "Creating the filesystem."
2024-05-02 22:16:36 +00:00
2024-08-23 16:29:51 +02:00
if [ "${dev}" = "nvme0n1" ]; then
boot="${dev}p1"
else
boot="${dev}1"
2024-05-02 22:16:36 +00:00
fi
# Create boot filesystem
2024-08-23 16:29:51 +02:00
mkfs.fat -F 32 -n UEFI "/dev/${boot}"
2022-02-13 15:18:55 +00:00
echo "Filesystem for boot successfully created."
2022-02-13 23:37:10 +00:00
echo
2022-02-13 15:18:55 +00:00
# Creating btrfs filesystem
2024-08-23 16:29:51 +02:00
mkfs.btrfs "/dev/mapper/main"
2022-04-26 15:52:51 +00:00
2024-08-23 16:29:51 +02:00
mount "/dev/mapper/main" "/mnt"
2022-04-26 15:52:51 +00:00
2024-08-23 16:29:51 +02:00
btrfs subvolume create "/mnt/root"
btrfs subvolume create "/mnt/home"
2022-04-26 15:52:51 +00:00
2024-08-23 16:29:51 +02:00
umount "/mnt"
2022-10-18 14:34:45 +00:00
echo
2022-04-26 15:52:51 +00: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."
2026-07-04 11:25:11 +02:00
clear
2022-02-13 15:18:55 +00:00
##########
# Updating mirrors using reflector
# https://wiki.archlinux.org/title/Installation_guide#Select_the_mirrors
2022-02-13 15:25:31 +00:00
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 15:25:31 +00:00
echo "Done."
2022-02-15 17:00:02 +00:00
echo
2022-02-13 15:25:31 +00:00
2024-08-23 16:29:51 +02:00
# Check if keyring is up-to-date
echo "Updating keyring.."
pacman -Sy archlinux-keyring --needed --noconfirm
echo "Done."
2022-04-26 15:59:46 +00:00
echo
# Installing base system
# https://wiki.archlinux.org/title/Installation_guide#Install_essential_packages
2022-02-13 15:25:31 +00:00
echo "Installing basic packages.."
2025-02-10 13:20:55 +01:00
2025-06-17 14:12:26 +02:00
# Base packages
2025-02-11 10:03:55 +01:00
base_packages=(
2025-06-17 14:12:26 +02:00
base # Arch Linux Base
btrfs-progs # Btrfs
2025-02-11 10:03:55 +01:00
firefox
2025-06-17 14:12:26 +02:00
konsole # Terminal
2025-02-11 10:03:55 +01:00
linux
linux-firmware
linux-zen
2025-06-17 14:12:26 +02:00
nano # Editor
2025-02-11 10:03:55 +01:00
networkmanager
2026-07-01 16:40:47 +02:00
plasma-login-manager
2025-02-11 10:03:55 +01:00
sudo
xorg-xwayland
plasma-desktop
2025-06-17 14:12:26 +02:00
plasma-nm # Network manager applet
2025-02-11 10:03:55 +01:00
)
2025-06-17 14:12:26 +02:00
# Necessary Plasma integrations
2025-02-11 10:03:55 +01:00
plasma_integrations=(
2025-06-17 14:12:26 +02:00
plasma-pa # Audio applet
breeze-gtk # Widget theme
kde-gtk-config # Syncs KDE settings to GTK applications
kdeplasma-addons # Misc addons: https://github.com/KDE/kdeplasma-addons
kscreen # Adds screen management to settings
2025-02-11 10:03:55 +01:00
plasma-browser-integration
2025-06-17 14:12:26 +02:00
powerdevil # Power management
2025-02-11 10:03:55 +01:00
)
# KDE Utilities
kde_utils=(
2025-06-17 14:12:26 +02:00
ark # Archiving tool
bluedevil # Bluetooth
discover # GUI package management
dolphin # File browser
filelight # Disk usage analyzer
gwenview # Image viewer
kate # Text editor
kcalc # Calculator
kdeconnect # Mobile synchronisation tool
kinfocenter # System information
#kmag # Doesn't work on Wayland
2025-02-11 10:03:55 +01:00
plasma-systemmonitor
2025-06-17 14:12:26 +02:00
okular # PDF viewer
partitionmanager # partitioning utility
spectacle # Screenshot utility
2025-02-11 10:03:55 +01:00
)
# Additional default software
default_software=(
libreoffice
pipewire
pipewire-pulse
pipewire-alsa
wireplumber
)
2025-06-17 14:12:26 +02:00
# Put all packages together
2025-02-11 10:03:55 +01:00
all_packages=(
"${base_packages[@]}"
"${plasma_integrations[@]}"
"${kde_utils[@]}"
"${default_software[@]}"
)
2025-06-17 14:12:26 +02:00
# Install packages
2025-02-11 10:03:55 +01:00
pacstrap "/mnt" "${all_packages[@]}"
2025-02-10 13:20:55 +01:00
2022-02-13 15:25:31 +00:00
echo "Base system installed."
2026-07-04 11:25:11 +02:00
clear
2022-02-13 15:25:31 +00:00
##########
2025-06-17 14:12:26 +02:00
# Generating fstab
# https://wiki.archlinux.org/title/Installation_guide#Fstab
2022-10-18 14:34:45 +00:00
echo "Generating fstab.."
2024-08-23 16:29:51 +02:00
genfstab -Up "/mnt" > "/mnt/etc/fstab"
2022-04-26 15:59:46 +00:00
echo "Done."
2022-02-15 17:00:02 +00:00
echo
2022-02-13 15:25:31 +00:00
2026-07-01 22:15:23 +02:00
# Set time and hardware clock
2026-07-01 17:54:28 +02:00
# https://wiki.archlinux.org/title/Installation_guide#Time
2026-07-01 22:15:23 +02:00
echo "Setting timezone and clock.."
arch-chroot "/mnt" ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
arch-chroot "/mnt" hwclock --systohc
echo "Done."
echo
2026-07-01 22:15:23 +02:00
# Set hostname
# https://wiki.archlinux.org/title/Installation_guide#Network_configuration
echo "Setting hostname.."
echo "${host}" > "/mnt/etc/hostname"
echo "Done."
echo
# Set locale and keymap
# https://wiki.archlinux.org/title/Installation_guide#Localization
2026-07-01 22:15:23 +02:00
echo "Setting locale and keymap.."
echo "en_US.UTF-8 UTF-8" >> "/mnt/etc/locale.gen"
2026-07-08 11:01:44 +02:00
echo "de_DE.UTF-8 UTF-8" >> "/mnt/etc/locale.gen"
arch-chroot "/mnt" locale-gen
2026-07-01 23:44:14 +02:00
arch-chroot "/mnt" localectl set-locale LANG=en_US.UTF-8
2026-07-01 23:44:14 +02:00
echo "KEYMAP=de-latin1-nodeadkeys" > "/mnt/etc/vconsole.conf"
2026-07-01 22:15:23 +02:00
arch-chroot /mnt localectl set-keymap --no-convert de-latin1-nodeadkeys
echo "Done."
echo
##########
2022-02-15 22:24:43 +00:00
# Editing mkinitcpio.conf
2022-10-18 14:34:45 +00: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 15:25:31 +00:00
echo "Done."
2022-02-15 17:00:02 +00:00
echo
2022-02-13 15:25:31 +00:00
# Editing taskbar
2024-05-05 17:56:14 +00: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 17:45:46 +00:00
# Creating inital ramdisk
# https://wiki.archlinux.org/title/Installation_guide#Initramfs
2022-10-18 14:34:45 +00: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 15:25:31 +00:00
echo "Done."
2022-02-15 17:00:02 +00:00
echo
2022-02-13 15:25:31 +00:00
# Enable network and display manager
2026-07-01 16:40:47 +02:00
echo "Enabling NetworkManager and Plasma Login Manager.."
arch-chroot "/mnt" systemctl enable NetworkManager plasmalogin
2022-02-13 15:25:31 +00:00
echo "Done."
2022-02-15 17:00:02 +00:00
echo
2022-02-13 15:25:31 +00:00
##########
2022-02-14 15:10:49 +00:00
# Set root password
# https://wiki.archlinux.org/title/Installation_guide#Root_password
2022-10-18 14:34:45 +00: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 17:00:02 +00:00
echo "Done."
echo
2022-02-13 15:25:31 +00:00
# Install bootloader
# https://wiki.archlinux.org/title/Installation_guide#Boot_loader
2022-10-18 14:34:45 +00:00
echo "Installing systemd-boot.."
2024-08-23 16:29:51 +02:00
arch-chroot "/mnt" bootctl --path=/boot install
2022-02-15 17:00:02 +00:00
echo "Done."
echo
2022-02-13 15:25:31 +00:00
2022-12-12 13:00:34 +00: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 13:00:34 +00:00
# Set bootloader entry
2022-10-18 14:34:45 +00:00
echo "Setting up bootloader.."
2024-08-23 16:29:51 +02:00
cat << EOF > "/mnt/boot/loader/entries/arch.conf"
2022-02-13 15:25:31 +00: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 15:52:51 +00:00
options root=/dev/mapper/main rw
2022-11-29 22:26:20 +00:00
options rootflags=subvol=root
2022-02-13 15:25:31 +00:00
options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd
EOF
# Set bootloader fallback entry
2024-08-23 16:29:51 +02:00
cat << EOF > "/mnt/boot/loader/entries/arch-fallback.conf"
2022-02-13 15:25:31 +00: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 15:52:51 +00:00
options root=/dev/mapper/main rw
2022-11-29 22:26:20 +00:00
options rootflags=subvol=root
2022-02-13 15:25:31 +00:00
options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd
EOF
# 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 17:00:02 +00:00
echo "Done."
echo
2022-02-13 15:25:31 +00:00
# Set username, password and group
2022-10-18 14:34:45 +00: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 15:52:51 +00:00
sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers
2026-07-04 11:25:11 +02:00
# Create keyboard layout
2026-07-04 12:01:08 +02:00
config_dir="/home/${user}/.config"
arch-chroot /mnt sudo -u "${user}" mkdir -p "${config_dir}"
2026-07-07 09:42:25 +02:00
arch-chroot /mnt sudo -u "${user}" bash -c \
2026-07-04 12:01:08 +02:00
"printf '[Layout]\nLayoutList=de\nUse=true' >> ${config_dir}/kxkbrc"
2022-02-15 17:00:02 +00:00
echo "Done."
echo
2022-02-13 15:25:31 +00:00
# Enabling plasma login manager auto login
2026-07-01 16:40:47 +02:00
echo "Enabling auto login.."
cat << EOF > /mnt/etc/plasmalogin.conf
2022-02-15 17:00:02 +00:00
[Autologin]
2026-07-01 16:40:47 +02:00
Session=plasma.desktop
2024-08-23 16:29:51 +02:00
User=${user}
2022-02-15 17:00:02 +00:00
EOF
echo "Done."
echo
2022-02-13 15:25:31 +00:00
2022-03-31 22:02:10 +00:00
clear
echo "Installation finished!"
2022-12-16 17:22:15 +00: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 22:11:53 +00:00
# less /tmp/install.log
2022-12-16 17:22:15 +00:00
#fi
#echo
2022-12-16 15:43:42 +00:00
2022-10-18 14:34:45 +00: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