setup/install.sh

170 lines
6.3 KiB
Bash
Raw Normal View History

2024-09-07 19:19:25 +00:00
#!/bin/bash
echo "We just need to ask some questions before installing"
2024-09-13 16:26:32 +00:00
read -p "Do you want to format any disks before installing? " formatyesno
case $formatyesno in
[yesYesYy]* )
cfdisk
;;
[noNoNn]* )
echo "Skipping"
;;
* ) echo "Please answer yes (Yes, y, Y) or no (No, n, N)";;
esac
2024-05-23 16:49:21 +00:00
# Get drive values for installation
lsblk
# Set EFI and root partitions
2024-05-23 16:49:21 +00:00
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
2024-09-07 21:40:36 +00:00
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
2024-09-07 21:06:46 +00:00
# Ask if a home partition should be created
read -p "Do you wish to set a home partition? " yesno
case $yesno in
[yesYesYy]* )
2024-09-07 21:26:37 +00:00
read -p 'Please enter the drive value for the home partition: ' homepar
2024-09-07 21:33:17 +00:00
# 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
2024-09-07 21:28:31 +00:00
;;
2024-09-07 21:06:46 +00:00
[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
2024-09-07 22:42:59 +00:00
# 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]* )
2024-09-07 22:48:34 +00:00
gpu="vmware"
2024-09-07 22:42:59 +00:00
;;
[noNoNn]* )
2024-09-07 22:48:34 +00:00
gpu="nvidia"
2024-09-07 22:42:59 +00:00
;;
* ) 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
2024-09-07 20:52:23 +00:00
echo -ne "\n"
read -rsp "Please re-enter the password " passwordconfirm
2024-09-07 21:40:36 +00:00
echo -ne "\n"
if [[ "$password" == "$password2" ]]; then
export USERNAME = $username
export PASSWORD = $password
echo "Credentials saved"
fi
# Run pacstrap and install base packages
2024-09-07 23:41:54 +00:00
pacstrap -i /mnt base base-devel linux linux-firmware linux-headers git openssh rsync networkmanager grub efibootmgr dosfstools os-prober nano dkms dbus-broker-units mkinitcpio iptables-nft --noconfirm --needed
2024-09-07 21:06:46 +00:00
# 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
2024-09-07 21:06:46 +00:00
if test -z "$homepar"; then
mount /dev/$homepar /mnt/home
2024-09-07 21:06:46 +00:00
fi
2024-05-23 16:49:21 +00:00
# Generate a fstab file
genfstab -U /mnt >> /mnt/etc/fstab
# Chroot into the new system and setup
2024-09-07 20:52:23 +00:00
arch-chroot /mnt /bin/bash <<EOF
2024-09-07 21:40:36 +00:00
# Set up user locale (date/time, keyboard layout)
2024-09-07 22:52:43 +00:00
echo "Setting user locale"
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
2024-09-07 21:40:36 +00:00
# Set host information
2024-09-07 22:52:43 +00:00
echo "Setting host information"
echo archlinux > /etc/hostname
2024-09-07 21:06:46 +00:00
echo -e "\n127.0.0.1 localhost\n::1 localhost\n127.0.0.1 archlinux" >> /etc/hosts
2024-09-07 21:40:36 +00:00
# Set up environment file
echo -e "\n# Set terminal editor to Nano\nEDITOR=nano" >> /etc/environment
# Add "chaotic-aur" as a Pacman repository
2024-09-07 22:52:43 +00:00
echo "Configuring Pacman"
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'
2024-09-07 21:40:36 +00:00
# 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
2024-09-07 21:40:36 +00:00
# Do a full sync on Pacman to enable extra repos
pacman -Syu
# Enable NetworkManager
2024-09-07 22:52:43 +00:00
echo "Enabling networking"
systemctl enable NetworkManager
2024-09-07 20:52:23 +00:00
# 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
2024-09-07 21:40:36 +00:00
# Create the standard user and add it to all neccesary groups
2024-09-07 22:52:43 +00:00
echo "Creating user account"
useradd -mG power,storage,wheel $username
echo "$username:$password" | chpasswd
2024-09-07 21:40:36 +00:00
# Disable the option to log in as the root user
2024-09-07 20:52:23 +00:00
passwd --lock root
2024-09-07 21:40:36 +00:00
# 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
2024-09-07 22:42:59 +00:00
# Set up GPU drivers depending on device
2024-09-07 22:52:43 +00:00
echo "Installing and configuring GPU drivers"
if [[ $gpu == "vmware" ]] then
2024-09-07 22:42:59 +00:00
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
2024-09-07 22:52:43 +00:00
if [[ $gpu == "nvidia" ]] then
2024-09-07 22:42:59 +00:00
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
2024-09-07 21:40:36 +00:00
# Required to enable network changes (not sure if this is neccesary)
#sysctl --system
2024-09-07 23:37:10 +00:00
# Install some essential utilities and enable any appropriate services
pacman -S --noconfirm yay ufw clamav hblock
freshclam
systemctl enable clamav-freshclam.service
systemctl enable clamav-daemon.service
ufw limit 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw default deny incoming
ufw default allow outgoing
ufw limit ssh
ufw enable
systemctl enable ufw.service
systemctl enable sshd.service
hblock
# Prompt the user to reboot
2024-09-07 21:40:36 +00:00
echo "Install complete, please reboot"
EOF