#!/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=d:t:l:h:u:s: 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" d="CHANGEME" # Device that shoud be partitioned e.g. "/dev/sda" t="CHANGEME" # Your timezone according to /usr/share/zoneinfo/ e.g. "/usr/share/zoneinfo/Europ/Berlin" l="CHANGEME" # Your locale according to /etc/locale.gen e.g. "en_US.UTF-8 UTF-8" h="CHANGEME" # Name for your machine e.g. "ArchLinux" u="CHANGEME" # Your username e.g. "foo" s="CHANGEME" # Name of the sudogrp CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" while true; do case "$1" in -d|--device) d="$2" shift 2 ;; -t|--timezone) t="$2" shift 2 ;; -l|--locale) l="$2" shift 2 ;; -h|--hostname) h="$2" shift 2 ;; -u|--username) u="$2" shift 2 ;; -s|--sudogrp) s="$2" shift 2 ;; --help) echo " Usage: ./install.sh -d [DEVICE] -t [/usr/share/zoneinfo/REGION/CITY] -l [LOCALE] -h [HOSTNAME] -u [USER] -s [SUDO] A small script to automate my archlinux configuration. 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 here. " exit 0 ;; *) echo "Programming error" exit 3 ;; esac done # partition 1: 1MiB -> 500MiB FAT32 # partition 2: 500MiB -> 3GiB swap # partition 3: 3GiB -> .. ext4 parted $d 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 "$d\p1" ]; then bootpart=$d\p1 swappart=$d\p2 rootpart=$d\p3 else bootpart=$d\1 swappart=$d\2 rootpart=$d\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 $t-l $l-h $h-u $u-s $s sed -i "s/arch-reboot.sh/\0 -u $u-s $s/" /mnt/etc/systemd/system/march.service umount $bootpart swapoff $swappart umount $cryptroot cryptsetup close $cryptroot shutdown -r now