#!/bin/bash

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

                                                                                                     
    ██                                                                                               
  █   ██                                                                                             
    ██    ██████    █████         ██    █████     █████     ████    ██        █████         ██       
         ██    ██  ██   ███  ███████   ██   ██   ██   ██       ██  ████████  ██    ██  ███████       
         █████     ██████   ██    ██   ██████    ██      ████████   ██   █   ███████   ██   ██       
         ██        ██████    ███████   ██████    ██       ██████    ██████   ██████    ███████       
                                                                                                     

EOF
}

# Clear screen and show logo
clear
print_logo

echo "Updating CoreDesktop..."
git -C ~/.local/share/coredesktop pull
sudo cp ~/.local/share/coredesktop/coreupdate ~/.local/bin/coreupdate
sudo cp ~/.local/share/coredesktop/corerefresh ~/.local/bin/corerefresh

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

echo "Updating Flatpaks..."
flatpak update

echo "Updating Ruby and Rails..."
mise upgrade --bump ruby
mise reshim
gem update

cd ~/.local/share/coredesktop
source utils.sh
source packages.conf

echo "Checking for new packages..."
install_packages "${SYSTEM_UTILS[@]}"
install_packages "${DEV_TOOLS[@]}"
install_packages "${MAINTENANCE[@]}"
install_packages "${DESKTOP[@]}"
install_packages "${MEDIA[@]}"
install_packages "${FONTS[@]}"

echo "Checking for new flatpaks..."
. install-flatpaks.sh

echo "Configuring Bitwarden SSH agent..."
. bitwarden.sh

echo "Done."
