#!/bin/bash
# Volante Repo Setup for Ubuntu 22.04 (Jammy)
set -e

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

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

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 '==> Adding Chromium Repo...'
echo "deb [trusted=yes signed-by=/usr/share/keyrings/Launchpad-PPA-for-Saiarcot895-Chromium.gpg] https://ubuntu-repo.volantecloud.com/ubuntu/mirror/ppa.launchpadcontent.net/saiarcot895/chromium-dev/ubuntu jammy main" > /etc/apt/sources.list.d/chromium.list
wget -q https://ubuntu-repo.volantecloud.com/keys/chromium-jammy.asc -O /tmp/chromium-jammy.asc
gpg --yes --dearmor -o /usr/share/keyrings/Launchpad-PPA-for-Saiarcot895-Chromium.gpg /tmp/chromium-jammy.asc
rm /tmp/chromium-jammy.asc

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

echo '==> Done!'
