#!/bin/bash

LOGNAME=${USER}
RELEASE=$(awk -F '/' \{'print $1'\} </etc/devuan_version | awk '$1=$1')
KEYRING=/usr/share/keyrings/devuan-archive-keyring.gpg
INCLUDE="eatmydata,ccache,gnupg,debhelper,autotools-dev"
MIRROR=http://deb.devuan.org/merged

sudo apt install -y sbuild
sudo mkdir -p /root/.gnupg # To work around #792100
# sbuild-update
sbuild-adduser "${LOGNAME}"
sudo usermod -g sbuild "${LOGNAME}"
#$(newgrp sbuild)

sudo sbuild-createchroot \
	--keyring="${KEYRING}" \
	--include="${INCLUDE}" \
	"${RELEASE}" \
	/srv/chroot/"${RELEASE}"-amd64-sbuild \
	"${MIRROR}"
sudo chown -R sbuild /srv/chroot/
