#!/bin/bash
set -e

export LANG=C
export LC_ALL=C
LOG_FILE=/var/log/tuxedo-install-default-snaps.log

DEBIAN_FRONTEND=noninteractive dpkg --configure -a 2>&1 | tee -a ${LOG_FILE}
DEBIAN_FRONTEND=noninteractive apt-get --reinstall install -y snapd firefox thunderbird 2>&1 | tee -a ${LOG_FILE}

if snap list | grep -q "core24"; then
    snap refresh core24 --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install core24 --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "snapd"; then
    snap refresh snapd --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install snapd --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "firefox"; then
    snap refresh firefox --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install firefox --classic 2>&1 | tee -a ${LOG_FILE} || true
fi
snap install firmware-updater --classic 2>&1 | tee -a ${LOG_FILE} || true

if snap list | grep -q "gnome-46-2404"; then
    snap refresh gnome-46-2404 --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install gnome-46-2404 --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "bare"; then
    snap refresh bare --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install bare --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "gtk-common-themes"; then
    snap refresh gtk-common-themes --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install gtk-common-themes --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "mesa-2404"; then
    snap refresh mesa-2404 --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install mesa-2404 --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "snap-store"; then
    snap refresh snap-store --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install snap-store --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "snapd-desktop-integration"; then
    snap refresh snapd-desktop-integration --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install snapd-desktop-integration --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

if snap list | grep -q "thunderbird"; then
    snap refresh thunderbird --classic 2>&1 | tee -a ${LOG_FILE} || true
else
    snap install thunderbird --classic 2>&1 | tee -a ${LOG_FILE} || true
fi

unset LC_ALL
unset LANG

exit 0;
