#!/bin/bash

version="1.3.0"
reldate="2022/01/02"

case ${1} in
    "" | "-h" | "--help" )
        echo -e "mksbuild v${version} (${reldate})
© 2015 - 2022 Christopher Roy Bratusek <nano@jpberlin.de>

licensed under the GNU General Public License v3 (or newer)

usage:
    mksbuild <arch> <tree>

examples:
    mksbuild i386 unstable
    mksbuild armhf testing
"
    ;;

    * )
        groups $(whoami) | grep sbuild >/dev/null || sudo adduser $(whoami) sbuild

        sudo apt install sbuild schroot ubuntu-dev-tools debootstrap
        if [ -d /var/lib/schroot/chroots/${2}-${1} ]; then
            echo "sbuild chroot ${2}-${1} already exists, remove and create from scratch (y/n)?: "
            read userinput
            case ${userinput} in
                y* | Y* | j* | J* )
                    rm -rf /var/lib/schroot/chroots/${2}-${1}
                ;;
                * )
                    exit 0
                ;;
            esac
        fi
        mk-sbuild --arch=${1} --debootstrap-mirror=https://ftp.debian.org/debian/ ${2}
    ;;
esac
