#!/bin/bash

# Print the logo
print_logo() {
    cat << "EOF"


 ██╗  ██╗ █████╗ ███╗   ███╗██████╗  █████╗  ██████╗██╗  ██╗
 ██║  ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
 ███████║███████║██╔████╔██║██████╔╝███████║██║     █████╔╝ 
 ██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║     ██╔═██╗ 
 ██║  ██║██║  ██║██║ ╚═╝ ██║██║     ██║  ██║╚██████╗██║  ██╗
 ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝╚═╝     ╚═╝  ╚═╝ ╚═════╝╚═╝  ╚═╝                                                                                                     
                                                                                                     

EOF
}

# Clear screen and show logo
clear
print_logo

echo "Updating Arch..."
sudo pacman -Syu

echo "Updating AUR..."

if ! yay -Sua 2>/dev/null; then
    echo "yay -Sua returned an error. Let's rebuild YAY."
    sudo pacman -R yay
    cd /tmp
    git clone https://aur.archlinux.org/yay.git
    cd yay
    makepkg -si
    cd ..
    rm -rf yay
    cd
    yay -Sua --noconfirm
else
    yay -Sua --noconfirm
fi

HAMPACK_DIR="$HOME/.local/share/HamPack"

echo "Pulling latest HamPack configuration..."
git -C "$HAMPACK_DIR" pull

echo "Installing any new packages..."
source "$HAMPACK_DIR/utils.sh"
source "$HAMPACK_DIR/packages.conf"
install_packages "${UTILITIES[@]}"
install_packages "${APPLICATIONS[@]}"

echo "Installing any new Flatpaks..."
source "$HAMPACK_DIR/install-flatpaks.sh"

echo "Installing any new or updated compiled applications..."
bash "$HAMPACK_DIR/install-compiled.sh"

echo "Installing any new or updated pre-built binaries..."
bash "$HAMPACK_DIR/install-binaries.sh"

echo "Done. You probably want to reboot your system..."
