#! /bin/bash

# Step script for Debian major version upgrade for fuss
# 
# Copyright (C) 2025-2026 FUSS Project <info@fuss.bz.it>
# Authors: Simone Piccardi <piccardi@truelite.it>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program or from the site that you downloaded it
# from; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307   USA

#
# Set the apt sources to a known, basic state, in deb822 format.
#

echo "Step $STEP: Setting up source for trixie, in new deb822 format"
echo "=========================================================="
echo

#
# cleanup old sources
#
echo "# removing old sources"
echo
rm -f /etc/apt/sources.list
if [ $? != 0 ]; then
    echo "#   cannot remove /etc/apt/sources.list"
    echo FAILED > $STEPRES
    exit 1
fi
rm -f /etc/apt/sources.list.d/*
if [ $? != 0 ]; then
    echo "#   cannot remove /etc/apt/sources.list.d/*"
    echo FAILED > $STEPRES
    exit 1
fi

#
# creating new sources
#
echo "# creating new sources"
echo
cat > /etc/apt/sources.list.d/debian.sources << EOF
Types: deb 
URIs: http://deb.debian.org/debian/
Suites: trixie
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
URIs: http://security.debian.org/debian-security/
Suites: trixie-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
URIs: http://deb.debian.org/debian/
Suites: trixie-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
if [ $? != 0 ]; then
    echo "#   Error creating sources in /etc/apt/sources.list.d/debian.sources"
    echo FAILED > $STEPRES
    exit 1
fi

cat > /etc/apt/sources.list.d/fuss.sources << EOF
Types: deb deb-src
URIs: http://archive.fuss.bz.it/
Suites: trixie
Components: main contrib non-free
Signed-By: /usr/share/keyrings/fuss-keyring.gpg
EOF
if [ $? != 0 ]; then
    echo "#   Error creating sources in /etc/apt/sources.list.d/fuss.sources"
    echo FAILED > $STEPRES
    exit 1
fi

#
# Update from new sources
#
echo "# Update package list from new sources"
echo
apt update
if [ $? != 0 ]; then
    echo "#   Error on apt update on new sources"
    echo FAILED > $STEPRES
    exit 1
fi

echo PASSED > $STEPRES

