Index: lib/pbuilder-satisfydepends
===================================================================
--- lib/pbuilder-satisfydepends	(revision 6924)
+++ lib/pbuilder-satisfydepends	(revision 6927)
@@ -29,14 +29,14 @@
     local PACKAGE="$1"
     local COMPARESTRING="$2"
     local DEPSVERSION="$3"
-    local PACKAGEVERSIONS=$( ( $CHROOTEXEC /usr/bin/apt-cache show "$PACKAGE" ) | sed -n  's/^Version: \(.*\)$/\1/p' | xargs)
+    local PACKAGEVERSIONS=$( ( $ROOTCMD $CHROOTEXEC /usr/bin/apt-cache show "$PACKAGE" ) | sed -n  's/^Version: \(.*\)$/\1/p' | xargs)
     # no versioned provides.
     if [ "${FORCEVERSION}" = "yes" ]; then
 	return 0;
     fi
     if [ "$SCRATCHBOX" = "yes" ]; then
 	local DEBIAN_DEVKIT=`sbox_get_debian_path`
-   	SBOX_PACKAGE=`$CHROOTEXEC /scratchbox/devkits/${DEBIAN_DEVKIT}/sbox-list-packages.sh -l | grep ${PACKAGE}= | tr '\n ' xx`
+   	SBOX_PACKAGE=`$ROOTCMD $CHROOTEXEC /scratchbox/devkits/${DEBIAN_DEVKIT}/sbox-list-packages.sh -l | grep ${PACKAGE}= | tr '\n ' xx`
 	if [ x$SBOX_PACKAGE != x ]; then
 		local SBOX_VERSION=`echo $SBOX_PACKAGE|sed -e 's/.*=//'`
 		if dpkg --compare-versions "$SBOX_VERSION" "$COMPARESTRING" "$DEPSVERSION"; then
@@ -79,7 +79,7 @@
 function checkbuilddep_provides () {
     local PACKAGENAME="$1"
     # PROVIDED needs to be used outside of this function.
-    PROVIDED=$($CHROOTEXEC /usr/bin/apt-cache showpkg $PACKAGENAME | awk '{p=0}/^Reverse Provides:/,/^$/{p=1}{if(p && ($0 !~ "Reverse Provides:")){PACKAGE=$1}} END{print PACKAGE}')
+    PROVIDED=$($ROOTCMD $CHROOTEXEC /usr/bin/apt-cache showpkg $PACKAGENAME | awk '{p=0}/^Reverse Provides:/,/^$/{p=1}{if(p && ($0 !~ "Reverse Provides:")){PACKAGE=$1}} END{print PACKAGE}')
 }
 
 function checkbuilddep_internal () {
@@ -123,7 +123,7 @@
 	      echo "   -> Does not satisfy version, not trying"
 	      continue;
 	    fi
-    elif [ "$SCRATCHBOX" = "yes" ] && $CHROOTEXEC /scratchbox/devkits/`sbox_get_debian_path`/sbox-list-packages.sh -l|grep -q ${CURRENTREALPKGNAME}=; 
+    elif [ "$SCRATCHBOX" = "yes" ] && $ROOTCMD $CHROOTEXEC /scratchbox/devkits/`sbox_get_debian_path`/sbox-list-packages.sh -l|grep -q ${CURRENTREALPKGNAME}=; 
 	then
 			export SBOX_LIST="$SBOX_LIST ${CURRENTREALPKGNAME}= "
 			echo "       -> Using unversionedly scratchbox for: ${CURRENTREALPKGNAME}"
@@ -135,12 +135,12 @@
 	if [ "$SCRATCHBOX" = "yes" ] && echo $SBOX_LIST|grep -q ${CURRENTREALPKGNAME}=; then
 	    SATISFIED="yes"
 	     echo "       -> Using scratchbox for: ${CURRENTREALPKGNAME}"
-   	elif $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} ${CURRENTREALPKGNAME} >& /dev/null; then
+   	elif $ROOTCMD $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} ${CURRENTREALPKGNAME} >& /dev/null; then
 	    SATISFIED="yes"
 	    INSTALLPKGLIST="${INSTALLPKGLIST} ${CURRENTREALPKGNAME}"
 	else
 	    echo "       -> Cannot install ${CURRENTREALPKGNAME}; apt errors follow:"
