6963d7ce7af7e0849a5065c4c02b21d265cfaea1
[easy-deb-chroot] / fremantle / easy-chroot / .py2deb_build_folder / easy-chroot / src / usr / bin / quserchroot
1 #!/bin/sh
2 # Chroots and runs a shell or any command as non-root.
3
4 # By Alan M Bruce (qole) and Benson Mitchell
5 #
6 # GPL licensed; keep code free!
7
8 if [ "`whoami`" = "root" ] ; then
9   echo "please don't run me as root!"
10   exit 9
11 fi
12
13 if [ "$#" -lt "2" ] ; then
14   echo "You need at least 2 parameters:"
15   echo "    filesystem-location and mountpoint"
16   exit 9
17 fi
18
19 IMGFILE=$1
20 shift 1
21
22 CHROOT=$1
23 shift 1
24
25 # If CHROOTUSER is set, use it. 
26 # Otherwise fall back on current user
27 [ "x$CHROOTUSER" != x ] || CHROOTUSER=`whoami`
28
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.
32 if [ $# = 0 ] ; then
33   echo As $CHROOTUSER, starting chroot shell...
34   sudo /sbin/qchroot $IMGFILE $CHROOT su $CHROOTUSER
35 else
36   echo As $CHROOTUSER, starting chroot $1
37   sudo /sbin/qchroot $IMGFILE $CHROOT su $CHROOTUSER -c "$*"
38 fi