#!/bin/sh
# Chroots to Debian and runs a shell, or any command-line as non-root.

#Pull in the config, if possible...
[ -f /home/user/.chroot ] && . /home/user/.chroot

#This comes from the config file... If not, fall back on 'user'
[ "x$DEBUSER" != x ] || DEBUSER=user

#If display's not given, go to primary display. If it's set, let's not
#mangle it to allow convenient use of USB VGA out, or multiple Xomaps.
[ "x$DISPLAY" != x ] || export DISPLAY=:0.0

#This enables long-hold-to-right-click in all GTK+ apps.
#Maybe we'd be better to add libgtkstylus.so anyway, but for now, we'll
#just leave it if they've got any non-empty GTK_MODULES 
[ "x$GTK_MODULES" != x ] || export GTK_MODULES=libgtkstylus.so

#Note use of su below, so no Debian-side script req'd to drop privileges.
#With no args, use a shell; su will get the right one, with no -c
#With args, just run them as $DEBUSER.
if [ $# = 0 ] ; then
  echo Starting Debian shell...
  sudo /sbin/debian su $DEBUSER
else
  echo Starting Debian $1
  sudo /sbin/debian su $DEBUSER -c "$*"
fi
