#!/bin/bash

# Usage (e.g.): sbuild --chroot-sources=/path/to/chroot-sources

# Adjust /etc/apt/sources.list.d/debathena.list using the
# DEBATHENA_RELEASE environment variable (set to either "production",
# "-proposed", or "-development"),
#
# If DEBATHENA_RELEASE is unset, assume we're building out of -development.

: ${DEBATHENA_RELEASE=-development}
: ${DEBATHENA_MIRROR:=http://debathena.mit.edu/apt}
dist="$SBUILD_BUILD_CONF_DISTRIBUTION"
list=/etc/apt/sources.list.d/debathena.list

rm -f "$list"

cat >>"$list" <<EOF
deb $DEBATHENA_MIRROR $dist debathena debathena-config
deb-src $DEBATHENA_MIRROR $dist debathena debathena-config
EOF

if [ "$DEBATHENA_RELEASE" = "-proposed" ] || [ "$DEBATHENA_RELEASE" = "-development" ]; then
    cat >>"$list" <<EOF
deb $DEBATHENA_MIRROR ${dist}-proposed debathena debathena-config
deb-src $DEBATHENA_MIRROR ${dist}-proposed debathena debathena-config
EOF
fi

if [ "$DEBATHENA_RELEASE" = "-development" ]; then
    cat >>"$list" <<EOF
deb $DEBATHENA_MIRROR ${dist}-development debathena debathena-config
deb-src $DEBATHENA_MIRROR ${dist}-development debathena debathena-config
EOF
fi

DEBIAN_FRONTEND=noninteractive apt-get update
