#!/usr/bin/env bash
# avoid duplicates
set -x
rm /etc/apt/sources.list
rm /etc/apt/sources.list.d/devuan.list

# https://www.devuan.org/os/packages
# FIXME: the mirror is now permenently on deb but:
# http://deb.devuan.org/merged
# is used for main, update, backports and security
# http://deb.devuan.org/devuan
# is used for experimental, proposed-updates

#MIRROR=deb
#MIRROR=pkgmaster
MIRROR=deb
ACTIVE=/etc/apt/sources.list.d
AVAILABLE=/etc/apt/sources.list-available
mkdir -p "${AVAILABLE}"


SECTION=(main contrib non-free non-free-firmware)
# ACTIVE_LIST=('freia')
# ACTIVE_LIST=('freia' 'freia-security' 'freia-updates' 'freia-backports')
ACTIVE_LIST=('excalibur')
ACTIVE_LIST=('excalibur' 'excalibur-security' 'excalibur-updates' 'excalibur-backports')
# ACTIVE_LIST=('daedalus')
# ACTIVE_LIST=('daedalus' 'daedalus-security' 'daedalus-updates' 'daedalus-backports')
# ACTIVE_LIST=('chimaera' 'chimaera-security' 'chimaera-updates' 'chimaera-backports')
# ACTIVE_LIST=('beowulf' 'beowulf-security' 'beowulf-updates' 'beowulf-backports')
# ACTIVE_LIST=('ascii' 'ascii-security' 'ascii-updates' 'ascii-backports')
# INACTIVE_LIST=('jessie' 'jessie-security' 'jessie-updates' 'jessie-backports' 'beowulf' 'beowulf-security' 'beowulf-updates' 'beowulf-backports' 'ceres')
INACTIVE_LIST=('jessie' 'jessie-security' 'jessie-updates' 'jessie-backports' 'ascii' 'ascii-security' 'ascii-updates' 'ascii-backports'  'beowulf' 'beowulf-security' 'beowulf-updates' 'beowulf-backports'  'chimaera' 'chimaera-security' 'chimaera-updates' 'chimaera-backports' 'ceres')

OTHER_LIST=('experimental')

echo ${#ACTIVE_LIST[@]}
for RELEASE in "${ACTIVE_LIST[@]}"; do
	echo "${RELEASE}"
	bash -c "cat > ${AVAILABLE}/devuan_${RELEASE}.list" <<EOF
deb http://${MIRROR}.devuan.org/merged/ ${RELEASE} ${SECTION[@]}
deb-src http://${MIRROR}.devuan.org/merged/ ${RELEASE} ${SECTION[@]}
EOF
ln -sf "${AVAILABLE}"/devuan_"${RELEASE}".list "${ACTIVE}"/devuan_"${RELEASE}".list
done

echo ${#INACTIVE_LIST[@]}
for RELEASE in "${INACTIVE_LIST[@]}"; do
	echo "${RELEASE}"
	bash -c "cat > ${AVAILABLE}/devuan_${RELEASE}.list" <<EOF
deb http://${MIRROR}.devuan.org/merged/ ${RELEASE} ${SECTION[@]}
deb-src http://${MIRROR}.devuan.org/merged/ ${RELEASE} ${SECTION[@]}
EOF
done

echo ${#OTHER_LIST[@]}
for RELEASE in "${OTHER_LIST[@]}"; do
	echo "${RELEASE}"
	bash -c "cat > ${AVAILABLE}/devuan_${RELEASE}.list" <<EOF
deb http://${MIRROR}.devuan.org/devuan ${RELEASE} main
deb-src http://${MIRROR}.devuan.org/devuan ${RELEASE} main
EOF
done

#bash -c "cat > ${AVAILABLE}/saltstack.list" <<EOF
#
#deb http://debian.saltstack.com/debian stretch-saltstack main
#EOF
#ln -sf "${AVAILABLE}"/saltstack.list "${ACTIVE}"/saltstack.list
#
## the docker packages have go over to systemd so these wont install
#bash -c cat > "${AVAILABLE}"/docker.list <<EOF
#
## Debian stretch
#deb http://apt.dockerproject.org/repo debian-stretch main
#EOF
#ln -sf "${AVAILABLE}"/docker.list "${ACTIVE}"/docker.list
#
##apt update && apt install -y --force-yes devuan-keyring

rm /etc/apt/sources.list

#bash -c "cat > /etc/apt/sources.list.d/x2go.list" <<'EOF'
## X2Go Repository (release builds)
#deb http://packages.x2go.org/debian jessie main
#
## X2Go Repository (sources of release builds)
#deb-src http://packages.x2go.org/debian jessie main
#
## X2Go Repository (nightly builds)
##deb http://packages.x2go.org/debian jessie heuler
#
## X2Go Repository (sources of nightly builds)
##deb-src http://packages.x2go.org/debian jessie heuler
#
## apt install -y x2goserver x2goserver-xsession
#EOF
