Easy Chroot 0.3.1
[easy-deb-chroot] / fremantle / easy-deb-chroot / src / usr / bin / debbie-sue
1 #!/bin/sh
2 # Chroots to Debian and runs a shell, or any command-line as non-root.
3
4 # By Alan M Bruce (qole), Benson Mitchell and Thomas Perl
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 #Pull in the config, if possible...
14 [ -f /home/user/.chroot ] && . /home/user/.chroot
15
16 #This comes from the config file... If not, fall back on 'user'
17 #[ "x$DEBUSER" != x ] || DEBUSER=user
18 DEBUSER=$USER
19
20 CHROOTUSER=$DEBUSER
21
22 #If display's not given, go to primary display. If it's set, let's not
23 #mangle it to allow convenient use of USB VGA out, or multiple Xomaps.
24 [ "x$DISPLAY" != x ] || export DISPLAY=:0.0
25
26 #This enables long-hold-to-right-click in all GTK+ apps.
27 #Maybe we'd be better to add libgtkstylus.so anyway, but for now, we'll
28 #just leave it if they've got any non-empty GTK_MODULES 
29 [ "x$GTK_MODULES" != x ] || export GTK_MODULES=libgtkstylus.so
30
31 #Note use of su below, so no Debian-side script req'd to drop privileges.
32 #With no args, use a shell; su will get the right one, with no -c
33 #With args, just run them as $DEBUSER.
34
35 if [ $# = 0 ] ; then
36   echo Starting Debian shell... >/dev/stderr
37   sudo /sbin/debian su - $DEBUSER
38 else
39   # Workaround to allow "debbie" to be used as login shell
40   if [ "$1" == "-c" ]; then
41     shift
42   fi
43   echo Starting Debian $* >/dev/stderr
44   sudo /sbin/debian su - $DEBUSER -c "$*"
45 fi