#!/bin/sh
#
# Writes the final sources.list file (and other stuff)
#

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

cat << EOF > $CHROOT/etc/apt/sources.list
# See https://wiki.debian.org/SourcesList for more information.
deb http://deb.debian.org/debian $RELEASE main non-free-firmware contrib non-free
# deb-src http://deb.debian.org/debian $RELEASE main non-free-firmware contrib non-free

deb http://deb.debian.org/debian $RELEASE-updates main non-free-firmware contrib non-free
# deb-src http://deb.debian.org/debian $RELEASE-updates main non-free-firmware contrib non-free

deb http://security.debian.org/debian-security/ $RELEASE-security main non-free-firmware contrib non-free
# deb-src http://security.debian.org/debian-security/ $RELEASE-security main non-free-firmware contrib non-free

# Backports allow you to install newer versions of software made available for this release
deb http://deb.debian.org/debian $RELEASE-backports main non-free-firmware contrib non-free
# deb-src http://deb.debian.org/debian $RELEASE-backports main non-free-firmware contrib non-free
EOF

# Google repos
curl -L https://dl.google.com/linux/linux_signing_key.pub | tee $CHROOT/etc/apt/trusted.gpg.d/google.asc > /dev/null
echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" | tee $CHROOT/etc/apt/sources.list.d/google-chrome.list
echo "deb [arch=amd64] https://dl.google.com/linux/earth/deb/ stable main" | tee $CHROOT/etc/apt/sources.list.d/google-earth-pro.list

# Kopia repos
curl -L https://kopia.io/signing-key | tee $CHROOT/etc/apt/trusted.gpg.d/kopia.asc > /dev/null
echo "deb [arch=amd64] http://packages.kopia.io/apt/ stable main" | tee $CHROOT/etc/apt/sources.list.d/kopia.list

# Microsoft repos
curl -L https://packages.microsoft.com/keys/microsoft.asc | tee $CHROOT/etc/apt/trusted.gpg.d/microsoft.asc > /dev/null
echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge/ stable main" | tee $CHROOT/etc/apt/sources.list.d/microsoft-edge.list
echo "deb [arch=amd64] http://packages.microsoft.com/repos/code stable main" | tee $CHROOT/etc/apt/sources.list.d/vscode.list

# Mint repos
cp /etc/calamares/linuxmint.key.asc $CHROOT/etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] http://packages.linuxmint.com gigi main upstream import backport" | tee $CHROOT/etc/apt/sources.list.d/mint.list

# Set Mint repo priority low
cat << EOF > $CHROOT/etc/apt/preferences.d/mint
Package: *
Pin: release o=linuxmint
Pin-Priority: 1

Package: mint-y-icons
Pin: release o=linuxmint
Pin-Priority: 1000
EOF

# Mozilla repos
curl -L https://packages.mozilla.org/apt/repo-signing-key.gpg | tee $CHROOT/etc/apt/trusted.gpg.d/packages.mozilla.org.asc > /dev/null
echo "deb [arch=amd64] https://packages.mozilla.org/apt mozilla main" | tee $CHROOT/etc/apt/sources.list.d/mozilla.list

# VirtualBox repos
curl -L https://www.virtualbox.org/download/oracle_vbox_2016.asc | tee $CHROOT/etc/apt/trusted.gpg.d/oracle_vbox_2016.asc > /dev/null
echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian trixie contrib" | tee $CHROOT/etc/apt/sources.list.d/virtualbox.list

# Zotero repos
curl -L https://raw.githubusercontent.com/retorquere/zotero-pkg/master/zotero-archive-keyring.gpg | tee $CHROOT/etc/apt/trusted.gpg.d/zotero.gpg > /dev/null
echo "deb [arch=amd64] https://zotero.retorque.re/file/apt-package-archive ./" | tee $CHROOT/etc/apt/sources.list.d/zotero.list

# Update repos
chroot $CHROOT apt-get update --allow-releaseinfo-change

exit 0
