#!/usr/bin/bash -e # # Author: Casey DeLorme # # Description: A fully automated installation script wired for testing with # packer, but fully functional for a standard installation. # # Make sure you have a network connection, install git, clone this repository, # and finally run this script to automate the entire installation. # # pacman -Sy git # git clone https://git.caseydelorme.com/cdelorme/arch-desktop.git # cd arch-desktop # ./setup/install.sh # check that efivars is mounted or notify the user that it could create a problem [ ! -d /sys/firmware/efi/efivars ] && echo "efivars not mounted; this install may leave you with a derelict system..." && sleep 30s # verify required variables while [[ ! "$enable_hibernation" =~ ^[yn]$ ]]; do read -p "would you like to enable hibernation (yn)? " -n1 enable_hibernation && echo ""; done while [ -z "$root_password" ]; do read -p "please enter a root password: " -s root_password && echo ""; done while [ -z "$username" ]; do read -p "please enter your username: " username; done while [ -z "$password" ]; do read -p "please enter your password: " -s password && echo ""; done # optionally print all commands [ -n "$DEBUG" ] && set -x # test network connection ping -c 3 archlinux.org # synchronize time (print for debug) timedatectl set-ntp true timedatectl status # detect disks (if only one exists we can use it) # @todo: make sure this ignores optical drives (???) export disk=$(lsblk -l | grep disk | awk '{print $1}') # if more than one disk exists ask which to use: if [ $(echo "$disk" | wc -l) -gt 1 ]; then echo -e "multiple disks found:\n$disk" read -p "please enter the name of the disk you want to use: " disk # make sure the disk exists or terminate if [ ! -b "/dev/${disk}" ]; then echo "unable to locate disk: /dev/${disk}" exit 1 fi fi # either use sane default or intelligently size swap for hibernation export swap_size=2048 if [ "$enable_hibernation" = "y" ]; then export ram_size=$(numfmt --from-unit=K --from=iec --to-unit=M --to=iec $(cat /proc/meminfo | grep MemTotal | awk '{print $2}')) if [ $ram_size -le $(numfmt --from-unit=1024 --from=iec 4G) ]; then export swap_size=$(printf %.0f $(echo "$ram_size * 1.5" | bc)) else export ram_sqrt=$(echo "sqrt($(numfmt --from-unit=M --to-unit=Gi $ram_size))" | bc) export swap_size=$(printf %.0f $(echo "$ram_size + $(numfmt --from-unit=Gi --to-unit=Mi $ram_sqrt)" | bc)) fi fi # partition the hard drive parted "/dev/${disk}" -s 'mklabel gpt' parted "/dev/${disk}" -s 'mkpart primary fat32 1MiB 1024MiB' parted "/dev/${disk}" -s 'set 1 esp on' parted "/dev/${disk}" -s "mkpart primary linux-swap 1024MiB ${swap_size}MiB" parted "/dev/${disk}" -s "mkpart primary btrfs ${swap_size}MiB 100%" # acquire partitions as an array export partitions=( $(lsblk -l -xNAME "/dev/${disk}" | grep part | awk '{print $1}') ) # format the partitions mkfs.fat -F32 -nEFI "/dev/${partitions[0]}" mkswap -Larch "/dev/${partitions[1]}" mkfs.btrfs -fLarch "/dev/${partitions[2]}" # enable and mount partitions with appropriate settings swapon "/dev/${partitions[1]}" mount -o "noatime,compress=lzo,space_cache,autodefrag,ssd" "/dev/${partitions[2]}" /mnt mkdir /mnt/boot mount "/dev/${partitions[0]}" /mnt/boot # install base and base-devel package sets, and generate the fstab pacstrap /mnt base base-devel genfstab -U -p /mnt >> /mnt/etc/fstab # this assumes that arch.sh and install/ exists and will copy them to continue # @note: would prefer to copy to `/tmp` but `/mnt/tmp` from iso is a separate tmpfs mkdir -p /mnt/srv/arch-desktop cp -r install /mnt/srv/arch-desktop/ cp arch.sh /mnt/srv/arch-desktop/ # proceed to automate arch-chroot installation then umount and reboot with an async delay arch-chroot /mnt /srv/arch-desktop/arch.sh umount -R /mnt (sleep 5 && systemctl reboot) &