2022-07-25 14:23:03 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# WARNING: this script will destroy data on the selected disk.
|
|
|
|
# This script can be run by executing the following:
|
|
|
|
# curl -sL https://git.io/vAoV8 | bash
|
|
|
|
set -uo pipefail
|
|
|
|
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
|
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
REPO_URL="https://mkessler-arch.maximilian-kessler.de"
|
2022-07-25 14:23:03 +02:00
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
reflector
|
2022-07-25 14:23:03 +02:00
|
|
|
|
|
|
|
### Get infomation from user ###
|
|
|
|
hostname=$(dialog --stdout --inputbox "Enter hostname" 0 0) || exit 1
|
|
|
|
clear
|
|
|
|
: ${hostname:?"hostname cannot be empty"}
|
|
|
|
|
|
|
|
user=$(dialog --stdout --inputbox "Enter username" 0 0) || exit 1
|
|
|
|
clear
|
|
|
|
: ${user:?"user cannot be empty"}
|
|
|
|
|
|
|
|
password=$(dialog --stdout --passwordbox "Enter disk encryption password" 0 0) || exit 1
|
|
|
|
clear
|
|
|
|
: ${password:?"password cannot be empty"}
|
|
|
|
password2=$(dialog --stdout --passwordbox "Enter disk encryption password again" 0 0) || exit 1
|
|
|
|
clear
|
|
|
|
[[ "$password" == "$password2" ]] || ( echo "Passwords did not match"; exit 1; )
|
|
|
|
|
|
|
|
devicelist=$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | tac)
|
|
|
|
device=$(dialog --stdout --menu "Select installation disk" 0 0 0 ${devicelist}) || exit 1
|
|
|
|
clear
|
|
|
|
|
|
|
|
# set up all further variables
|
|
|
|
|
|
|
|
cryptlvm="cryptlvm"
|
|
|
|
vlgrp="vlgrp"
|
|
|
|
key_fingerprint="B419CDA93D7544F8214B3216A23D90C2433DAFBC"
|
|
|
|
|
|
|
|
mapped_device="/dev/mapper/${cryptlvm}"
|
|
|
|
|
|
|
|
part_boot="${device}p1"
|
|
|
|
part_luks="${device}p2"
|
|
|
|
|
|
|
|
part_swap="/dev/${vlgrp}/swap"
|
|
|
|
part_root="/dev/${vlgrp}/root"
|
|
|
|
part_home="/dev/${vlgrp}/home"
|
|
|
|
|
|
|
|
|
|
|
|
### Set up logging ###
|
|
|
|
exec 1> >(tee "stdout.log")
|
|
|
|
exec 2> >(tee "stderr.log")
|
|
|
|
|
|
|
|
timedatectl set-ntp true
|
|
|
|
|
|
|
|
### Setup the disk and partitions ###
|
2022-07-25 15:42:17 +02:00
|
|
|
ram_size=$(free --mebi | awk '/Mem:/ {print $2}')
|
|
|
|
swap_size=$((ram_size + 1024))M # 1 Gigabyte more swap space than available ram
|
|
|
|
root_size=60G
|
2022-07-25 14:23:03 +02:00
|
|
|
|
|
|
|
# creates two partitions: one boot partition and another partition, filling the rest of space
|
|
|
|
echo "Creating partitions on ${device}..."
|
|
|
|
fdisk "${device}" <<EOF
|
|
|
|
g
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
+256M
|
|
|
|
t
|
|
|
|
EFI System
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
|
|
wipefs "${part_boot}"
|
|
|
|
wipefs "${part_luks}"
|
|
|
|
|
|
|
|
echo "Setting up luks on ${part_luks}"
|
|
|
|
echo "${password}" | cryptsetup luksFormat -q "${part_luks}"
|
2022-07-25 15:42:17 +02:00
|
|
|
echo "${password}" | cryptsetup open "${part_luks}" "${cryptlvm}"
|
2022-07-25 14:23:03 +02:00
|
|
|
|
|
|
|
pvcreate "${mapped_device}"
|
|
|
|
vgcreate "${vlgrp}" "${mapped_device}"
|
2022-07-25 16:19:50 +02:00
|
|
|
lvcreate -L "${swap_size}" "${vlgrp}" -n swap
|
|
|
|
lvcreate -L "${root_size}" "${vlgrp}" -n root
|
2022-07-25 14:23:03 +02:00
|
|
|
lvcreate -l '99%FREE' "${vlgrp}" -n home
|
|
|
|
|
|
|
|
mkfs.fat -F32 "${part_boot}"
|
|
|
|
mkfs.ext4 "${part_root}"
|
|
|
|
mkfs.ext4 "${part_home}"
|
|
|
|
mkswap "${part_swap}"
|
|
|
|
|
|
|
|
mount "${part_root}" /mnt
|
|
|
|
mount "${part_home}" /mnt/home --mkdir
|
|
|
|
mount "${part_boot}" /mnt/boot --mkdir
|
|
|
|
swapon "${part_swap}"
|
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
|
|
|
|
echo "Finished setting up luks, lvm and mounted all partitions"
|
|
|
|
sleep 1
|
|
|
|
echo "Retrivieng signing key for mkessler-arch repository..."
|
|
|
|
|
2022-07-25 14:23:03 +02:00
|
|
|
### Install and configure the basic system ###
|
2022-07-25 16:21:54 +02:00
|
|
|
# Receive and lsign signing key of custom repo
|
2022-07-25 14:23:03 +02:00
|
|
|
pacman-key --recv-keys keyid "${key_fingerprint}"
|
|
|
|
pacman-key --lsign-key "${key_fingerprint}"
|
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
echo "Installing packages into /mnt"
|
2022-07-25 14:23:03 +02:00
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
pacstrap /mnt mkessler-desktop
|
2022-07-25 14:23:03 +02:00
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
echo "Generating fstab file"
|
|
|
|
genfstab -U /mnt >> /mnt/etc/fstab
|
2022-07-25 18:13:48 +02:00
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
echo "Setting hostname"
|
|
|
|
echo "${hostname}" > /mnt/etc/hostname
|
2022-07-25 18:13:48 +02:00
|
|
|
|
2022-07-25 18:55:50 +02:00
|
|
|
echo "Configuring mkessler-arch repo in installed system"
|
2022-07-25 14:23:03 +02:00
|
|
|
### Set up custom repo on installed system as well
|
|
|
|
cat >>/mnt/etc/pacman.conf <<EOF
|
2022-07-25 18:55:50 +02:00
|
|
|
|
2022-07-25 14:23:03 +02:00
|
|
|
[mkessler-arch]
|
|
|
|
Server = $REPO_URL
|
|
|
|
EOF
|
2022-07-25 18:55:50 +02:00
|
|
|
|
|
|
|
echo "Finished installation"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
2022-07-25 14:23:03 +02:00
|
|
|
arch-chroot /mnt pacman-key --recv-keys keyid "${key_fingerprint}"
|
|
|
|
arch-chroot /mnt pacman-key --lsign-key "${key_fingerprint}"
|
|
|
|
|
|
|
|
arch-chroot /mnt bootctl install
|
|
|
|
|
|
|
|
arch-chroot /mnt useradd --create-home --user-group --shell /usr/bin/zsh --groups wheel,uucp,video,audio,storage,games,input "$user"
|
|
|
|
arch-chroot /mnt chsh -s /usr/bin/zsh
|
|
|
|
|
|
|
|
echo "$user:$password" | chpasswd --root /mnt
|
|
|
|
echo "root:$password" | chpasswd --root /mnt
|