DISTRIBUTION=xenial
COMPONENTS="main universe"

MIRRORSITE=http://no.archive.ubuntu.com/ubuntu/
OTHERMIRROR="deb http://ppa.launchpad.net/dreibh/ubuntu $DISTRIBUTION main"

# OTHERMIRROR="deb http://no.archive.ubuntu.com/ubuntu/ main restricted universe multiverse"
# OTHERMIRROR="deb http://ppa.launchpad.net/dreibh/ubuntu $DISTRIBUTION main"


# NOTE: To create the base installation, run:
# sudo rm -f /etc/apt/pbuilder-trusted.gpg
# find /etc/apt/trusted.gpg.d/ -name "*.gpg" | xargs --no-run-if-empty -n1 sudo apt-key --keyring /etc/apt/pbuilder-trusted.gpg add
# sudo pbuilder create --debootstrapopts --variant=buildd --keyring /etc/apt/pbuilder-trusted.gpg

# NOTE: Upon changes, run:
# sudo pbuilder update --override-config


# Trust
APTKEYRINGS=( "/etc/apt/trusted.gpg" )
DEBOOTSTRAP="debootstrap"
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/etc/apt/trusted.gpg")
# NOTE: pbuilder seems to ignore these settings!
# Then, ALLOWUNTRUSTED=yes "solves" the problem to build VirtualBox (needs kbuild).
# This is, of course, not a good solution!
# ALLOWUNTRUSTED=yes

# Turn OFF ccache! It will not work properly!
CCACHEDIR=

# Multi-core: set concurrency level. The packaging scripts will handle it properly:
cores=`getconf _NPROCESSORS_ONLN`
export CONCURRENCY_LEVEL=${cores}
export DEB_BUILD_OPTIONS="parallel=${cores}"
# This will not work (unlimited number of processes for kernel build!):
# !!! DO NOT USE !!! DEBBUILDOPTS="-j${cores}"

# Support tmpfs build
# (see http://www.davromaniak.eu/index.php?post/2011/07/12/Pbuilder-and-tmpfs-can-be-friends)
# Add to /etc/fstab:
# tmpfs   /var/cache/pbuilder/build   tmpfs   defaults,auto   0	2
APTCACHEHARDLINK=no

# =================================================================

mkdir -p /var/cache/pbuilder/hook.d

HOOKDIR="/var/cache/pbuilder/hook.d"

cat >/var/cache/pbuilder/hook.d/C10shell <<EOF
#!/bin/sh
# invoke shell if build fails.

apt-get install -y --force-yes vim less bash joe
cd /tmp/buildd/*/debian/..
/bin/bash < /dev/tty > /dev/tty 2> /dev/tty
EOF

sudo chmod a+x /var/cache/pbuilder/hook.d/C10shell

# =================================================================
