#!/bin/bash ### Variables: # $dsks = whole lsblk output (e.g. "sda 1,0T, sdb ..") # $disk = only selected disk (e.g. "sdc 500G") # $dev = selected disk without size (e.g. "sdd") # $main = main partition (e.g. "sde2") # $szmn = size of the main partition (e.g. "50") # szrt = size of root LVM volume # $boot = boot partition (e.g. "sdf1") # $host = hostname # $user = username # $pwur = user password # $pwrt = root password # $pwcr = encryption password # Friendly introduction. echo "Welcome to the Arch Linux installation script!" echo "This script will ERASE ALL DATA on the partition you will choose next!" echo read -p "Do you want to continue? Type [Y]es or [N]o. " -n 1 -r echo # (optional) move to a new line if [[ ! $REPLY =~ ^[Yy]$ ]] then exit 1 fi echo # Selecting disk. echo "Please select a disk to partition:" echo # Don't separate values by space. IFS=$'\n' # Set variable containing name and size of all disks. dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') ) # Declare the array. declare -a dsks # Select value on array. select dev in ${dsks[*]} do # Separate values by spaces. IFS=' ' # Create new variable of selection. array=($dev) dev="${array[0]}" szmn="${array[1]%?}" # Setting partition size. echo "Your system partition has a size of $szmn GB." echo "What size should your root partition have?" read szrt echo # Setting encryption password. echo "Choose a strong password for encrypting the primary partition:" while [ -z "$pwcr" ]; do echo "Please enter a password: " read -s pwfr read -s -p "Retype a password: " pwsc if [ $pwfr == $pwsc ]; then pwcr=$pwfr echo echo "Both passwords are the same. Continuing.." else echo echo "You have entered different passwords. Try again.." fi # Setting hostname. echo "Before installing the system, please enter a hostname:" echo read host echo # Setting root password. echo "Please enter a password for the root account:" while [ -z "$pwr" ]; do echo "Please enter a password: " read -s pwfr read -s -p "Retype a password: " pwsc if [ $pwfr == $pwsc ]; then pwrt=$pwfr echo echo "Both passwords are the same. Continuing.." else echo echo "You have entered different passwords. Try again.." fi echo # Setting username echo "And please enter a username:" read user echo # Setting user password. echo "Also please enter a password for your user:" while [ -z "$pwu" ]; do echo "Please enter a password: " read -s pwfr read -s -p "Retype a password: " pwsc if [ $pwfr == $pwsc ]; then pwur=$pwfr echo echo "Both passwords are the same. Continuing.." else echo echo "You have entered different passwords. Try again.." fi echo echo "System is getting installed.." echo # Starting partitioning. echo "Partitioning /dev/$dev.." echo # Clearing partition table of selected disk. echo "Clearing existing partitioning table." sgdisk -Z /dev/$dev && echo # Creating boot partition. #szmn="${array[1]%?}" echo "Creating boot partition of 256 MB." sgdisk -n 1:0:+256M /dev/$dev && echo # Setting type for EFI. sgdisk -t 1:ef00 /dev/$dev && # Creating system partition. echo "Creating system partition of $szmn GB." sgdisk -n 2:0:0 /dev/$dev echo # Print partitions. echo "This is your new partition table:" lsblk | grep "$dev" echo # Exit. break done # Get new variable. main=$(dev)2 # Encrypting partition. echo "Encrypting system partition. This might take a while." echo echo -en "&pwcr\n$pwcr" | cryptsetup -c aes-xts-plain -s 512 luksFormat /dev/$main && echo "Partition successfully encrypted." echo # Opening encrypted partition and mounting at /dev/mapper/lvm. echo "Decrypting.. This also might take a while." echo echo -en "&pwcr\n$pwcr" | cryptsetup luksOpen /dev/$main lvm && echo "Partition successfully opened." echo lsblk | grep "$dev" echo # Lol, this part: #main=$( /mnt/etc/fstab && echo "Installed fstab." # Setting hostname. echo "Please enter a hostname:" read host && echo $host > /mnt/etc/hostname echo "Hostname set." # Setting locale. echo "Setting and generating locale." echo #localegen=$(cat /mnt/etc/locale.gen) cat </mnt/etc/locale.gen en_US.UTF-8 UTF-8 de_DE.UTF-8 UTF-8 EOF #echo "${localegen}" >>/mnt/etc/locale.gen arch-chroot /mnt locale-gen echo "LANG=de_DE.UTF-8" >/mnt/etc/locale.conf echo "KEYMAP=de-latin1" > /mnt/etc/vconsole.conf echo echo "Done." # Editing mkinitcpio.conf. echo "Editing /etc/mkinitcpio.conf." echo sed -i '7s/.*/MODULES=(ext4)/' /mnt/etc/mkinitcpio.conf && sed -i '52s/.*/HOOKS=(base udev autodetect modconf block keyboard keymap encrypt lvm2 filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf && echo echo "Done." # Creating inital ramdisk. echo "Creating inital ramdisk for linux-zen." echo arch-chroot /mnt mkinitcpio -p linux-zen && echo "Done." # Enable network and display manager. echo "Enabling Networkmanager and display manager (sddm)." echo arch-chroot /mnt systemctl enable NetworkManager sddm && echo echo "Done." echo "Setting root password:" echo -en "&pwrt\n$pwrt" | arch-chroot /mnt passwd arch-chroot /mnt bootctl install cat << EOF > /mnt/boot/loader/entries/arch.conf # The title of your systemd-boot entry. title Arch Linux # Change only when using different kernel, e. g. /vmlinuz-linux-zen. linux /vmlinuz-linux-zen # Uncomment if you have installed the respective Microcode. #initrd /amd-ucode.img #initrd /intel-ucode.img # Change only when using different kernel, e. g. /vmlinuz-linux-zen. initrd /initramfs-linux-zen.img # Change to the correct device like /dev/sda2. options cryptdevice=/dev/$main:lvm:allow-discards # Change to correct LVM device. options root=/dev/mapper/main-root rw # Localization options. options lang=de locale=de_DE.UTF-8 # Default init is systemd. options init=/usr/lib/systemd/systemd # Prints only kernel errors and above on boot. #options loglevel=3 EOF cat << EOF > /mnt/boot/loader/entries/arch-fallback.conf title Arch Linux Fallback linux /vmlinuz-linux initrd /initramfs-linux-fallback.img options cryptdevice=/dev/$main:lvm options root=/dev/mapper/main-root rw options lang=de locale=de_DE.UTF-8 options init=/usr/lib/systemd/systemd EOF echo "timeout 1" >> /mnt/boot/loader/loader.conf echo "default arch.conf" >> /mnt/boot/loader/loader.conf arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys arch-chroot /mnt useradd -m $user && echo -en "&pwur\n$pwur" | arch-chroot /mnt passwd $user && arch-chroot /mnt gpasswd -a $user wheel cat << EOF > /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" Option "XkbLayout" "de" Option "XkbModel" "pc105" Option "XkbVariant" "deadgraveacute" EndSection EOF sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers mkdir /mnt/etc/sddm.conf.d echo "[Autologin]" >> /mnt/etc/sddm.conf.d/autologin.conf echo "User=$user" >> /mnt/etc/sddm.conf.d/autologin.conf echo "Session=plasma" >> /mnt/etc/sddm.conf.d/autologin.conf umount /mnt/boot umount /mnt/home reboot