Arch-Linux-Installer/install.sh

287 lines
6.6 KiB
Bash
Raw Normal View History

2022-02-13 16:18:55 +01:00
#!/bin/bash
#PS3="Please select a disk to partition:"
echo "Please select a disk to partition:"
# Don't separate values by space.
IFS=$'\n'
# Set variable containing name and size of all disks.
disks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') )
# Declare the array.
declare -a disks
# Select value on array.
select disk in ${disks[*]}
do
# Separate values by spaces.
IFS=' '
# Create new variable of selection.
array=($disk)
dev="${array[0]}"
echo -e
# Starting partitioning.
echo "Partitioning /dev/$dev.."
echo -e
# Clearing partition table of selected disk.
echo "Clearing existing partitioning table."
sgdisk -Z /dev/$dev &&
echo -e
# Creating boot partition.
size="${array[1]%?}"
echo "Creating boot partition of 256 MB."
sgdisk -n 1:0:+256M /dev/$dev &&
# Setting type for EFI.
sgdisk -t 1:ef00 /dev/$dev &&
echo -e
# Creating system partition.
echo "Creating system partition of $size GB."
sgdisk -n 2:0:0 /dev/$dev
echo -e
# Print partitions.
echo "This is your new partition table:"
lsblk | grep "$dev"
echo $dev > /tmp/disk
# Exit.
break
done
# Get variable from filesystem.
part=$(</tmp/disk)2
# Encrypting partition.
echo "Encrypting system partition."
echo -e
cryptsetup -c aes-xts-plain -y -s 512 luksFormat /dev/$part &&
echo "Partition successfully encrypted."
echo -e
# Opening encrypted partition and mounting at /dev/mapper/lvm.
echo "Opening and mounting encrypted partition."
echo -e
cryptsetup luksOpen /dev/$part lvm &&
echo "Partition opened and mounted:"
echo -e
disk="${part%?}"
lsblk | grep "$disk"
echo -e
# Creating physical volume.
echo "Creating physical volume."
pvcreate /dev/mapper/lvm &&
echo -e
# Creating volume group "main".
echo "Creating volume group."
vgcreate main /dev/mapper/lvm &&
echo -e
# Creating logical volumes.
echo "Creating logical volumes for root and home."
echo -e
# Lol, this part:
part=$(</tmp/disk)2 && i=( $(lsblk | grep "$part" | tail -n+1 | awk '{print $4}') ) && size="${i%?}"
echo "Your system partition has a size of $size GB."
echo "What size should your root partition have?"
read root
echo "Creating a $root GB root volume."
echo -e
lvcreate -L ${root}G -n root main &&
lvcreate -l 100%FREE -n home main &&
echo -e
echo "Logical volumes successfully created."
echo -e
echo "Creating the filesystem."
echo -e
boot=$(</tmp/disk)1
mkfs.fat -F 32 -n UEFI /dev/$boot &&
echo "Filesystem for boot successfully created."
echo -e
mkfs.ext4 -L root /dev/mapper/main-root &&
echo "Filesystem for root successfully created."
echo -e
mkfs.ext4 -L home /dev/mapper/main-home &&
echo "Filesystem for home successfully created."
echo -e
echo "Mounting.."
echo -e
mount /dev/mapper/main-root /mnt
mkdir /mnt/boot
mkdir /mnt/home
mount /dev/$boot /mnt/boot
mount /dev/mapper/main-home /mnt/home
echo "Mounting complete."
echo -e
lsblk
echo -e
2022-02-13 16:25:31 +01:00
# Updating mirrors using reflector.
echo "Updating mirrors.."
echo -e
#reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
reflector --verbose --latest 10 --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist &&
echo -e
echo "Done."
# Installing base system.
echo "Installing basic packages.."
echo -e
pacstrap /mnt base base-devel firefox konsole linux linux-firmware linux-zen lvm2 networkmanager nano plasma-desktop sddm sddm-kcm &&
echo -e
echo "Base system installed."
echo -e
# Generating fstab.
echo "Generating fstab."
genfstab -Up /mnt > /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 -e
localegen=$(cat /mnt/etc/locale.gen)
cat <<EOF >/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 -e
echo "Done."
# Editing mkinitcpio.conf.
echo "Editing /etc/mkinitcpio.conf."
echo -e
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 -e
echo "Done."
# Creating inital ramdisk.
echo "Creating inital ramdisk for linux-zen."
echo -e
arch-chroot /mnt mkinitcpio -p linux-zen &&
echo "Done."
# Enable network and display manager.
echo "Enabling Networkmanager and display manager (sddm)."
echo -e
arch-chroot /mnt systemctl enable NetworkManager sddm &&
echo -e
echo "Done."
echo "Setting root password:"
arch-chroot /mnt passwd
arch-chroot /mnt bootctl install
cat << EOF > /mnt/boot/loader/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/$part: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/arch-fallback.conf
title Arch Linux Fallback
linux /vmlinuz-linux
initrd /initramfs-linux-fallback.img
options cryptdevice=/dev/$part: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
localectl --no-convert set-keymap de-latin1-nodeadkeys
echo "Username?"
read user
useradd -m $user &&
passwd $user &&
gpasswd -a $user wheel
2022-02-13 16:27:55 +01:00
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
2022-02-13 16:25:31 +01:00
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
2022-02-13 16:27:55 +01:00
echo "User=$user" >> /mnt/etc/sddm.conf.d/autologin.conf
2022-02-13 16:25:31 +01:00
echo "Session=plasma" >> /mnt/etc/sddm.conf.d/autologin.conf
umount /mnt/boot
umount /mnt/home
reboot