setup/scripts/0-install.sh
2024-09-07 23:46:19 +01:00

139 lines
5.5 KiB
Bash

#!/bin/bash
echo "We just need to ask some questions before installing"
# Get drive values for installation
lsblk
# Set EFI and root partitions
read -p 'Please enter the drive value for the root partition, this partition will be wiped and formatted: ' rootpar
read -p 'Please enter the drive value for the EFI partition: ' efipar
# Format the root partition to ext4
mkfs.ext4 /dev/$rootpar
# Mount root partition
mount /dev/$rootpar /mnt
# Ask if the EFI partition should be wiped before mounting
read -p "Do you wish to wipe the EFI partition? " yesno
case $yesno in
[yesYesYy]* )
mkfs.fat -F32 /dev/$efipar
;;
[noNoNn]* )
echo "The EFI partition will not be wiped"
;;
* ) echo "Please answer yes (Yes, y, Y) or no (No, n, N)";;
esac
# Ask if a home partition should be created
read -p "Do you wish to set a home partition? " yesno
case $yesno in
[yesYesYy]* )
read -p 'Please enter the drive value for the home partition: ' homepar
# Ask if a home partition should be wiped
read -p 'Do you wish to wipe the home partition? ' wipeyesno
case $wipeyesno in
[yesYesYy]* )
mkfs.ext4 /dev/$homepar
;;
[noNoNn]* )
echo "The home partition will not be wiped"
;;
* ) echo "Please answer yes (Yes, y, Y) or no (No, n, N)";;
esac
;;
[noNoNn]* )
echo "A home partition will not be used in this installation"
;;
* ) echo "Please answer yes (Yes, y, Y) or no (No, n, N)";;
esac
# Ask if this is being installed as a VM or bare metal, then install appropriate video drivers
read -p 'Is this being installed on VMWare Fusion? ' vmyesno
case $vmyesno in
[yesYesYy]* )
export GPU == "vmware"
;;
[noNoNn]* )
export GPU == "nvidia"
;;
* ) echo "Please answer yes (Yes, y, Y) or no (No, n, N)";;
esac
# Get user credentials
read -p "Please enter a username " username
read -rsp "Please enter a password " password
echo -ne "\n"
read -rsp "Please re-enter the password " passwordconfirm
echo -ne "\n"
if [[ "$password" == "$password2" ]]; then
export USERNAME = $username
export PASSWORD = $password
echo "Credentials saved"
fi
# Run pacstrap and install base packages
pacstrap -i /mnt base base-devel linux linux-firmware rsync networkmanager grub efibootmgr dosfstools os-prober nano dkms dbus-broker-units mkinitcpio iptables-nft --noconfirm --needed
# Create the /boot/efi directory, then mount the EFI partition (and the home partition if selected)
mkdir /mnt/boot/efi
mount /dev/$efipar /mnt/boot/efi
if test -z "$homepar"; then
mount /dev/$homepar /mnt/home
fi
# Generate a fstab file
genfstab -U /mnt >> /mnt/etc/fstab
# Chroot into the new system and setup
arch-chroot /mnt /bin/bash <<EOF
# Set up user locale (date/time, keyboard layout)
sed -i 's/^#en_GB.UTF-8 UTF-8/en_GB.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
pacman -S --noconfirm hunspell-en_gb
ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
hwclock --systohc
echo LANG=en_GB.UTF-8 > /etc/locale.conf
echo "KEYMAP=uk" > /etc/vconsole.conf
# Set host information
echo archlinux > /etc/hostname
echo -e "\n127.0.0.1 localhost\n::1 localhost\n127.0.0.1 archlinux" >> /etc/hosts
# Set up environment file
echo -e "\n# Set terminal editor to Nano\nEDITOR=nano" >> /etc/environment
# Add "chaotic-aur" as a Pacman repository
pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
pacman-key --lsign-key 3056513887B78AEB
pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
# Amend pacman.conf to preference
sed -i 's/^#Color/Color\nILoveCandy/' /etc/pacman.conf
sed -i 's/^#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf
echo -e "\n[chaotic-aur]\nInclude = /etc/pacman.d/chaotic-mirrorlist" >> /etc/pacman.conf
# Do a full sync on Pacman to enable extra repos
pacman -Syu
# Enable NetworkManager
systemctl enable NetworkManager
# Install GRUB
echo "Installing bootloader"
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg
# Create the standard user and add it to all neccesary groups
useradd -mG power,storage,wheel $username
echo "$username:$password" | chpasswd
# Disable the option to log in as the root user
passwd --lock root
# Set up sudo so "wheel" group users can do root commands (password required)
sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
# Set up GPU drivers depending on device
if [[ $gpu == "vmware" ]]
echo "Installing VM drivers"
pacman -S --noconfirm --needed open-vm-tools
cat /proc/version > /etc/arch-release
systemctl enable vmware-vmblock-fuse
systemctl enable vmtoolsd
pacman -S --noconfirm --needed xf86-input-vmmouse xf86-video-vmware mesa
fi
if [[ $gpu == "nvidia" ]]
echo "Installing NVIDIA GPU drivers"
pacman -S --noconfirm nvidia-dkms nvidia-utils lib32-nvidia-utils nvidia-settings
# Tweak systemd.conf and enable services for proper suspend/resume
echo "options nvidia NVreg_PreserveVideoMemoryAllocations=1" >> /lib/modprobe.d/systemd.conf
systemctl enable nvidia-suspend.service
systemctl enable nvidia-hibernate.service
systemctl enable nvidia-resume.service
fi
# Required to enable network changes (not sure if this is neccesary)
#sysctl --system
# Prompt the user to reboot
echo "Install complete, please reboot"
EOF