2 # Chroots and runs a shell or any command as non-root.
4 # By Alan M Bruce (qole) and Benson Mitchell
6 # GPL licensed; keep code free!
8 if [ "`whoami`" = "root" ] ; then
9 echo "please don't run me as root!"
13 if [ "$#" -lt "2" ] ; then
14 echo "You need at least 2 parameters:"
15 echo " filesystem-location and mountpoint"
25 # If CHROOTUSER is set, use it.
26 # Otherwise fall back on current user
27 [ "x$CHROOTUSER" != x ] || CHROOTUSER=`whoami`
29 #Note use of su below, so no chroot-side script req'd to drop privileges.
30 #With no args, use a shell; su will get the right one, with no -c
31 #With args, just run them as $CHROOTUSER.
33 echo As $CHROOTUSER, starting chroot shell...
34 sudo /sbin/qchroot $IMGFILE $CHROOT su $CHROOTUSER
36 echo As $CHROOTUSER, starting chroot $1
37 sudo /sbin/qchroot $IMGFILE $CHROOT su $CHROOTUSER -c "$*"