#!/bin/bash
# Volante Repo Setup for Ubuntu 24.04 (Noble)
set -e

# Check OS version
VERSION=$(grep VERSION_CODENAME /etc/os-release | cut -d'=' -f2)
if [ "$VERSION" != "noble" ]; then
    echo "ERROR: This script is for Ubuntu 24.04 (Noble) only."
    echo "Detected: $VERSION"
    echo "Use setup-jammy.sh for Ubuntu 22.04"
    exit 1
fi

echo '==> Fixing security URL in sources...'
sed -i 's|http://security.ubuntu.com/ubuntu/|https://ubuntu-repo.volantecloud.com/ubuntu/mirror/archive.ubuntu.com/ubuntu|g' /etc/apt/sources.list.d/ubuntu.sources 2>/dev/null || true

echo '==> Adding Mozilla Repo...'
echo "deb [trusted=yes signed-by=/usr/share/keyrings/Launchpad-PPA-for-Mozilla-Team.gpg] https://ubuntu-repo.volantecloud.com/ubuntu/mirror/ppa.launchpadcontent.net/mozillateam/ppa/ubuntu noble main" > /etc/apt/sources.list.d/mozilla.list
wget -q https://ubuntu-repo.volantecloud.com/keys/mozilla.asc -O /tmp/mozilla.asc
gpg --yes --dearmor -o /usr/share/keyrings/Launchpad-PPA-for-Mozilla-Team.gpg /tmp/mozilla.asc
rm /tmp/mozilla.asc

echo '==> Adding Chromium Repo...'
echo "deb [trusted=yes arch=amd64 signed-by=/usr/share/keyrings/Chromium.gpg] https://ubuntu-repo.volantecloud.com/ubuntu/mirror/ppa.launchpadcontent.net/xtradeb/apps/ubuntu noble main" > /etc/apt/sources.list.d/chromium.list
wget -q https://ubuntu-repo.volantecloud.com/keys/chromium-noble.asc -O /tmp/chromium-noble.asc
gpg --yes --dearmor -o /usr/share/keyrings/Chromium.gpg /tmp/chromium-noble.asc
rm /tmp/chromium-noble.asc

echo '==> Adding Volante Repo...'
echo "deb [trusted=yes arch=all signed-by=/usr/share/keyrings/volante-archive-keyring.gpg] https://ubuntu-repo.volantecloud.com/ubuntu/mirror/archive.ubuntu.com/ubuntu/ volante main" > /etc/apt/sources.list.d/volante-official-stable.list
wget -q https://ubuntu-repo.volantecloud.com/keys/volante.asc -O /tmp/volante.asc
gpg --yes --dearmor -o /usr/share/keyrings/volante-archive-keyring.gpg /tmp/volante.asc
rm /tmp/volante.asc

echo '==> Updating package lists...'
apt-get clean
rm -rf /var/lib/apt/lists/*
apt-get update

echo '==> Done!'
