<file_sep>#!/bin/sh

pacman -Syyu --noconfirm
pacman -S linux linux-firmware --noconfirm
systemctl disable netctl || /bin/true
pacman -Rns --noconfirm netctl || /bin/true
pacman -S --noconfirm networkmanager
systemctl enable NetworkManager
echo 'HOOKS=(base systemd autodetect sd-vconsole modconf block keyboard keymap sd-encrypt sd-lvm2 fsck filesystems' >> /etc/mkinitcpio.conf
rot=$(cryptsetup status luks|grep device|awk '{print $2}')
cryptrot="$(blkid $rot|awk '{print $2}'|sed 's/^.\{6\}//'|sed 's/.\{1\}$//')"
cat <<EOF > /boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options rd.luks.uuid=${cryptrot} rd.luks.options=discard root=/dev/mapper/vg0-root quiet loglevel=3 rd.udev.log_priority=3 rd.systemd.show_status=auto vga=current fan_control=1
EOF

mkinitcpio -p linux
bootctl --path=/boot/ install
echo 'MAKEFLAGS="-j$(nproc)"' >> /etc/makepkg.conf

ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
hwclock --systohc

echo 'store /dev/md127 none luks,timeout=180' >> /etc/crypttab
echo '/dev/mapper/vg1-store /store ext4 rw,relatime,noauto,x-systemd.automount 0 2' >> /etc/fstab
<file_sep># Installtion notes

Previously, I had planned to make a modular metadistribution for Arch. Trying to do this taught me a few things:
- Automating an install is not always desirable.
- It is rare that I will not want to change something by hand that is best done early in the setup process. (Ie. I would be writing a script for other, hypothetical people; something I have no current interest in doing.)
- I do not often do installs at the moment. I have no need for a quick setup for remote machines. 
- NixOS offers a good solution for automating server installs; it also lacks the rolling release issues associated with Arch. (Though, the install is a lot less minimal than a barebones Arch install.)
- I actually enjoy installing Arch, as it offers some moments for reflection on my system.
<file_sep>#!/bin/sh
# License: MIT

set -uo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
MIRRORLIST_URL="https://www.archlinux.org/mirrorlist/?country=GB&protocol=https&use_mirror_status=on"

pacman -Sy --noconfirm pacman-contrib dialog archlinux-keyring
pacman-key --refresh-keys

curl -s "$MIRRORLIST_URL" | \
	sed -e 's/^#Server/Server/' -e '/^#/d' | \
	rankmirrors -n 5 - > /etc/pacman.d/mirrorlist

hostname=$(dialog --stdout --inputbox "Enter hostname" 0 0) || exit 1
clear
: ${hostname:?"hostname cannot be empty"}

user=$(dialog --stdout --inputbox "Enter admin username" 0 0) || exit 1
clear
: ${user:?"user cannot be empty"}

password=$(dialog --stdout --passwordbox "Enter admin password" 0 0) || exit 1
clear
: ${password:?"password <PASSWORD>"}
password2=$(dialog --stdout --passwordbox "Enter again" 0 0) || exit 1
clear
[[ "$password" == "$<PASSWORD>" ]] || ( echo "Passwords did not match"; exit 1; )
clear

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

timedatectl set-ntp true

umount --force -R /mnt || /bin/true

wipefs -af ${device}
wipefs -f -a ${device}
dd if=/dev/zero of=${device} bs=1M count=1024

parted --script "${device}" mklabel msdos \
	mkpart primary ext4 1Mib 98% \
    mkpart primary ext4 98% 100% \
	set 2 boot on \

part_boot="$(ls ${device}* | grep -E "^${device}p?2$")"
part_crypt="$(ls ${device}* | grep -E "^${device}p?1$")"

wipefs "${part_boot}"
wipefs "${part_crypt}"

mkfs.ext4 "${part_boot}"

cryptsetup -c aes-xts-plain64 -y --use-random luksFormat "${part_crypt}"

cryptsetup luksOpen "${part_crypt}" luks

pvcreate /dev/mapper/luks
vgcreate vg0 /dev/mapper/luks
lvcreate --size 6G vg0 --name swap
lvcreate -l +100%FREE vg0 --name root

mkswap /dev/mapper/vg0-swap

mkfs.ext4 /dev/mapper/vg0-root

swapon /dev/mapper/vg0-swap
mount /dev/mapper/vg0-root /mnt
mkdir /mnt/boot
mount "${part_boot}" /mnt/boot
#mkdir -p /mnt/boot/loader/entries

pacman -Syy
pacstrap /mnt base base-devel mkinitcpio lvm2 sudo intel-ucode
genfstab -pU /mnt >> /mnt/etc/fstab
echo "${hostname}" > /mnt/etc/hostname
cat <<EOF > /mnt/etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 $(echo $hostname).local $(echo $hostname)
EOF
mkdir /mnt/scripts &>/dev/null
cp *.sh /mnt/scripts &>/dev/null
cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/

