This commit is contained in:
proledatarian 2024-08-23 16:29:51 +02:00
parent e88fee8fc2
commit 0e6f16c226
1 changed files with 122 additions and 124 deletions

View File

@ -15,8 +15,7 @@ echo "This script will ERASE ALL DATA on the partition you will choose next!"
echo echo
read -p "Do you want to continue? Type [Y]es or [N]o. " -n 1 -r read -p "Do you want to continue? Type [Y]es or [N]o. " -n 1 -r
echo echo
if [[ ! $REPLY =~ ^[Yy]$ ]] if [[ ! $REPLY =~ ^[Yy]$ ]]; then
then
exit 1 exit 1
fi fi
clear clear
@ -30,13 +29,10 @@ echo
IFS=$'\n' IFS=$'\n'
# Set variable containing name and size of all disks. # Set variable containing name and size of all disks.
dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') ) declare -a dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') )
# Declare the array.
declare -a dsks
# Select value on array. # Select value on array.
select dev in ${dsks[*]} select dev in "${dsks[@]}"
do do
break break
@ -47,7 +43,7 @@ echo
IFS=' ' IFS=' '
# Create new variable of selection. # Create new variable of selection.
array=($dev) array=("${dev}")
dev="${array[0]}" dev="${array[0]}"
clear clear
@ -58,13 +54,13 @@ echo
# Setting encryption password. # Setting encryption password.
echo "Choose a strong password for encrypting the primary partition:" echo "Choose a strong password for encrypting the primary partition:"
pwcr="" pwcr=""
while [ -z "$pwcr" ]; do while [[ -z "${pwcr}" ]]; do
echo "Please enter a password: " echo "Please enter a password: "
read -s pwfr read -rs pwfr
read -s -p "Retype a password: " pwsc read -rs -p "Retype a password: " pwsc
if [ $pwfr == $pwsc ]; if [[ "${pwfr}" == "${pwsc}" ]];
then then
pwcr=$pwfr pwcr="${pwfr}"
echo echo
echo "Both passwords are the same. Continuing.." echo "Both passwords are the same. Continuing.."
break break
@ -82,7 +78,7 @@ echo
# Setting hostname. # Setting hostname.
echo "Before installing the system, please enter a hostname:" echo "Before installing the system, please enter a hostname:"
read host read -r host
clear clear
@ -92,13 +88,13 @@ echo
# Setting root password. # Setting root password.
echo "Choose a password for the root account:" echo "Choose a password for the root account:"
pwr="" pwr=""
while [ -z "$pwr" ]; do while [[ -z "${pwr}" ]]; do
echo "Please enter a password: " echo "Please enter a password: "
read -s pwfr read -rs pwfr
read -s -p "Retype a password: " pwsc read -rs -p "Retype a password: " pwsc
if [ $pwfr == $pwsc ];
then if [[ "${pwfr}" == "${pwsc}" ]]; then
pwrt=$pwfr pwrt="${pwfr}"
echo echo
echo "Both passwords are the same. Continuing.." echo "Both passwords are the same. Continuing.."
break break
@ -116,19 +112,20 @@ echo
# Setting username # Setting username
echo "Please enter a username:" echo "Please enter a username:"
read user read -r user
echo echo
# Setting user password. # Setting user password.
echo "Also please choose a password for your user:" echo "Also please choose a password for your user:"
pwu="" pwu=""
while [ -z "$pwu" ]; do while [[ -z "${pwu}" ]]; do
echo "Please enter a password: " echo "Please enter a password: "
read -s pwfr read -rs pwfr
read -s -p "Retype a password: " pwsc read -rs -p "Retype a password: " pwsc
if [ $pwfr == $pwsc ];
if [[ "${pwfr}" == "${pwsc}" ]];
then then
pwur=$pwfr pwur="${pwfr}"
echo echo
echo "Both passwords are the same. Continuing.." echo "Both passwords are the same. Continuing.."
break break
@ -145,144 +142,145 @@ echo "5. INSTALLING SYSTEM.."
echo echo
# Starting partitioning. # Starting partitioning.
echo "Partitioning /dev/$dev.." echo "Partitioning /dev/${dev}.."
echo echo
# Clearing partition table of selected disk. # Clearing partition table of selected disk.
echo "Clearing existing partitioning table." echo "Clearing existing partitioning table."
sgdisk -Z /dev/$dev && sgdisk -Z "/dev/${dev}"
echo echo
# Creating boot partition. # Creating boot partition.
echo "Creating boot partition of 512 MB." echo "Creating boot partition of 512 MB."
sgdisk -n 1:0:+512M /dev/$dev && sgdisk -n 1:0:+512M "/dev/${dev}"
echo echo
# Setting type for EFI. # Setting type for EFI.
echo "Setting partition type." echo "Setting partition type."
sgdisk -t 1:ef00 /dev/$dev && sgdisk -t 1:ef00 "/dev/${dev}"
echo echo
# Creating system partition. # Creating system partition.
echo "Creating system partition." echo "Creating system partition."
sgdisk -n 2:0:0 /dev/$dev sgdisk -n 2:0:0 "/dev/${dev}"
echo echo
# Print partitions. # Print partitions.
echo "This is your new partition table:" echo "This is your new partition table:"
lsblk | grep "$dev" lsblk | grep "${dev}"
echo echo
# Get new variable. # Get new variable.
if [ $dev = "nvme0n1" ]; if [[ "${dev}" = "nvme0n1" ]]; then
then main="${dev}p2"
main=${dev}p2
else else
main=${dev}2 main="${dev}2"
fi fi
# Encrypting partition. # Encrypting partition.
echo "Encrypting system partition. This might take a while." echo "Encrypting system partition. This might take a while."
echo echo
echo -en "$pwcr\n$pwcr" | cryptsetup -c aes-xts-plain -s 512 luksFormat /dev/$main && echo -en "${pwcr}\n${pwcr}" | cryptsetup -c aes-xts-plain -s 512 luksFormat /dev/$main
echo "Partition successfully encrypted." echo "Partition successfully encrypted."
echo echo
# Opening encrypted partition and mounting at /dev/mapper/main. # Opening encrypted partition and mounting at /dev/mapper/main.
echo "Decrypting.. This also might take a while." echo "Decrypting.. This also might take a while."
echo echo
echo -en "$pwcr\n$pwcr" | cryptsetup luksOpen /dev/$main main && echo -en "${pwcr}\n${pwcr}" | cryptsetup luksOpen "/dev/${main}" main
echo "Partition successfully opened." echo "Partition successfully opened."
echo echo
lsblk | grep "$dev" lsblk | grep "${dev}"
echo echo
echo "Creating the filesystem." echo "Creating the filesystem."
if [ $dev = "nvme0n1" ]; if [ "${dev}" = "nvme0n1" ]; then
then boot="${dev}p1"
boot=${dev}p1
else else
boot=${dev}1 boot="${dev}1"
fi fi
mkfs.fat -F 32 -n UEFI /dev/$boot && mkfs.fat -F 32 -n UEFI "/dev/${boot}"
echo "Filesystem for boot successfully created." echo "Filesystem for boot successfully created."
echo echo
# Creating btrfs partition. # Creating btrfs partition.
mkfs.btrfs /dev/mapper/main && mkfs.btrfs "/dev/mapper/main"
mount /dev/mapper/main /mnt && mount "/dev/mapper/main" "/mnt"
btrfs subvolume create /mnt/root && btrfs subvolume create "/mnt/root"
btrfs subvolume create /mnt/home && btrfs subvolume create "/mnt/home"
umount /mnt && umount "/mnt"
echo echo
echo "Mounting.." && echo "Mounting.."
mount -o autodefrag,compress=zstd:3,subvol=root /dev/mapper/main /mnt && mount -o autodefrag,compress=zstd:3,subvol=root "/dev/mapper/main" "/mnt"
mkdir /mnt/home && mkdir "/mnt/home "
mount -o autodefrag,compress=zstd:3,subvol=home /dev/mapper/main /mnt/home && mount -o autodefrag,compress=zstd:3,subvol=home "/dev/mapper/main" "/mnt/home"
mkdir /mnt/boot && mkdir "/mnt/boot"
mount /dev/$boot /mnt/boot && mount "/dev/${boot}" "/mnt/boot"
echo "Mounting complete." && echo "Mounting complete."
echo echo
lsblk lsblk -a
echo echo
# Updating mirrors using reflector. # Updating mirrors using reflector.
echo "Updating mirrors.." echo "Updating mirrors.."
reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist && reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
echo "Done." echo "Done."
echo echo
# Check if keyring is up-to-date
if checkupdates | grep -q archlinux-keyring; then
echo "Updating keyring.." echo "Updating keyring.."
pacman -Sy archlinux-keyring --noconfirm && pacman -Sy archlinux-keyring --noconfirm
echo "Done." echo "Done."
fi
echo echo
# Installing base system. # Installing base system.
echo "Installing basic packages.." echo "Installing basic packages.."
pacstrap /mnt base btrfs-progs firefox konsole linux linux-firmware linux-zen nano networkmanager plasma-desktop sddm sddm-kcm sudo xorg-xwayland && pacstrap "/mnt" base btrfs-progs firefox konsole linux linux-firmware linux-zen nano networkmanager plasma-desktop sddm sddm-kcm sudo xorg-xwayland
echo "Base system installed." echo "Base system installed."
echo echo
# Generating fstab. # Generating fstab.
echo "Generating fstab.." echo "Generating fstab.."
genfstab -Up /mnt > /mnt/etc/fstab && genfstab -Up "/mnt" > "/mnt/etc/fstab"
echo "Done." echo "Done."
echo echo
# Setting hostname. # Setting hostname.
echo "Setting hostname.." echo "Setting hostname.."
echo $host > /mnt/etc/hostname && echo "${host}" > "/mnt/etc/hostname"
echo "Done." echo "Done."
echo echo
# Setting locale. # Setting locale.
echo "Setting and generating locale.." echo "Setting and generating locale.."
cat << EOF >/mnt/etc/locale.gen cat << EOF > "/mnt/etc/locale.gen"
en_US.UTF-8 UTF-8 en_US.UTF-8 UTF-8
EOF EOF
#echo "${localegen}" >>/mnt/etc/locale.gen #echo "${localegen}" >>/mnt/etc/locale.gen
arch-chroot /mnt locale-gen arch-chroot "/mnt" locale-gen
echo "LANG=en_US.UTF-8" > /mnt/etc/locale.conf && echo "LANG=en_US.UTF-8" > "/mnt/etc/locale.conf"
echo "KEYMAP=de-latin1" > /mnt/etc/vconsole.conf && echo "KEYMAP=de-latin1" > "/mnt/etc/vconsole.conf"
echo "Done." echo "Done."
echo echo
# Set X locale and keyboard alyout. # Set X locale and keyboard alyout.
echo "Setting locale and keyboard layout." echo "Setting locale and keyboard layout."
#arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys && #arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys
systemd-firstboot --root=/mnt --keymap=de-latin1-nodeadkeys && systemd-firstboot --root=/mnt --keymap=de-latin1-nodeadkeys
cat << EOF > /mnt/etc/X11/xorg.conf.d/00-keyboard.conf && cat << EOF > "/mnt/etc/X11/xorg.conf.d/00-keyboard.conf"
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's # 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 # probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it. # instruct systemd-localed to update it.
@ -299,7 +297,7 @@ echo
# Editing mkinitcpio.conf. # Editing mkinitcpio.conf.
echo "Editing /etc/mkinitcpio.conf.." echo "Editing /etc/mkinitcpio.conf.."
sed -i '55s/.*/HOOKS=(base udev autodetect microcode modconf kms block keyboard keymap encrypt filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf && sed -i '55s/.*/HOOKS=(base udev autodetect microcode modconf kms block keyboard keymap encrypt filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf
echo "Done." echo "Done."
echo echo
@ -308,40 +306,40 @@ echo
# Creating inital ramdisk. # Creating inital ramdisk.
echo "Creating inital ramdisk for linux-zen.." echo "Creating inital ramdisk for linux-zen.."
arch-chroot /mnt mkinitcpio -p linux-zen && arch-chroot /mnt mkinitcpio -p linux-zen
echo "Done." echo "Done."
echo echo
# Enable network and display manager. # Enable network and display manager.
echo "Enabling Networkmanager and display manager (sddm).." echo "Enabling Networkmanager and display manager (sddm).."
arch-chroot /mnt systemctl enable NetworkManager sddm && arch-chroot "/mnt" systemctl enable NetworkManager sddm
echo "Done." echo "Done."
echo echo
# Set root password # Set root password
echo "Setting root password.." echo "Setting root password.."
echo -en "$pwrt\n$pwrt" | arch-chroot /mnt passwd echo -en "${pwrt}\n${pwrt}" | arch-chroot "/mnt" passwd
echo "Done." echo "Done."
echo echo
# Install bootloader. # Install bootloader.
echo "Installing systemd-boot.." echo "Installing systemd-boot.."
arch-chroot /mnt bootctl --path=/boot install && arch-chroot "/mnt" bootctl --path=/boot install
echo "Done." echo "Done."
echo echo
# Get UUID for primary partition # Get UUID for primary partition
uuid=$(ls -l /dev/disk/by-uuid | grep $main | awk '{print $9}') uuid=$(ls -l /dev/disk/by-uuid | grep "${main}" | awk '{print $9}')
# Set bootloader entry. # Set bootloader entry.
echo "Setting up bootloader.." echo "Setting up bootloader.."
cat << EOF > /mnt/boot/loader/entries/arch.conf && cat << EOF > "/mnt/boot/loader/entries/arch.conf"
title Arch Linux title Arch Linux
linux /vmlinuz-linux-zen linux /vmlinuz-linux-zen
#initrd /amd-ucode.img #initrd /amd-ucode.img
#initrd /intel-ucode.img #initrd /intel-ucode.img
initrd /initramfs-linux-zen.img initrd /initramfs-linux-zen.img
options cryptdevice=UUID=$uuid:main options cryptdevice=UUID=${uuid}:main
options root=/dev/mapper/main rw options root=/dev/mapper/main rw
options rootflags=subvol=root options rootflags=subvol=root
options lang=de locale=de_DE.UTF-8 options lang=de locale=de_DE.UTF-8
@ -349,11 +347,11 @@ options init=/usr/lib/systemd/systemd
EOF EOF
# Set bootloader fallback entry. # Set bootloader fallback entry.
cat << EOF > /mnt/boot/loader/entries/arch-fallback.conf && cat << EOF > "/mnt/boot/loader/entries/arch-fallback.conf"
title Arch Linux Fallback title Arch Linux Fallback
linux /vmlinuz-linux linux /vmlinuz-linux
initrd /initramfs-linux-fallback.img initrd /initramfs-linux-fallback.img
options cryptdevice=UUID=$uuid:main options cryptdevice=UUID=${uuid}:main
options root=/dev/mapper/main rw options root=/dev/mapper/main rw
options rootflags=subvol=root options rootflags=subvol=root
options lang=de locale=de_DE.UTF-8 options lang=de locale=de_DE.UTF-8
@ -361,26 +359,26 @@ options init=/usr/lib/systemd/systemd
EOF EOF
# Set bootloader. # Set bootloader.
echo "timeout 1" >> /mnt/boot/loader/loader.conf && echo "timeout 1" >> "/mnt/boot/loader/loader.conf"
echo "default arch.conf" >> /mnt/boot/loader/loader.conf && echo "default arch.conf" >> "/mnt/boot/loader/loader.conf"
echo "Done." echo "Done."
echo echo
# Set username, password and group. # Set username, password and group.
echo "Adding user.." echo "Adding user.."
arch-chroot /mnt useradd -m $user && arch-chroot /mnt useradd -m "${user}"
echo -en "$pwur\n$pwur" | arch-chroot /mnt passwd $user && echo -en "${pwur}\n${pwur}" | arch-chroot /mnt passwd "${user}"
arch-chroot /mnt gpasswd -a $user wheel && arch-chroot /mnt gpasswd -a "${user}" wheel
sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers
echo "Done." echo "Done."
echo echo
# Enabling sddm auto-login. # Enabling sddm auto-login.
echo "Enabling auto-login.." echo "Enabling auto-login.."
mkdir /mnt/etc/sddm.conf.d && mkdir /mnt/etc/sddm.conf.d
cat << EOF > /mnt/etc/sddm.conf.d/autologin.conf cat << EOF > /mnt/etc/sddm.conf.d/autologin.conf
[Autologin] [Autologin]
User=$user User=${user}
Session=plasma Session=plasma
EOF EOF
echo "Done." echo "Done."
@ -391,7 +389,7 @@ cat << EOF > /mnt/etc/sddm.conf.d/kde_settings.conf
[Autologin] [Autologin]
Relogin=false Relogin=false
Session=plasma Session=plasma
User=$user User=${user}
[General] [General]
HaltCommand=/usr/bin/systemctl poweroff HaltCommand=/usr/bin/systemctl poweroff
@ -407,8 +405,8 @@ EOF
# Unmounting and rebooting. # Unmounting and rebooting.
echo "Unmounting system.." echo "Unmounting system.."
umount /mnt/boot && umount "/mnt/boot"
umount /mnt && umount "/mnt"
echo "Done." echo "Done."
echo echo