Files
march/install.sh
2020-05-23 18:25:34 +02:00

128 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo "I'm sorry, `getopt --test` failed in this environment."
exit 1
fi
OPTIONS=dtlhush
LONGOPTS=device,timezone,locale,hostname,username,sudogrp,help
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
exit 2
fi
eval set -- "$PARSED"
device="CHANGEME" # Device that shoud be partitioned e.g. "/dev/sda"
timezone="CHANGEME" # Your timezone according to /usr/share/zoneinfo/ e.g. "/usr/share/zoneinfo/EUROPE/Berlin"
locale="CHANGEME" # Your locale according to /etc/locale.gen e.g. "en_US.UTF-8 UTF-8"
hostname="CHANGEME" # Name for your machine e.g. "ArchLinux"
username="CHANGEME" # Your username e.g. "foo"
sudogrp="CHANGEME" # Name of the sudogrp
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
while true; do
case "$!" in
-d|--device)
device="$2"
shift 2
;;
-t|--timezone)
timezone="$2"
shift 2
;;
-l|--locale)
locale="$2"
shift 2
;;
-h|--hostname)
hostname="$2"
shift 2
;;
-u|--username)
username="$2"
shift 2
;;
-s|--sudogrp)
sudogrp="$2"
shift 2
;;
-h|--help)
description=$(< tail -n +3 $CWD/README.md)
echo "
Usage: ./install.sh -d [DEVICE] -t [/usr/share/zoneinfo/REGION/CITY] -l [LOCALE] -h [HOSTNAME] -u [USER] -s [SUDO]
Mandatory arguments:
-d | --device Device that shoud be partitioned e.g. "/dev/sda"
-t | --timezone Your timezone according to /usr/share/zoneinfo/ e.g. "/usr/share/zoneinfo/EUROPE/Berlin"
-l | --locale Your locale according to /etc/locale.gen e.g. "en_US.UTF-8 UTF-8"
-h | --hostname Name for your machine e.g. "ArchLinux"
-u | --username Your username e.g. "foo"
-s | --sudogrp Name of the sudogrp
-h | --help This ehre.
"
exit 0
;;
*)
echo "Programming error"
exit 3
;;
esac
done
# partition 1: 1MiB -> 500MiB FAT32
# partition 2: 500MiB -> 3GiB swap
# partition 3: 3GiB -> .. ext4
parted $device mklabel gpt mkpart primary fat32 1MiB 512 mkpart primary linux-swap 500MiB 3GiB mkpart primary ext4 3GiB 100% set 1 esp on -s
if [ -b "$device\p1" ]; then
bootpart=$device\p1
swappart=$device\p2
rootpart=$device\p3
else
bootpart=$device\1
swappart=$device\2
rootpart=$device\3
fi
mkfs.vfat $bootpart
mkswap $swappart
swapon $swappart
# LUKS
cryptsetup -y luksFormat --type luks2 $rootpart
cryptsetup open $rootpart cryptroot
cryptroot=/dev/mapper/cryptroot
mkfs.ext4 $cryptroot
mount $cryptroot /mnt
mkdir /mnt/boot
mount $bootpart /mnt/boot
pacstrap /mnt base base-devel linux linux-firmware
genfstab -U /mnt >> /mnt/etc/fstab
cp $CWD/etc/systemd/system/march.service /mnt/etc/systemd/system/march.service
cp $CWD/root/march-chroot.sh /mnt/root/arch-chroot.sh
cp $CWD/root/march-reboot.sh /mnt/root/arch-reboot.sh
chmod +x /mnt/root/arch-chroot.sh
chmod +x /mnt/root/arch-reboot.sh
arch-chroot /mnt /root/march-chroot.sh -t $timezone -l $locale -h $hostname -u $username -s $sudogrp
sed -i "s/arch-reboot.sh/\0 -u $username -s $sudogrp/" /mnt/etc/systemd/system/march.service
umount $bootpart
swapoff $swappart
umount $cryptroot
cryptsetup close $cryptroot
shutdown -r now