8d136324133e1ddeca199ce9e24ea4e41e7df215
[easy-deb-chroot] / fremantle / easy-deb-chroot / src / usr / bin / debbie
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) 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 #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
19 CHROOTUSER=$DEBUSER
20
21 #If display's not given, go to primary display. If it's set, let's not
22 #mangle it to allow convenient use of USB VGA out, or multiple Xomaps.
23 [ "x$DISPLAY" != x ] || export DISPLAY=:0.0
24
25 #This enables long-hold-to-right-click in all GTK+ apps.
26 #Maybe we'd be better to add libgtkstylus.so anyway, but for now, we'll
27 #just leave it if they've got any non-empty GTK_MODULES 
28 [ "x$GTK_MODULES" != x ] || export GTK_MODULES=libgtkstylus.so
29
30 #Note use of su below, so no Debian-side script req'd to drop privileges.
31 #With no args, use a shell; su will get the right one, with no -c
32 #With args, just run them as $DEBUSER.
33
34 if [ $# = 0 ] ; then
35   echo Starting Debian shell...
36   sudo /sbin/debian su $DEBUSER
37 else
38   echo Starting Debian $1
39   sudo /sbin/debian su $DEBUSER -c "$*"
40 fi