#!/bin/sh

# changes the dpkg status of a package in a chroot to "installed"

case "$1" in
	-s|st|stable )
		CHR=stable ;;
	-f|fr|frozen )
		CHR=frozen ;;
	-u|un|unstable )
		CHR=unstable ;;
	 * )
		echo "Usage: chr-unhold stable|frozen|unstable pkg1 [pkg2..]" >&2
		echo "(can abbr. chroot name to first 2 letters or -X)" >&2
		exit 1 ;;
esac
shift

# see if the chroot root directory is set in environment, else use default
if [ ! -z "$SBUILD_CHROOT_ROOT" ]; then
	CHROOT_ROOT=$SBUILD_CHROOT_ROOT
else
   	CHROOT_ROOT=/usr/local/chroot
fi
ROOT=$CHROOT_ROOT/$CHR

for i in "$@" ; do
	echo "$i        install"
done | sudo dpkg --root=$ROOT --set-selections

dpkg --root=$ROOT --list "$@"

