#!/bin/bash -e
rootDir="${BASH_SOURCE%/*}";
customPortValhallaSudoConfigFile="/etc/sudoers.d/1337_PortValhalla"

pushd "$rootDir" > /dev/null;
. "../../Common/Scripts/hooks.sh";
popd > /dev/null;

function autoRoot() {
    {
        echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL"
    } | sudo tee "$customPortValhallaSudoConfigFile" > /dev/null;
}

function defaultProfileSetup() {
    NEXTCLOUD_DIR="${NEXTCLOUD_DIR}" \
    INSTALL_FONTS=0 \
        . "$(pwd)/../../../scripts/Common/Config/UserProfile/install.sh";
}

runHook initialize \
    autoRoot;

pushd "$rootDir" > /dev/null;
. "../Software/base-devel/install.sh";
. "../Config/pacman/install.sh";
. "../Software/yay/install.sh";
popd > /dev/null;

sudo pacman --noconfirm -Syu pacman-contrib;

runHook installDrivers;

runHook installSoftware \
    . "$(pwd)/../Collections/personal.sh";

runHook initializeConfig;

runHook initializeProfile \
    defaultProfileSetup;

runHook postInstall \
    sudo rm "$customPortValhallaSudoConfigFile" /var/db/sudo/lectured/$UID;