#!/bin/bash

# ---Clearing Variables to Default---
var_wheel=""

# ---Questions---
read -p 'Hostname: ' var_hostname
read -p 'Root password: ' var_password
read -p 'User name: ' var_user_name
read -p "User ($var_user_name) password: " var_user_password
read -p "Would you like the user \"$var_user_name\" to be a super user? (type \'wheel\' to say yes) " var_user_wheel
if [[ $var_user_wheel = "wheel" ]]
then
    var_wheel="-aG wheel"
else
    var_wheel=" "
fi


echo
echo
echo 'Starting to install...'
echo
echo
echo
sleep 1

# ---Execution---
ln -sf /usr/share/zoneinfo/America/Buenos_Aires /etc/localtime
hwclock --systohc
timedatectl set-ntp true

sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
locale-gen

echo 'LANG=en_US.UTF-8' >> /etc/locale.conf
echo "$var_hostname" >> /etc/hostname

echo '127.0.0.1 localhost' >> /etc/hosts
echo '::1       localhost' >> /etc/hosts
echo "127.0.0.1 $var_hostname.localdomain $var_hostname" >> /etc/hosts

echo
echo
echo 'Doing btrfs stuff and encryption...'
echo
echo
echo
sleep 1

#   ---[Btrfs and encryption]---
sed -i 's/MODULES=(/MODULES=(btrfs/' /etc/mkinitcpio.conf
var_hooks_line="$(grep 'HOOKS=(' /etc/mkinitcpio.conf | grep -v '#    HOOKS')"
var_hooks_replace="$(grep 'HOOKS=(' /etc/mkinitcpio.conf | grep -v '#    HOOKS' | sed 's/filesystems/encrypt filesystems/')"
sed -i "s/$var_hooks_line/$var_hooks_replace/" /etc/mkinitcpio.conf
mkinitcpio -p linux

echo
echo
echo 'Doing user stuff...'
echo
echo
echo
sleep 1

#   ---[Users]---
useradd -m "$var_user_name"
echo "$var_user_name:$var_user_password" | chpasswd

echo "root:$var_password" | chpasswd

sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers
if [[ $var_wheel = "-aG wheel" ]]
then
    usermod $var_wheel $var_user_name
fi

echo
echo
echo 'Installing packages...'
echo
echo
echo
sleep 1

#   ---[Packages]---
pacman -S networkmanager gnome gdm gnome-tweaks alacritty fish exa vlc git base-devel adobe-source-sans-fonts

mkdir /root/arch-custom-install
cd /root/arch-custom-install

git clone https://gitlab.com/thebiblelover7/prebuilt-packages 
cd prebuilt-packages
for i in $(ls -1)
do
    pacman -U $i
done

paru -S brave-bin logseq-desktop-bin slack-desktop schildichat-desktop-bin whitesur-icon-theme whitesur-gtk-theme gnome-shell-extension-pop-shell-git cursor-theme-macos-big-sur

echo
echo
echo 'Installing configs...'
echo
echo
echo
sleep 1

#   ---[Configs]---
cd /home/$var_user_name
git clone https://gitlab.com/thebiblelover7/dotfiles
cd dotfiles
./install.sh
chown -R $var_user_name:$var_user_name /home/$var_user_name
chsh -s /bin/fish $var_user_name

cd

# pacman color and parallel downloads
# change dotfiles to have the plain background, and to have the right theme
# albert 

echo
echo
echo 'Enabling services to start on boot...'
echo
echo
echo
sleep 1

#   ---[Services]
systemctl enable NetworkManager
systemctl enable bluetooth
systemctl enable gdm
#systemctl enable cups.service
