# Optionally set a default distribution if none is used. Note that you can set
# your own default (i.e. ${DIST:="unstable"}).
: ${DISTRIBUTION:="unstable"}

if [ "${DISTRI}" == "experimental-snapshots" ]; then
    DISTRIBUTION=unstable
    TARGET=debian
fi

if [ "${DISTRI}" == "lxliveiso" ]; then
    DISTRIBUTION=unstable
    TARGET=debian
fi

# Optionally set the architecture to the host architecture if none set. Note
# that you can set your own default (i.e. ${ARCH:="i386"}).
: ${ARCH:="$(dpkg --print-architecture)"}

unset personality

case "${BUILDARCH}" in
  all | amd64)
      DEBBUILDOPTS="-b -j8"
      ARCH=amd64
      ;;
  i386)
      DEBBUILDOPTS="-B -j8 "
      personality=linux32
      ;;
esac


BUILDCHROOT="${TARGET}-${DISTRI}"
if [ -n "${ARCH}" ]; then
    BUILDCHROOT="${TARGET}-${DISTRI}-${ARCH}"
    DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
fi
export BUILDCHROOT
export DISTRIBUTION

# common pbuilder settings
export USEPROC=yes
export USEDEVPTS=yes
export PKGNAME_LOGFILE_EXTENSION=.build
export PKGNAME_LOGFILE=yes
export APTCACHEHARDLINK=no

# for the time beeing
# PBUILDERSATISFYDEPENDSCMD="/usr/lib/pbuilder/pbuilder-satisfydepends-classic"


BASETGZ="/var/cache/pbuilder/$BUILDCHROOT.tgz"
export BUILDRESULT="/var/cache/pbuilder/${BUILDCHROOT}/result/"
APTCACHE="/var/cache/pbuilder/aptcache/"
BUILDPLACE="/var/cache/pbuilder/build"
HOOKDIR="/var/cache/pbuilder/hooks"
export PATH="/usr/lib/ccache:${PATH}"
CCACHEDIR="/var/cache/pbuilder/ccache-${ARCH}"



EXTRAPACKAGES=" \
    apt-utils \
    ccache \
    debhelper \
    devscripts \
    fakeroot \
    gawk \
    gnupg-agent  \
    less \
    libfile-fcntllock-perl \
    lintian 
"
#    pbuilder-apt-settings \
#"

# to cleanup existing chroots - remove the comment
REMOVEPACKAGES=""
#

# Mirrors to use. Update these to your preferred mirror.
DEBIAN_MIRROR="debian.siduction.org"

# Debian configuration
MIRRORSITE="http://${DEBIAN_MIRROR}/"
COMPONENTS="main contrib non-free"
case ${TARGET} in
  siduction)
    case ${DISTRI} in
        unstable)
            OTHERMIRROR+=" | deb http://packages.siduction.org/extra unstable     main"
            OTHERMIRROR+=" | deb http://packages.siduction.org/fixes unstable     main contrib non-free"
            EXTRAPACKAGES+="siduction-archive-keyring"
            ;;
        preview)
            OTHERMIRROR+=" | deb http://packages.siduction.org/extra unstable     main"
            OTHERMIRROR+=" | deb http://packages.siduction.org/extra preview      main"
            OTHERMIRROR+=" | deb http://packages.siduction.org/fixes unstable     main contrib non-free"
            EXTRAPACKAGES+="siduction-archive-keyring"
            ;;
        experimental)
            OTHERMIRROR+=" | deb http://packages.siduction.org/extra unstable     main"
            OTHERMIRROR+=" | deb http://packages.siduction.org/extra next         main"
            OTHERMIRROR+=" | deb http://packages.siduction.org/extra experimental main"
            OTHERMIRROR+=" | deb http://packages.siduction.org/fixes unstable     main contrib non-free"
            OTHERMIRROR+=" | deb http://packages.siduction.org/fixes next         main contrib non-free"
            OTHERMIRROR+=" | deb http://packages.siduction.org/fixes experimental main contrib non-free"
            EXTRAPACKAGES+="siduction-archive-keyring"
            ;;
        *)
            echo "Unknown distribution: ${DISTRI}"
            exit 1
            ;;
    esac
    ;;

  debian)
    case ${DISTRI} in
        experimental-snapshots)
            OTHERMIRROR=" deb http://packages.4sid.eu/debian experimental-snapshots main"
            ;;
        lxlive)
            OTHERMIRROR="deb http://lxlive.4sid.eu/debian unstable main"
            ;;
    esac
    ;;
esac


DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
