2021-08-15 17:09:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e # Stop on Errors
|
|
|
|
|
2021-08-27 16:44:06 +00:00
|
|
|
scriptdir="$(dirname "$(readlink -f "$0")")"
|
|
|
|
|
2021-08-15 17:09:03 +00:00
|
|
|
function show_help() {
|
2021-09-17 14:19:24 +00:00
|
|
|
echo "$0 -d <device> -h <hostname> [options]"
|
2021-08-15 17:09:03 +00:00
|
|
|
echo " A Semi-Automatic Archlinux Install Script"
|
2021-08-15 17:19:55 +00:00
|
|
|
echo " -d <device> Device to Install to"
|
|
|
|
echo " -k <kernel> Kernel Name to Install (default: linux-zen)"
|
2022-09-01 19:10:46 +00:00
|
|
|
echo " -n <nm> Network Management: n NetworkMangager, m NetworkManager + ModemManager, s systemd-networkd (default: none)"
|
2021-08-15 17:19:55 +00:00
|
|
|
echo " -l <locale> Locale to use (default: de_DE)"
|
|
|
|
echo " -m <keymap> Console Keymap to use (default: de)"
|
|
|
|
echo " -t <timezone> Timezone to use (default: Europe/Berlin)"
|
2021-09-17 14:19:24 +00:00
|
|
|
echo " -h <hostname> Set the Target Hostname"
|
2021-12-18 20:22:37 +00:00
|
|
|
echo " -s <hddsize> Only use hddsize for the system partition"
|
2021-08-15 17:19:55 +00:00
|
|
|
echo " -b Set System Type to BIOS (default: UEFI)"
|
2021-09-17 14:08:20 +00:00
|
|
|
echo " -c Disable Encryption (default: enabled)"
|
2021-08-15 17:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
;;
|
2022-09-01 19:10:46 +00:00
|
|
|
3) echo "Installing systemd-networkd"
|
|
|
|
systemctl enable --root=/mnt systemd-networkd
|
|
|
|
;;
|
2021-08-15 17:09:03 +00:00
|
|
|
*) echo "No Network Management selected, not installing any" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
## Defaults
|
|
|
|
kernel="linux-zen"
|
|
|
|
locale="de_DE"
|
|
|
|
keymap="de"
|
2021-08-15 17:19:55 +00:00
|
|
|
timezone="Europe/Berlin"
|
|
|
|
systype="x86_64-efi"
|
2021-08-15 17:09:03 +00:00
|
|
|
network=0
|
2021-09-17 14:08:20 +00:00
|
|
|
encryption=1
|
2021-12-18 20:22:37 +00:00
|
|
|
hddsize="100%"
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
## Get CLI Options
|
2021-12-18 20:22:37 +00:00
|
|
|
while getopts 'k:d:n:m:l:h:s:t:bc?' flag; do
|
2021-08-15 17:09:03 +00:00
|
|
|
case "${flag}" in
|
|
|
|
k) kernel="${OPTARG}" ;;
|
|
|
|
n) case "${OPTARG}" in
|
|
|
|
n) network=1 ;;
|
|
|
|
m) network=2 ;;
|
2022-09-01 19:10:46 +00:00
|
|
|
s) network=3 ;;
|
2021-08-15 17:09:03 +00:00
|
|
|
*) exit_error "Unknown Network Type Selected, Aborting" ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
d) device="${OPTARG}" ;;
|
|
|
|
l) locale="${OPTARG}" ;;
|
|
|
|
m) keymap="${OPTARG}" ;;
|
2021-08-15 17:19:55 +00:00
|
|
|
t) timezone="${OPTARG}" ;;
|
|
|
|
b) systype="i386-pc" ;;
|
2021-09-17 14:14:31 +00:00
|
|
|
c) encryption=0 ;;
|
2021-08-15 17:09:03 +00:00
|
|
|
h) hostname="${OPTARG}" ;;
|
2021-12-18 20:22:37 +00:00
|
|
|
s) hddsize="${OPTARG}" ;;
|
2021-08-15 17:09:03 +00:00
|
|
|
?) 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}"
|
2021-08-15 17:19:55 +00:00
|
|
|
if [[ "${systype}" == "x86_64-efi" ]]; then
|
2021-08-15 17:09:03 +00:00
|
|
|
parted -s "$device" \
|
2021-08-22 14:20:02 +00:00
|
|
|
mklabel gpt \
|
2021-08-15 17:09:03 +00:00
|
|
|
mkpart ESP fat32 1MiB 513MiB \
|
2021-09-17 14:19:24 +00:00
|
|
|
set 1 esp on \
|
2021-12-18 20:22:37 +00:00
|
|
|
mkpart arch 514MiB ${hddsize}
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
part_esp="/dev/disk/by-partlabel/ESP"
|
2021-09-17 14:08:20 +00:00
|
|
|
part_root="/dev/disk/by-partlabel/arch"
|
2021-08-15 17:19:55 +00:00
|
|
|
extrapkgs="efibootmgr"
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
partprobe "${device}"
|
2021-09-17 15:09:10 +00:00
|
|
|
sleep 2
|
2021-08-15 17:09:03 +00:00
|
|
|
mkfs.fat -F32 -n EFI "${part_esp}"
|
|
|
|
else
|
|
|
|
parted -s "$device" \
|
2021-08-22 14:20:02 +00:00
|
|
|
mklabel gpt \
|
|
|
|
mkpart grub 1MiB 2MiB \
|
2021-09-17 14:19:24 +00:00
|
|
|
set 1 bios_grub on \
|
2021-09-17 14:08:20 +00:00
|
|
|
mkpart arch 2MiB 100%
|
2021-08-15 17:09:03 +00:00
|
|
|
|
2021-09-17 15:09:10 +00:00
|
|
|
partprobe "${device}"
|
|
|
|
sleep 2
|
2021-09-17 14:08:20 +00:00
|
|
|
part_root="/dev/disk/by-partlabel/arch"
|
2021-08-15 17:09:03 +00:00
|
|
|
fi
|
|
|
|
|
2021-09-17 14:08:20 +00:00
|
|
|
if [ $encryption -eq 1 ]; then
|
2021-09-17 14:56:55 +00:00
|
|
|
echo "Creating Encrypted Root Partition"
|
2021-09-17 14:51:57 +00:00
|
|
|
read -s -r -p "Please Enter the Encryption Passhprase: " lukspw
|
2021-09-17 14:59:23 +00:00
|
|
|
echo ""
|
2021-09-17 14:51:57 +00:00
|
|
|
read -s -r -p "Please Verify the Encryption Passhprase: " lukspw2
|
2021-09-17 15:09:10 +00:00
|
|
|
echo ""
|
2021-09-17 14:51:57 +00:00
|
|
|
[ "$lukspw" != "$lukspw2" ] && echo "Passphrases don't match!" && exit 1
|
|
|
|
echo -n "$lukspw" | cryptsetup luksFormat --type luks1 --cipher aes-xts-plain64 --hash sha512 --key-size 512 "${part_root}" -
|
|
|
|
echo -n "$lukspw" | cryptsetup open --key-file - "${part_root}" "cryptroot"
|
2021-09-17 15:09:10 +00:00
|
|
|
unset lukspw lukspw2
|
2021-09-17 14:08:20 +00:00
|
|
|
root_dev="/dev/mapper/cryptroot"
|
|
|
|
else
|
|
|
|
root_dev="${part_root}"
|
|
|
|
fi
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
echo "Creating BTRFS Filesystem"
|
2021-09-17 15:10:26 +00:00
|
|
|
mkfs.btrfs -f -L archlinux "${root_dev}"
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
echo "Creating BRTFS Subvolumes"
|
2021-09-17 14:08:20 +00:00
|
|
|
mount "${root_dev}" /mnt
|
2021-09-17 14:23:48 +00:00
|
|
|
for sv in "@" "@home" "@data" "@snapshots" "@log" "@pkg" "@machines" "@portables"; do
|
2021-08-15 17:09:03 +00:00
|
|
|
btrfs su cr "/mnt/${sv}"
|
|
|
|
done
|
|
|
|
|
2022-01-21 12:58:25 +00:00
|
|
|
btrfs_opts="ssd,noatime,compress=zstd,autodefrag,discard=async"
|
|
|
|
|
2021-08-15 17:09:03 +00:00
|
|
|
umount /mnt
|
|
|
|
echo "Mounting System Subvolumes"
|
2022-01-21 12:58:25 +00:00
|
|
|
mount -o ${btrfs_opts},subvol=@ "${root_dev}" /mnt
|
2021-08-15 17:09:03 +00:00
|
|
|
mkdir -p /mnt/{home,data,.snapshots,var/log,var/cache/pacman/pkg,var/lib/machines,var/lib/portables}
|
2022-01-21 12:58:25 +00:00
|
|
|
mount -o ${btrfs_opts},subvol=@home "${root_dev}" /mnt/home
|
|
|
|
mount -o ${btrfs_opts},subvol=@data "${root_dev}" /mnt/data
|
|
|
|
mount -o ${btrfs_opts},subvol=@snapshots "${root_dev}" /mnt/.snapshots
|
|
|
|
mount -o ${btrfs_opts},subvol=@log "${root_dev}" /mnt/var/log
|
|
|
|
mount -o ${btrfs_opts},subvol=@pkg "${root_dev}" /mnt/var/cache/pacman/pkg
|
|
|
|
mount -o ${btrfs_opts},subvol=@machines "${root_dev}" /mnt/var/lib/machines
|
|
|
|
mount -o ${btrfs_opts},subvol=@portables "${root_dev}" /mnt/var/lib/portables
|
2021-08-15 17:09:03 +00:00
|
|
|
chattr +C /mnt/var/log /mnt/var/cache/pacman/pkg
|
2021-08-15 17:19:55 +00:00
|
|
|
if [[ "${systype}" == "x86_64-efi" ]]; then
|
2021-09-17 14:59:23 +00:00
|
|
|
mkdir -p /mnt/boot/efi
|
2021-08-15 17:09:03 +00:00
|
|
|
mount "${part_esp}" /mnt/boot/efi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Installing Base System Packages"
|
2021-12-31 11:14:51 +00:00
|
|
|
pacstrap /mnt base $kernel $microcode $firmware $extrapkgs btrfs-progs grub grub-btrfs snapper vim git tmux htop iftop iotop tcpdump mtr rsync wget which zip lsof strace openssh inetutils bc man-pages sudo
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
echo "Creating Basic Config Files"
|
2021-09-17 14:30:30 +00:00
|
|
|
genfstab -U /mnt | sed -e 's/suvolid=[0-9]*,//g' >> /mnt/etc/fstab
|
2021-08-15 17:09:03 +00:00
|
|
|
|
|
|
|
echo "${hostname}" >> /mnt/etc/hostname
|
|
|
|
cat > /mnt/etc/hosts <<EOF
|
|
|
|
127.0.0.1 localhost
|
|
|
|
::1 localhost
|
|
|
|
127.0.1.1 ${hostname}.localdomain ${hostname}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "$locale.UTF-8 UTF-8" > /mnt/etc/locale.gen
|
|
|
|
echo "LANG=$locale.UTF-8" > /mnt/etc/locale.conf
|
|
|
|
echo "KEYMAP=$keymap" > /mnt/etc/vconsole.conf
|
2021-08-27 16:44:06 +00:00
|
|
|
|
|
|
|
if [ -d "${scriptdir}/etc" ]; then
|
|
|
|
cp -r "${scriptdir}/etc/"* /mnt/etc/
|
|
|
|
fi
|
2021-09-17 14:08:20 +00:00
|
|
|
|
|
|
|
sed -i 's/#COMPRESSION="zstd"/COMPRESSION="zstd"/g' /mnt/etc/mkinitcpio.conf
|
|
|
|
if [ $encryption -eq 1 ]; then
|
2021-09-17 14:36:01 +00:00
|
|
|
sed -i 's/HOOKS=.*/HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)/g' /mnt/etc/mkinitcpio.conf
|
2021-09-17 14:08:20 +00:00
|
|
|
|
|
|
|
UUID=$(blkid ${part_root} | cut -f2 -d'"')
|
2021-09-17 14:38:45 +00:00
|
|
|
sed -i 's/#GRUB_ENABLE_CRYPTODISK=y/GRUB_ENABLE_CRYPTODISK=y/g' /mnt/etc/default/grub
|
2021-09-17 14:08:20 +00:00
|
|
|
sed -i "s#GRUB_CMDLINE_LINUX_DEFAULT=.*#GRUB_CMDLINE_LINUX_DEFAULT=\"loglevel=3 quiet cryptdevice=UUID=$UUID:cryptroot:allow-discards root=${root_dev}\"#g" /mnt/etc/default/grub
|
|
|
|
else
|
2021-09-17 14:36:01 +00:00
|
|
|
sed -i 's/HOOKS=.*/HOOKS=(base udev autodetect keyboard keymap modconf block filesystems fsck)/g' /mnt/etc/mkinitcpio.conf
|
2021-09-17 14:08:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
arch-chroot /mnt /bin/bash -e <<EOF
|
|
|
|
|
|
|
|
# Timezone and RTC Setup
|
|
|
|
ln -sfn /usr/share/zoneinfo/$timezone /etc/localtime
|
|
|
|
hwclock --systohc
|
|
|
|
|
|
|
|
# Locales
|
|
|
|
echo "Generating Locales"
|
|
|
|
locale-gen
|
|
|
|
|
|
|
|
# Initramfs
|
|
|
|
echo "Generating Initramfs"
|
|
|
|
mkinitcpio -P
|
|
|
|
|
2021-12-18 21:22:56 +00:00
|
|
|
# My Repository
|
|
|
|
pacman-key -r 805517CC
|
|
|
|
pacman-key --lsign-key 805517CC
|
|
|
|
echo '[seiichiro]' >> /etc/pacman.conf
|
|
|
|
echo 'SigLevel = Required DatabaseOptional TrustedOnly' >> /etc/pacman.conf
|
2021-12-31 11:14:51 +00:00
|
|
|
echo 'Server = http://www.seiichiro0185.org/repo/\$arch' >> /etc/pacman.conf
|
2021-12-18 21:22:56 +00:00
|
|
|
|
2021-09-17 14:08:20 +00:00
|
|
|
echo "Setting up Snapper"
|
|
|
|
umount /.snapshots
|
|
|
|
rm -r /.snapshots
|
|
|
|
snapper --no-dbus -c root create-config /
|
|
|
|
btrfs subvolume delete /.snapshots &>/dev/null
|
|
|
|
mkdir /.snapshots
|
|
|
|
mount -a
|
|
|
|
chmod 750 /.snapshots
|
|
|
|
|
|
|
|
echo "Installing Grub"
|
|
|
|
if [ "${systype}" == "x86_64-efi" ]; then
|
|
|
|
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB &>/dev/null
|
|
|
|
else
|
|
|
|
grub-install --target=i386-pc ${device}
|
|
|
|
fi
|
|
|
|
grub-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "Please set a Password for root"
|
|
|
|
arch-chroot /mnt /bin/passwd
|
|
|
|
|
2021-09-17 15:23:53 +00:00
|
|
|
install_network ${network}
|
|
|
|
|
|
|
|
echo "Enabling Services"
|
2021-09-17 14:08:20 +00:00
|
|
|
systemctl enable sshd grub-btrfs.path --root /mnt
|
2021-09-17 14:51:57 +00:00
|
|
|
|
|
|
|
echo -e "\n\nInstallation finished, you may further customize it in /mnt or reboot now"
|