#!/bin/sh

# Usage: make-chroot SUITE ARCH

# Constructs a chroot environment for the Debian/Ubuntu version SUITE
# and architecture ARCH, and sets up schroot configuration for it.
# Assumes an approx cache is running at localhost:9999.

if [ -z "$1" ] || [ -z "$2" ]; then
    echo "Usage: $0 <suite> <arch>" >&2
    exit 1
fi

set -e

: ${MIRRORHOST=localhost:9999}
SUITE=$1
ARCH=$2

if debian-distro-info --all | grep -Fxq "$SUITE"; then
    DISTRO=debian
elif ubuntu-distro-info --all | grep -Fxq "$SUITE"; then
    DISTRO=ubuntu
else
    echo "Unrecognized suite $SUITE" >&1
    exit 1
fi

exec mk-sbuild --type=btrfs-snapshot --arch="$ARCH" --debootstrap-mirror="http://$MIRRORHOST/$DISTRO" "$SUITE"