echo "LANG=en_GB.UTF-8" > /mnt/etc/locale.conf
echo "en_GB.UTF-8 UTF-8" > /mnt/etc/locale.gen
echo "en_GB ISO-8859-1" > /mnt/etc/locale.gen

arch-chroot /mnt useradd -mU -s /usr/bin/bash -G wheel "$user"
echo "$user:$password" | chpasswd --root /mnt
echo "root:$password" | chpasswd --root /mnt
echo "$user ALL=(ALL:ALL) ALL' >> /etc/sudoers"

arch-chroot /mnt /scripts/chrooted.sh

<file_sep>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

exec 1> >(tee "stdout.log")
exec 2> >(tee "stderr.log")

timedatectl set-ntp true

parted --script "${device}" --mklabel gpt \
	mkpart ESP fat32 1Mib 129Mib \
	set 1 boot on \
	mkpart primary ext4 129MIB 100%

part_boot="$(ls ${device}* | grep -E "^${device}p?1$")"
part_crypt="$(ls ${device}* | grep -E "^${device}p?2$")"

wipefs "${part_boot}"
wipefs "${part_crypt}"

mkfs.vfat -F32 "${part_boot}"

cryptsetup -c aes-xts-plain64 -y --use-random luksFormat "${part_crypt}"

cryptsetup luksOpen "${part_crypt}" luks

pvcreate /dev/mapper/luks
vgcreate vg0 /dev/mapper/luks
lvcreate --size 6G vg0 --name swap
lvcreate -l +100%FREE vg0 --name root

mkswap /dev/mapper/vg0-swap

mkfs.ext4 /dev/mapper/vg0-root

swapon /dev/mapper/vg0-swap
mount /dev/mapper/vg0-root /mnt
mkdir /mnt/boot
mount "${part_boot}" /mnt/boot

pacstrap /mnt base base-devel git nvim linux-headers
genfstab -t PARTUUID /mnt >> /mnt/etc/fstab
echo "${hostname}" > /mnt/etc/hostname

arch-chroot /mnt bootctl install

cat <<EOF > /mnt/boot/loader/loader.conf
default arch
EOF

cat <<EOF > /mnt/boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=PARTUUID=$(blkid -s PARTUUID -o value "$part_root") rw
EOF

echo "LANG=en_GB.UTF-8" > /mnt/etc/locale.conf

arch-chroot /mnt useradd -mU -s /usr/bin/bash -G wheel "$user"

echo "$user:$password" | chpasswd --root /mnt
echo "$root:$password" | chpasswd --root /mnt

# below assumes admin user is setup
dialog --infobox "Refreshing Arch keyring..." 4 40
pacman --noconfirm -Sy archlinux-keyring >/dev/null 2>&1
dialog --infobox "Installing /`basedevel\` and \`git\`." 5 70
pacman --noconfirm --needed -S base-devel git >/dev/null 2>&1
[ -f /etc/sudoers.pacnew ] && cp /etc/sudoers.pacnew /etc/sudoers
newperms "%wheel ALL=(ALL) NOPASSWD: ALL"
grep "^Color" /etc/pacman.conf >/dev/null || sed -i "s/^#Color/Color/" /etc/pacman.conf
grep "ILoveCandy" /etc/pacman.conf >/dev/null || sed -i "/#VerbosePkgLists/a ILoveCandy" /etc/pacman.conf
sed -i "s/-j2/-j$(nproc)/;s/^#MAKEFLAGS/MAKEFLAGS/" /etc/makepkg.conf
[ -z "$aurhelper" ] && aurhelper="yay"
[ -f "/usr/bin/$aurhelper" ] || (
dialog --infobox "Installing \"$aurhelper\"..." 4 50
cd /tmp || exit
rm -rf /tmp/"$aurhelper"*
curl -s0 https://aur.archlinux.org/cgit/aur.git/snapshot/"$aurhelper".tar.gz &&
	sudo -u "$name" tar -xvf "$aurhelper".tar.gz >/dev/null 2>&1 &&
	cd "$aurhelper" &&
	sudo -u "$name" makepkg --noconfirm -si >/dev/null 2>&1
cd /tmp || return


<file_sep>mount /dev/mapper/vg0-root /mnt/gentoo
ntpd -q -g
cd /mnt/gentoo
echo "If wget fails, go to lynx https://www.gentoo.org/downloads/mirrors/"
wget https://mirror.bytemark.co.uk/gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-20191013T214502Z.tar.xz # this WILL change
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
nano -w /mnt/gentoo/etc/portage/make.conf

