ArchTitus/scripts/1-setup.sh

173 lines
8.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#github-action genshdoc
#
# @file Setup
# @brief Configures installed system, installs base packages, and creates user.
echo "
-------------------------------------------------------------------------
█████╗ ██████╗ ██████╗██╗ ██╗████████╗██╗████████╗██╗ ██╗███████╗
██╔══██╗██╔══██╗██╔════╝██║ ██║╚══██╔══╝██║╚══██╔══╝██║ ██║██╔════╝
███████║██████╔╝██║ ███████║ ██║ ██║ ██║ ██║ ██║███████╗
██╔══██║██╔══██╗██║ ██╔══██║ ██║ ██║ ██║ ██║ ██║╚════██║
██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ██║ ██║ ╚██████╔╝███████║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝
-------------------------------------------------------------------------
Automated Arch Linux Installer
SCRIPTHOME: ArchTitus
-------------------------------------------------------------------------"
source $HOME/ArchTitus/configs/setup.conf
echo "
-------------------------------------------------------------------------
Network Setup
-------------------------------------------------------------------------"
pacman -S --noconfirm --needed networkmanager dhclient
systemctl enable --now NetworkManager
echo "
-------------------------------------------------------------------------
Setting up mirrors for optimal download
-------------------------------------------------------------------------"
pacman -S --noconfirm --needed pacman-contrib curl
pacman -S --noconfirm --needed reflector rsync grub arch-install-scripts git
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
nc=$(grep -c ^processor /proc/cpuinfo)
echo "
-------------------------------------------------------------------------
You have " $nc" cores. And
changing the makeflags for "$nc" cores. Aswell as
changing the compression settings.
-------------------------------------------------------------------------"
TOTAL_MEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*')
if [[ $TOTAL_MEM -gt 8000000 ]]; then
sed -i "s/^#\(MAKEFLAGS=\"-j\)2\"/\1$nc\"/;
/^COMPRESSXZ=(xz -c -z -)/s/-c /&-T $nc /" /etc/makepkg.conf
fi
echo "
-------------------------------------------------------------------------
Setup Language to US and set locale
-------------------------------------------------------------------------"
sed -i '/^#en_US.UTF-8 /s/^#//' /etc/locale.gen
locale-gen
timedatectl --no-ask-password set-timezone ${TIMEZONE}
timedatectl --no-ask-password set-ntp 1
localectl --no-ask-password set-locale LANG="en_US.UTF-8" LC_TIME="en_US.UTF-8"
ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
# Set keymaps
localectl --no-ask-password set-keymap ${KEYMAP}
# Add sudo no password rights
sed -Ei 's/^# (%wheel ALL=\(ALL(:ALL)?\) NOPASSWD: ALL)/\1/' /etc/sudoers
#Add parallel downloading
sed -i '/^#ParallelDownloads/s/^#//' /etc/pacman.conf
#Enable multilib
sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf
pacman -Sy --noconfirm --needed
echo "
-------------------------------------------------------------------------
Installing Base System
-------------------------------------------------------------------------"
# sed $INSTALL_TYPE is using install type to check for MINIMAL installation, if it's true, stop
# stop the script and move on, not installing any more packages below that line
if [[ ! $DESKTOP_ENV == server ]]; then
sed -n '/'$INSTALL_TYPE'/q;p' $HOME/ArchTitus/pkg-files/pacman-pkgs.txt | while read line; do
[[ ${line} == '--END OF MINIMAL INSTALL--' ]] && continue # If selected installation type is FULL, skip the --END OF THE MINIMAL INSTALLATION-- line
echo "INSTALLING: ${line}"
sudo pacman -S --noconfirm --needed ${line}
done
fi
echo "
-------------------------------------------------------------------------
Installing Microcode
-------------------------------------------------------------------------"
# determine processor type and install microcode
proc_type=$(lscpu)
if grep -E "GenuineIntel" <<< ${proc_type}; then
echo "Installing Intel microcode"
pacman -S --noconfirm --needed intel-ucode
proc_ucode=intel-ucode.img
elif grep -E "AuthenticAMD" <<< ${proc_type}; then
echo "Installing AMD microcode"
pacman -S --noconfirm --needed amd-ucode
proc_ucode=amd-ucode.img
fi
echo "
-------------------------------------------------------------------------
Installing Graphics Drivers
-------------------------------------------------------------------------"
# Graphics Drivers find and install
gpu_type=$(lspci)
if grep -E "NVIDIA|GeForce" <<< ${gpu_type}; then
pacman -S --noconfirm --needed nvidia
nvidia-xconfig
elif lspci | grep 'VGA' | grep -E "Radeon|AMD"; then
pacman -S --noconfirm --needed xf86-video-amdgpu
elif grep -E "Integrated Graphics Controller|Intel Corporation UHD" <<< ${gpu_type}; then
pacman -S --noconfirm --needed libva-intel-driver libvdpau-va-gl lib32-vulkan-intel vulkan-intel libva-intel-driver libva-utils lib32-mesa
fi
#SETUP IS WRONG THIS IS RUN
if ! source $HOME/ArchTitus/configs/setup.conf; then
# Loop through user input until the user gives a valid username
while true; do
read -p "Please enter username:" username
# username regex per response here https://unix.stackexchange.com/questions/157426/what-is-the-regex-to-validate-linux-users
# lowercase the username to test regex
[[ "${username,,}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]] && break
echo "Incorrect username."
done
# convert name to lowercase before saving to setup.conf
echo "username=${username,,}" >> ${HOME}/ArchTitus/configs/setup.conf
#Set Password
read -p "Please enter password:" password
echo "password=${password,,}" >> ${HOME}/ArchTitus/configs/setup.conf
# Loop through user input until the user gives a valid hostname, but allow the user to force save
while true; do
read -p "Please name your machine:" name_of_machine
# hostname regex (!!couldn't find spec for computer name!!)
[[ "${name_of_machine,,}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]] && break
# if validation fails allow the user to force saving of the hostname
read -p "Hostname doesn't seem correct. Do you still want to save it? (y/n)" force
[[ "${force,,}" = "y" ]] && break
done
echo "NAME_OF_MACHINE=${name_of_machine,,}" >> ${HOME}/ArchTitus/configs/setup.conf
fi
echo "
-------------------------------------------------------------------------
Adding User
-------------------------------------------------------------------------"
if [ $(whoami) = "root" ]; then
groupadd libvirt
useradd -m -G wheel,libvirt -s /bin/bash $USERNAME
echo "$USERNAME created, home directory created, added to wheel and libvirt group, default shell set to /bin/bash"
# use chpasswd to enter $USERNAME:$password
echo "$USERNAME:$PASSWORD" | chpasswd
echo "$USERNAME password set"
cp -R $HOME/ArchTitus /home/$USERNAME/
chown -R $USERNAME: /home/$USERNAME/ArchTitus
echo "ArchTitus copied to home directory"
# enter $NAME_OF_MACHINE to /etc/hostname
echo $NAME_OF_MACHINE > /etc/hostname
else
echo "You are already a user proceed with aur installs"
fi
if [[ ${FS} == "luks" ]]; then
# Making sure to edit mkinitcpio conf if luks is selected
# add encrypt in mkinitcpio.conf before filesystems in hooks
sed -i 's/filesystems/encrypt &/g' /etc/mkinitcpio.conf
# making mkinitcpio with linux kernel
mkinitcpio -p linux
fi
echo "
-------------------------------------------------------------------------
SYSTEM READY FOR 2-user.sh
-------------------------------------------------------------------------"