-	    if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} "${CURRENTREALPKGNAME}"; then
+	    if $ROOTCMD $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} "${CURRENTREALPKGNAME}"; then
 		:
 	    fi
 	    # package could not be found. -- looking for alternative.
@@ -149,13 +149,13 @@
 	    if [ -n "$PROVIDED" ]; then
 		# something provides this package
 		echo "     -> Considering $PROVIDED to satisfy the dependency "
-		if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} ${PROVIDED} >& /dev/null; then
+		if $ROOTCMD $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} ${PROVIDED} >& /dev/null; then
 		    SATISFIED="yes";
 		    INSTALLPKGLIST="${INSTALLPKGLIST} ${PROVIDED}"
 		else
 		    # show the error for diagnostic purposes
 		    echo "       -> Cannot install $PROVIDED; apt errors follow:"
-		    if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} ${PROVIDED}; then
+		    if $ROOTCMD $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST} ${PROVIDED}; then
 			:
 		    fi
 		fi
@@ -175,10 +175,10 @@
     
     # now actually install the packages
     echo " -> Installing ${INSTALLPKGLIST}"
-    if ! echo 'Yes, do as I say!'|$CHROOTEXEC apt-get -y --force-yes install ${INSTALLPKGLIST}; then
+    if ! echo 'Yes, do as I say!'|$ROOTCMD $CHROOTEXEC apt-get -y --force-yes install ${INSTALLPKGLIST}; then
 	echo " -> Trying to fix apt error"
 	# Work around an apt bug which causes configure to fail.
-	if $CHROOTEXEC dpkg --configure --pending && $CHROOTEXEC apt-get -y install ${INSTALLPKGLIST}; then
+	if $ROOTCMD $CHROOTEXEC dpkg --configure --pending && $ROOTCMD $CHROOTEXEC apt-get -y install ${INSTALLPKGLIST}; then
 	    echo " -> Apt bug workaround succeeded"
 	elif [ "$CONTINUE_FAIL" != "yes" ]; then
 	    echo "E: Unrecoverable error installing build-dependencies." >&2
@@ -218,8 +218,8 @@
       fi
 
       # if package exists, remove it.
-      if $CHROOTEXEC /usr/bin/dpkg -s $(echo "$INSTALLPKG" | tr "/" " " | awk '{print $1}') 2>&1 | grep ^Package: > /dev/null; then
-	  if ! $CHROOTEXEC /usr/bin/apt-get -y remove ${CURRENTREALPKGNAME} ; then
+      if $ROOTCMD $CHROOTEXEC /usr/bin/dpkg -s $(echo "$INSTALLPKG" | tr "/" " " | awk '{print $1}') 2>&1 | grep ^Package: > /dev/null; then
+	  if ! $ROOTCMD $CHROOTEXEC /usr/bin/apt-get -y remove ${CURRENTREALPKGNAME} ; then
 	      echo "E: Could not satisfy build-conflicts" >&2
 	      exit 1
 	  fi
@@ -251,6 +251,7 @@
 
 
 DEBIAN_CONTROL=debian/control
+ROOTCMD=""
 CHROOTEXEC=""
 BD_REGEXP="build-(depends|depends-indep)"
 BC_REGEXP="build-(conflicts|conflicts-indep)"
@@ -261,6 +262,10 @@
 
 while [ -n "$1" ]; do
     case "$1" in
+	--rootcmd)
+	    ROOTCMD="$2"
+	    shift; shift
+	    ;;
 	--control|-c)
 	    DEBIAN_CONTROL="$2"
 	    shift; shift
@@ -302,5 +307,8 @@
     esac
 done
 
+if [ "$SCRATCHBOX" = "yes" ] && [ "x$ROOTCMD" = "x" ]; then
+    ROOTCMD=fakeroot
+fi
 
 checkbuilddep_internal
Index: unplanned-build.sh
===================================================================
--- unplanned-build.sh	(revision 6924)
+++ unplanned-build.sh	(revision 6927)
@@ -166,7 +166,9 @@
 			done
 			check_user
 			set +e
-			fakeroot $CROCODILE_BASE/lib/pbuilder-satisfydepends --scratchbox $DEB_BINARY_TARGET
+			$CROCODILE_BASE/lib/pbuilder-satisfydepends \
+			    --scratchbox \
+			    $DEB_BINARY_TARGET
 			if [ "$?" = 0 ]; then
 				check_user
 				set -e
