diff --git a/archinstall.sh b/archinstall.sh new file mode 100755 index 0000000..52c26aa --- /dev/null +++ b/archinstall.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +set -e # Stop on Errors + +function show_help() { + echo "$0 -d [options]" + echo " A Semi-Automatic Archlinux Install Script" + echo " -d Device to Install to" + echo " -k Kernel Name to Install (default: linux-zen)" + echo " -n Network Management: n NetworkMangager, m NetworkManager + ModemManager, (default: none)" + echo " -l Locale to use (default: de_DE)" + echo " -m Console Keymap to use (default: de)" + echo " -b Set System Type to BIOS (default: UEFI)" +} + +function exit_error() { + echo "$1" + show_help + exit 1 +} + +function install_network() { + local option=$1 + case $option in + 1) echo "Installing NetworkManager" + pacstrap /mnt networkmanager + systemctl enable --root=/mnt NetworkManager + ;; + 2) echo "Installing NetworkManager an ModemManager" + pacstrap /mnt networkmanager modemmanager + systemctl enable --root=/mnt NetworkManager ModemManager + ;; + *) echo "No Network Management selected, not installing any" ;; + esac +} + +## Defaults +kernel="linux-zen" +locale="de_DE" +keymap="de" +systype="UEFI" +network=0 + +## Get CLI Options +while getopts 'k:d:n:m:l:h:b?' flag; do + case "${flag}" in + k) kernel="${OPTARG}" ;; + n) case "${OPTARG}" in + n) network=1 ;; + m) network=2 ;; + *) exit_error "Unknown Network Type Selected, Aborting" ;; + esac + ;; + d) device="${OPTARG}" ;; + l) locale="${OPTARG}" ;; + m) keymap="${OPTARG}" ;; + b) systype="BIOS" ;; + h) hostname="${OPTARG}" ;; + ?) show_help ;; + *) show_help ;; + esac +done + +if [[ -z "$device" ]]; then + exit_error "No Installation Device Selected, Aborting" +fi + +if [[ -z "$hostname" ]]; then + exit_error "No Hostname given, Aborting" +fi + +## Confirm installation +read -r -p "This will delete the current partition table on $device. Do you agree [y/N]? " response +response=${response,,} +if [[ "$response" =~ ^(yes|y)$ ]]; then + wipefs -af "$device" &>/dev/null + sgdisk -Zo "$device" &>/dev/null +else + exit_error "Installation Aborted by User" +fi + +## Select Microcode +if [[ "$(systemd-detect-virt)" == "none" ]]; then + if [[ "$(grep vendor_id /proc/cpuinfo)" == *"AuthenticAMD"* ]]; then + microcode=amd-ucode + else + microcode=intel-ucode + fi + firmware=linux-firmware +fi + +echo "Paritioning Disk ${device}" +if [[ "${systype}" == "UEFI" ]]; then + parted -s "$device" \ + mkpart ESP fat32 1MiB 513MiB \ + set esp 1 on mkpart \ + mkpart cryptroot 512MiB 100% + + part_esp="/dev/disk/by-partlabel/ESP" + part_root="/dev/disk/by-partlabel/cryptroot" + + partprobe "${device}" + mkfs.fat -F32 -n EFI "${part_esp}" +else + parted -s "$device" \ + mkpart grub fat32 1MiB 2MiB \ + set esp 1 on mkpart \ + mkpart cryptroot 2MiB 100% + + part_root="/dev/disk/by-partlabel/cryptroot" +fi + +echo "Creating Encrypted Root Partition" +cryptsetup luksFormat --type luks1 --cipher aes-xts-plain64 --hash sha512 --keysize 512 "${part_root}" +cryptsetup open "${part_root}" "cryptroot" +crypt_root="/dev/mapper/cryptroot" + +echo "Creating BTRFS Filesystem" +mkfs.btrfs -L root "$crypt_root" + +echo "Creating BRTFS Subvolumes" +mount "${crypt_root}" /mnt +for sv in "@" "@home" "@data" "@snapshot" "@log" "@pkg" "@machines" "@portables"; do + btrfs su cr "/mnt/${sv}" +done + +umount /mnt +echo "Mounting System Subvolumes" +mount -o ssd,noatime,space_cache,compress=zstd,subvol=@ "${crypt_root}" /mnt +mkdir -p /mnt/{home,data,.snapshots,var/log,var/cache/pacman/pkg,var/lib/machines,var/lib/portables} +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@home "${crypt_root}" /mnt/home +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@data "${crypt_root}" /mnt/data +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@snapshots "${crypt_root}" /mnt/.snapshots +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@log "${crypt_root}" /mnt/var/log +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@pkg "${crypt_root}" /mnt/var/cache/pacman/pkg +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@machines "${crypt_root}" /mnt/var/lib/machines +mount -o ssd,noatime,space_cache.compress=zstd,autodefrag,discard=async,subvol=@portables "${crypt_root}" /mnt/var/lib/portables +chattr +C /mnt/var/log /mnt/var/cache/pacman/pkg +if [[ "${systype}" == "UEFI" ]]; then + mount "${part_esp}" /mnt/boot/efi +fi + +echo "Installing Base System Packages" +pacstrap /mnt base $kernel $microcode $firmware btrfs-progs grub grub-btrfs snapper vim git tmux htop lsof strace openssh + +echo "Creating Basic Config Files" +genfstab -U /mnt | sed -e 's#suvolid=.*,##g;s#subvol=/.*##g' >> /mnt/etc/fstab + +echo "${hostname}" >> /mnt/etc/hostname +cat > /mnt/etc/hosts < /mnt/etc/locale.gen +echo "LANG=$locale.UTF-8" > /mnt/etc/locale.conf +echo "KEYMAP=$keymap" > /mnt/etc/vconsole.conf