#!/usr/bin/env bash # shellcheck disable=SC1091,SC2001 # shellcheck source=./setup.conf CONFIG_FILE=$(pwd)/setup.conf if [[ -f "$CONFIG_FILE" ]]; then source "$CONFIG_FILE" else echo "Missing file: setup.conf" exit 1 fi make_boot() { if [[ "$UEFI" -eq 1 ]]; then mkfs.vfat -F32 -n "$BOOT" "$PART1" fi } something_failed() { echo "Something is not right. Exiting." exit 1 } do_btrfs() { mkfs.btrfs -L "$1" "$2" -f mount -t btrfs "$2" "$MOUNTPOINT" title "Creating subvolumes and directories" for x in "${SUBVOLUMES[@]}"; do btrfs subvolume create "$MOUNTPOINT"/"${x}" done umount /mnt mount -o "$MOUNTOPTION",subvol=@ "$2" "$MOUNTPOINT" for z in "${SUBVOLUMES[@]:1}"; do w="$(echo "$z" | sed 's/@//g')" mkdir /mnt/"${w}" mount -o "$MOUNTOPTION",subvol="${z}" "$2" "$MOUNTPOINT"/"${w}" done } do_format() { mkfs."$FS" "$1" \ "$([[ $FS == xfs || $FS == btrfs || $FS == reiserfs ]] && echo "-f")" \ "$([[ $FS == vfat ]] && echo "-F32")" \ "$([[ $FS == ext4 ]] && echo "-E discard -F")" } do_lvm() { i=0 while [[ "$i" -le "${#LVM_PART_NUM[@]}" ]]; do if [[ "$i" -eq "${#LVM_PART_NUM[@]}" ]]; then lvcreate -l 100%FREE "$LVM_VG" -n "${LVM_NAMES[$i]}" else lvcreate -L "${LVM_SIZES[$i]}" "$LVM_VG" -n "${LVM_NAMES[$i]}" fi i=$((i + 1)) done } lvm_mount() { vgchange -ay &>/dev/null i=0 if [[ "$LUKS" -eq 1 ]]; then LVM_PATH=/dev/mapper/ else LVM_PATH=/dev/"$LVM_VG"/ fi while [[ "$i" -le "${#LVM_PART_NUM[@]}" ]]; do lvchange -ay "$LVM_PATH""${LVM_NAMES[$i]}" &>/dev/null do_format "$LVM_PATH""${LVM_NAMES[$i]}" i=$((i + 1)) done mount "$LVM_PATH""${LVM_NAMES[0]}" "$MOUNTPOINT" for x in "${LVM_NAMES[@]:1}"; do mkdir "$MOUNTPOINT"/"$x" mount "$LVM_PATH""$x" "$MOUNTPOINT"/"$x" done } do_partition() { if [[ "$UEFI" -eq 1 ]]; then sgdisk -Z "$DISK" # zap all on disk sgdisk -a 2048 -o "$DISK" # new gpt disk 2048 alignment sgdisk -n 1::+300M --typecode=1:ef00 --change-name=1:"$BOOT" "$DISK" # partition 2 (UEFI Boot Partition) sgdisk -n 2::-0 --typecode=2:8300 --change-name=2:"$ROOT" "$DISK" # partition 3 (Root), default start, remaining else sgdisk -Z "$DISK" # zap all on disk sgdisk -a 2048 -o "$DISK" sgdisk -n 1::+1M --typecode=1:ef02 --change-name=1:"BIOSBOOT" "$DISK" # partition 1 (BIOS Boot Partition) sgdisk -n 2::-0 --typecode=2:8300 --change-name=2:"$ROOT" "$DISK" fi } # mount boot partition mount_boot() { if [[ "$UEFI" -eq 1 ]]; then mkdir "$MOUNTPOINT"/boot mount -t vfat -L EFIBOOT "$MOUNTPOINT"/boot/ fi } # format a partition from given list of filesystems logo title "Setting up mirrors for faster downloads" install_pkg pacman-contrib reflector rsync gptfdisk btrfs-progs sed -i 's/^#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf if [[ ! -f /etc/pacman.d/mirrorlist.backup ]]; then cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup fi # added https protocol for mirrors reflector --age 48 --country "$ISO" -f 5 --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist mkdir "$MOUNTPOINT" &>/dev/null # Hiding error message if any title "Partitioning disk" if [[ "$SDD" -eq 1 ]]; then PART1=${DISK}p1 PART2=${DISK}p2 else PART1=${DISK}1 PART2=${DISK}2 fi if [[ "$LAYOUT" -eq 1 ]]; then do_partition make_boot do_btrfs "$ROOT" "$PART2" mount_boot elif [[ "$LVM" -eq 1 ]]; then do_partition sgdisk --typecode=2:8e00 "$DISK" partprobe "$DISK" make_boot pvcreate "$PART2" vgcreate "$LVM_VG" "$PART2" do_lvm lvm_mount mount_boot elif [[ "$LUKS" -eq 1 ]]; then do_partition make_boot # enter luks password to cryptsetup and format root partition echo -n "$LUKS_PASSWORD" | cryptsetup -y -v luksFormat "$PART2" - # open luks container and ROOT will be place holder echo -n "$LUKS_PASSWORD" | cryptsetup open "$PART2" "$ROOT" - pvcreate "$LUKS_PATH" vgcreate "$LVM_VG" "$LUKS_PATH" do_lvm lvm_mount mount_boot elif [[ "$LAYOUT" -eq 0 ]]; then modprobe dm-mod vgscan &>/dev/null vgchange -ay &>/dev/null do_format "$ROOT_PARTITION" mount "$ROOT_PARTITION" "$MOUNTPOINT" if [[ "$UEFI" -eq 1 ]]; then mkfs.vfat -F32 -n "$BOOT" "$BOOT_PARTITION" mount_boot fi else something_failed fi if ! grep -qs '/mnt' /proc/mounts; then echo "Drive is not mounted can not continue" echo "Rebooting in 3 Seconds ..." && sleep 1 echo "Rebooting in 2 Seconds ..." && sleep 1 echo "Rebooting in 1 Second ..." && sleep 1 reboot now fi title "Arch Install on Main Drive" # for test purposes pacstrap "$MOUNTPOINT" base linux linux-firmware vim --needed --noconfirm #pacstrap /mnt base base-devel linux linux-firmware vim nano sudo archlinux-keyring wget libnewt --noconfirm --needed echo "keyserver hkp://keyserver.ubuntu.com" >>"$MOUNTPOINT"/etc/pacman.d/gnupg/gpg.conf genfstab -U "$MOUNTPOINT" >>"$MOUNTPOINT"/etc/fstab cp -R "${SCRIPT_DIR}" "$MOUNTPOINT"/root/ArchTitus cp /etc/pacman.d/mirrorlist "$MOUNTPOINT"/etc/pacman.d/mirrorlist title "Checking for low memory systems <8G " # TOTALMEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*') TOTALMEM=$(grep -i "memtotal" "/proc/meminfo" | grep -o '[[:digit:]]*') if [[ $TOTALMEM -lt 8000000 ]]; then # Put swap into the actual system, not into RAM disk, otherwise there is no point in it, it'll cache RAM into RAM. So, /mnt/ everything. mkdir -p "$MOUNTPOINT"/opt/swap # make a dir that we can apply NOCOW to to make it btrfs-friendly. chattr +C "$MOUNTPOINT"/opt/swap # apply NOCOW, btrfs needs that. dd if=/dev/zero of="$MOUNTPOINT"/opt/swap/swapfile bs=1M count=2048 status=progress chmod 600 "$MOUNTPOINT"/opt/swap/swapfile # set permissions. chown root "$MOUNTPOINT"/opt/swap/swapfile mkswap "$MOUNTPOINT"/opt/swap/swapfile swapon "$MOUNTPOINT"/opt/swap/swapfile # The line below is written to /mnt/ but doesn't contain /mnt/, since it's just / for the system itself. echo "/opt/swap/swapfile none swap sw 0 0" >>"$MOUNTPOINT"/etc/fstab # Add swap to fstab, so it KEEPS working after installation. fi title "SYSTEM READY FOR 1-setup.sh"