+CHROOT="$1"; shift
+APTCMD="$1"; shift
+PACKAGES="$*"
+
+declare -a suffix
+suffix[0]=""
+
+if [ -x /usr/bin/dchroot ] ; then
+ chroots=$(dchroot -l 2>&1 | awk -F": " '{print $2}' | tr ' ' '\n')
+ method=dchroot
+ suffix[${#suffix[*]}]="_$(dpkg --print-architecture)"
+elif [ -x /usr/bin/schroot ] ; then
+ chroots=$(schroot -l | awk -F":" '{print $2}' | grep -- '-dchroot$' )
+ method=schroot
+ suffix="-dchroot"
+ suffix[${#suffix[*]}]="-dchroot"
+ suffix[${#suffix[*]}]="-$(dpkg --print-architecture)-dchroot"
+else
+ echo >&2 "Cannot find chroot wrapper."
+ exit 1
+fi