better installer

This commit is contained in:
Maximilian Keßler 2022-07-25 21:18:29 +02:00
parent ff893df5ab
commit 91488dc902

View file

@ -1,13 +1,18 @@
#!/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
# This script does not work out of the box,
# it is run in the custom arch installer built via
# https://gitlab.com/kesslermaximilian/arch-pkgs
#
# For the exact requirements, see the README at the git repository
#
set -uo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
REPO_URL="https://mkessler-arch.maximilian-kessler.de"
reflector
# test internet connectivity
ping -c 1 -W 2 archlinux.org || (echo "You don't seem to be connected to the internet, aborting." && exit 1)
### Get infomation from user ###
hostname=$(dialog --stdout --inputbox "Enter hostname" 0 0) || exit 1
@ -18,22 +23,33 @@ 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
disk_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
: ${disk_password:?"password cannot be empty"}
disk_password2=$(dialog --stdout --passwordbox "Enter disk encryption password again" 0 0) || exit 1
clear
[[ "$password" == "$password2" ]] || ( echo "Passwords did not match"; exit 1; )
[[ "$disk_password" == "$disk_password2" ]] || ( echo "Passwords did not match"; exit 1; )
user_password=$(dialog --stdout --passwordbox "Enter user (and root) password" 0 0) || exit 1
clear
: ${user_password:?"password cannot be empty"}
user_password2=$(dialog --stdout --passwordbox "Enter user (and root) password again" 0 0) || exit 1
clear
[[ "$user_password" == "$user_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
#### Got all user input, start with installation now
# set up all further variables
REPO_URL="https://mkessler-arch.maximilian-kessler.de"
cryptlvm="cryptlvm"
vlgrp="vlgrp"
key_fingerprint="B419CDA93D7544F8214B3216A23D90C2433DAFBC"
mapped_device="/dev/mapper/${cryptlvm}"
@ -51,6 +67,10 @@ exec 2> >(tee "stderr.log")
timedatectl set-ntp true
### update mirrors
echo "Running reflector to update mirrors"
reflector
### Setup the disk and partitions ###
ram_size=$(free --mebi | awk '/Mem:/ {print $2}')
swap_size=$((ram_size + 1024))M # 1 Gigabyte more swap space than available ram
@ -78,8 +98,8 @@ wipefs "${part_boot}"
wipefs "${part_luks}"
echo "Setting up luks on ${part_luks}"
echo "${password}" | cryptsetup luksFormat -q "${part_luks}"
echo "${password}" | cryptsetup open "${part_luks}" "${cryptlvm}"
echo "${disk_password}" | cryptsetup luksFormat -q "${part_luks}"
echo "${disk_password}" | cryptsetup open "${part_luks}" "${cryptlvm}"
pvcreate "${mapped_device}"
vgcreate "${vlgrp}" "${mapped_device}"
@ -97,26 +117,20 @@ mount "${part_home}" /mnt/home --mkdir
mount "${part_boot}" /mnt/boot --mkdir
swapon "${part_swap}"
echo "Finished setting up luks, lvm and mounted all partitions"
sleep 1
echo "Retrivieng signing key for mkessler-arch repository..."
read -p "Continue with installing packages into /mnt? [y/n]? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
### Install and configure the basic system ###
# Receive and lsign signing key of custom repo
pacman-key --recv-keys keyid "${key_fingerprint}"
pacman-key --lsign-key "${key_fingerprint}"
echo "Installing packages into /mnt"
pacstrap /mnt mkessler-desktop
echo "Generating fstab file"
genfstab -U /mnt >> /mnt/etc/fstab
echo "Setting hostname"
echo "${hostname}" > /mnt/etc/hostname
echo "Configuring mkessler-arch repo in installed system"
### Set up custom repo on installed system as well
cat >>/mnt/etc/pacman.conf <<EOF
@ -125,17 +139,26 @@ cat >>/mnt/etc/pacman.conf <<EOF
Server = $REPO_URL
EOF
echo "Finished installation"
echo "Generating fstab file"
genfstab -U /mnt >> /mnt/etc/fstab
exit 0
arch-chroot /mnt pacman-key --recv-keys keyid "${key_fingerprint}"
arch-chroot /mnt pacman-key --lsign-key "${key_fingerprint}"
arch-chroot /mnt bootctl install
echo "Setting hostname"
echo "${hostname}" > /mnt/etc/hostname
echo "Adding user ${user} in new system"
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
echo "${user}:${user_password}" | chpasswd --root /mnt
echo "root:${user_password}" | chpasswd --root /mnt
cat <<EOF
---------------------
Installed basic packages and setup in /mnt
Manual configuration is still needed for the following
- edit /etc/mkinitcpio.conf and generate initcpio
- install grub, configure grub parameters, generate main grub.cfg
---------------------
EOF