#!/bin/bash set -e scriptstart=$SECONDS # https://dev.to/ifenna__/adding-colors-to-bash-scripts-48g4 ENDCOLOR="\e[0m" CYAN="\e[36m" BOLDGREEN="\e[1;32m" BOLDMAGENTA="\e[1;35m" BOLDRED="\e[1;31m" # https://stackoverflow.com/a/17695543 function prompt_yesno() { read -rp "$1 " case $(echo "$REPLY" | tr '[:upper:]' '[:lower:]') in y | yes) echo "yes" ;; *) echo "no" ;; esac } echo -e "${BOLDMAGENTA}ARCH-INSTALL/BOOTSTRAP STARTING${ENDCOLOR}" echo -e "${BOLDGREEN}Setting hardware clock to UTC...${ENDCOLOR}" read -rp "Press enter to continue..." _ # default timezone to UTC hwclock --systohc --utc # timedatectl set-timezone UTC echo -e "${CYAN}Set hardware clock.${ENDCOLOR}" echo -e "${BOLDGREEN}Setting default language to en_US...${ENDCOLOR}" read -rp "Press enter to continue..." _ # Set default language to US english sed -i "/#en_US.UTF-8 UTF-8/cen_US.UTF-8 UTF-8" /etc/locale.gen locale-gen echo "LANG=en_US.UTF-8" > /etc/locale.conf echo -e "${CYAN}Set system language.${ENDCOLOR}" echo -e "${BOLDGREEN}Setting known good mirror...${ENDCOLOR}" read -rp "Press enter to continue..." _ # use a known good mirror for initial package installation - we'll generate a # new mirrorlist shortly # shellcheck disable=SC2016 MIRROR='Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch' echo "$MIRROR" > /etc/pacman.d/mirrorlist echo -e "${CYAN}Set mirror.${ENDCOLOR}" echo -e "${BOLDGREEN}Adding supermario repository...${ENDCOLOR}" read -rp "Press enter to continue..." _ # add the supermario repo and then refresh - we'll set it "correctly" once # ansible runs curl -s https://finelli.pub/36FDA306.asc | pacman-key -a - pacman-key --lsign-key C3CD75B002978A8468CA7B1F6C3ADDDE36FDA306 echo '[supermario]' >> /etc/pacman.conf # shellcheck disable=SC2016 echo 'Server = https://pkgs.finelli.dev/arch/$arch' >> /etc/pacman.conf echo -e "${CYAN}Added supermario repository${ENDCOLOR}" echo -e "${BOLDGREEN}Synchronizing databases...${ENDCOLOR}" read -rp "Press enter to continue..." _ pstart=$SECONDS while :; do if pacman -Syyu; then break else echo -e "${BOLDRED}Synchronizing databases failed!${ENDCOLOR}" if [[ "no" == $(prompt_yesno "Retry?") ]]; then exit 1 fi fi done ptime=$((SECONDS - pstart)) echo -e "${CYAN}Synchronizing databases done. (in $ptime seconds)${ENDCOLOR}" echo -e "${BOLDGREEN}Setting hostname...${ENDCOLOR}" read -rp "Press enter to continue..." _ # can't have a baby without a name read -rp "What's the new hostname? " NEW_HOSTNAME echo "$NEW_HOSTNAME" > /etc/hostname echo -e "${CYAN}Set hostname: ${NEW_HOSTNAME}.${ENDCOLOR}" AMD=AuthenticAMD INTEL=GenuineIntel if [[ $(lscpu | grep -m1 Vendor\ ID | awk '{print $3}') == "$INTEL" ]]; then microcode=intel-ucode elif [[ $(lscpu | grep -m1 Vendor\ ID | awk '{print $3}') == "$AMD" ]]; then microcode=amd-ucode else microcode="" fi echo -e "${BOLDGREEN}Installing bootstrap packages...${ENDCOLOR}" read -rp "Press enter to continue..." _ pstart=$SECONDS while :; do # shellcheck disable=SC2086 if pacman -S efibootmgr btrfs-progs dosfstools ntfs-3g e2fsprogs \ exfat-utils f2fs-tools os-prober lvm2 cryptsetup mdadm usbutils \ elfutils iptables-nft $microcode; then break else echo -e "${BOLDRED}Installing boot packages failed!${ENDCOLOR}" if [[ "no" == $(prompt_yesno "Retry?") ]]; then exit 1 fi fi done ptime=$((SECONDS - pstart)) echo -e "${CYAN}Done installing boot packages. (in $ptime seconds)${ENDCOLOR}" echo -e "${BOLDGREEN}Installing systemd-boot...${ENDCOLOR}" read -rp "Press enter to continue..." _ bootctl install echo -e "${CYAN}Installed bootloader.${ENDCOLOR}" echo -e "${BOLDGREEN}Configuring sudo...${ENDCOLOR}" read -rp "Press enter to continue..." _ # we use GID 27 for sudo, which is what they use in debian if ! getent group 27; then groupadd --system -g 27 sudo fi echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/gsudo chmod 0440 /etc/sudoers.d/gsudo echo -e "${CYAN}Configured sudo.${ENDCOLOR}" echo -e "${BOLDGREEN}Installing ansible and dependencies...${ENDCOLOR}" read -rp "Press enter to continue..." _ pstart=$SECONDS while :; do # the rest of the system gets installed/configured using ansible if pacman -S ansible git pyalpm ansible-gpg-key-git gvim; then break else echo -e "${BOLDRED}Installing ansible packages failed!${ENDCOLOR}" if [[ "no" == $(prompt_yesno "Retry?") ]]; then exit 1 fi fi done ptime=$((SECONDS - pstart)) echo -e "${CYAN}Installing ansible done. (in $ptime seconds)${ENDCOLOR}" echo -e "${BOLDMAGENTA}ARCH-INSTALL/BOOTSTRAP COMPLETE${ENDCOLOR}" echo "Total time: $((SECONDS - scriptstart)) seconds" exit 0