Files
arch-installer/xabs-install.sh
2022-02-25 18:22:57 +01:00

120 lines
4.3 KiB
Bash

#!/bin/sh
# this script tries to automate the setup process from live USB
# once this script ends you should be able to reboot the computer and boot your
# new Archlinux installation.
# It assumes you have already set up an internet connection (since you've been
# able to download the script).
INSTALL_LOCATION="192.168.1.42"
welcomemsg(){
dialog --title "XABS Installer!" --msgbox "\nWelcome to Xavi's Automated Bootstrap Script" 10 60
}
error() { printf "%s\n" "$1" >&2; exit 1; }
refreshkeys() { \
case "$(readlink -f /sbin/init)" in
*systemd* )
dialog --infobox "Refreshing Arch Keyring..." 4 40
pacman --noconfirm -S archlinux-keyring >/dev/null 2>&1
;;
*)
dialog --infobox "Enabling Arch Repositories..." 4 40
pacman --noconfirm --needed -S artix-keyring artix-archlinux-support >/dev/null 2>&1
for repo in extra community; do
grep -q "^\[$repo\]" /etc/pacman.conf ||
echo "[$repo]
Include = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf
done
pacman -Sy >/dev/null 2>&1
pacman-key --populate archlinux
;;
esac ;}
getrootpass() { \
# Prompts user for new username an password.
rootpass1=$(dialog --no-cancel --passwordbox "Enter a password for the root user." 10 60 3>&1 1>&2 2>&3 3>&1)
rootpass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1)
while ! [ "$rootpass1" = "$rootpass2" ]; do
unset rootpass2
rootpass1=$(dialog --no-cancel --passwordbox "Passwords do not match.\\n\\nEnter password again." 10 60 3>&1 1>&2 2>&3 3>&1)
rootpass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1)
done ;}
## SCRIPT START ##
# Check this is an Arch distro an we're root
pacman --noconfirm --needed -Sy dialog || error "Are you sure you're running this as the root user, are on an Arch-based distribution and have an internet connection?"
# Start prompt
welcomemsg || error "User exit."
hostname=$(dialog --inputbox "First, please enter a name for your machine." 10 60 3>&1 1>&2 2>&3 3>&1) || exit 1
getrootpass || error "User exit."
# taken directly from the Archlinux Wiki
# 1.6 Check BOOT MODE
# exits if bot mode wasn't EFI
ls /sys/firmware/efi/efivars > /dev/null 2>&1 || error "Non EFI boot not yet supported."
# 1.7 Ignored (you should already have internet)
# 1.8 Update the system clock
timedatectl set-ntp true
# 1.9 Partition the disks
# for now, this assumes full device install
# first get the device name, ignore loop, rom and airoot. Remove lines that may
# be caused by already partitioned drives
disk=$(fdisk -l | grep "Disk" | egrep -v "identifier|type" | egrep -v "loop|rom|airoot" | cut -d ":" -f1 | cut -d " " -f2;)
dialog --title "Partitioning" --infobox "\nPartitioning your disk $disk" 10 60
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << FDISK_CMDS | fdisk $disk > /dev/null
g # new GPT
n # new partition
1 #
# default - first sector
+512MiB # size
n # new partition
2 #
# default - first sector
# default - last sector
t # partition type
1 #
uefi # uefi filesystem
t # partition type
2 #
linux # linux filesystem
w # write
FDISK_CMDS
dialog --title "Partitioning" --infobox "\n$disk succesfully partitioned. Starting format" 10 60
# create names for the partitions
part="${disk}2"
efipart="${disk}1"
# 1.10 format the partitions
mkfs.fat -F 32 $efipart || error "Error formating EFI partition"
mkfs.ext4 $part || error "Error formating linux partition"
dialog --title "Format" --infobox "\nSuccesfully formated partitions" 10 60
# 1.11 Mount the filesystems
mount $part /mnt &> /dev/null
mkdir /mnt/efi &> /dev/null
mount $efipart /mnt/efi &> /dev/null
# 2 Installation
# Refresh Arch keyrings.
refreshkeys || error "Error automatically refreshing Arch keyring. Consider doing so manually."
dialog --title "Installation" --infobox "\nInstalling of base packages. This might take a while..." 10 60
pacstrap /mnt base linux linux-firmware dhclient grub efibootmgr neovim nano >/dev/null 2>&1 || error "Error during installation of system, consider running pacstrap manually"
dialog --title "Installation" --infobox "\nSuccesful installation," 10 60
# 3 Basic config
# 3.1 fstab
genfstab -U /mnt >> /mnt/etc/fstab
# 3.2 chroot
curl $INSTALL_LOCATION/post-chroot.sh > /mnt/home/post-chroot.sh
curl $INSTALL_LOCATION/xabs.sh > /mnt/home/xabs.sh
arch-chroot /mnt /home/post-chroot.sh $rootpass1 $hostname