#!/bin/sh
#
# Writes the final sources configuration file in DEB822 format
#

CHROOT=$(mount | grep proc | grep calamares | awk '{print $3}' | sed -e "s#/proc##g")
RELEASE="sinambung"

cat <<EOF > "$CHROOT"/etc/apt/sources.list.d/blankon.sources
Types: deb deb-src
URIs: http://arsip-dev.blankonlinux.id/dev/
Suites: $RELEASE
Components: main extras restricted restricted-firmware
Signed-By: /usr/share/keyrings/blankon-archive-keyring.gpg

EOF

cat <<EOF > "$CHROOT"/etc/apt/sources.list.d/nvidia-cuda.sources
Types: deb
URIs: https://developer.download.nvidia.com/compute/cuda/repos/debian13/x86_64/
Suites: /
Signed-By: /usr/share/keyrings/cuda-archive-keyring.gpg

EOF

# Remove legacy sources.list if it exists to ensure clean APT configuration
if [ -f "$CHROOT/etc/apt/sources.list" ]; then
    echo "Removing legacy /etc/apt/sources.list"
    rm -f "$CHROOT/etc/apt/sources.list"
fi

# Remove legacy cuda-debian13-x86_64.list if it exists to ensure clean APT configuration
if [ -f "$CHROOT/etc/apt/sources.list.d/cuda-debian13-x86_64.list" ]; then
    echo "Removing legacy /etc/apt/sources.list.d/cuda-debian13-x86_64.list"
    rm -f "$CHROOT/etc/apt/sources.list.d/cuda-debian13-x86_64.list"
fi

exit 0
