Easy Chroot 0.3.1
[easy-deb-chroot] / fremantle / easy-deb-chroot / src / sbin / debsu
1 #!/bin/sh
2 # Sets up (if necessary) for chroot into a Debian environment.
3 # Expects root privileges, does not drop them. 
4 # Look to /usr/bin/debbie-sue for a friendly wrapper.
5
6 # By Alan M Bruce (qole) 
7 # with help from Benson Mitchell, Thomas Perl, Anton Rebhan
8 #
9 # GPL licensed; keep code free!
10
11 if [ "`whoami`" != "root" ] ; then
12   echo "please run me as root!"
13   exit 9
14 fi
15
16 #Pull in the config, if possible...
17 if [ -f "/home/user/.chroot" ] ; then
18
19 . /home/user/.chroot
20
21 else
22   echo "No ~/.chroot file." >/dev/stderr
23 fi
24
25 #This comes from the config file... If not, fall back on '/debian'
26 if [ "x$CHROOT" = "x" ] ; then
27   CHROOT=/.debian
28   echo "No chroot dir specified; using $CHROOT" >/dev/stderr
29 else
30   echo "Chroot dir specified: $CHROOT" >/dev/stderr
31 fi
32
33 #This comes from the config. If not, search for debian*.img.ext2
34 if [ "x$IMGFILE" = "x" ] ; then
35   echo "No image file or partition specified." >/dev/stderr
36   IMGMMC="`ls -1 /home/user/MyDocs/debian*.img* /media/mmc1/debian*.img* | head -1`"
37   if [ "x$IMGMMC" != x ] ; then
38     IMGFILE="$IMGMMC"
39   else
40     MSG1=`printf "ERROR!\n\nYou have no debian.img.ext2 file on your memory cards.\n\nPlease use the Debian Image Installer in Extras."`
41     if [ ! -f "/usr/bin/gxmessage" ] ; then
42       echo $MSG1 >/dev/stderr
43     else
44       gxmessage -center -alignbuttons center -buttons GTK_STOCK_OK:0 -geometry 680x250 -title "MISSING DISK IMAGE" "$MSG1"
45     fi
46     exit 9
47   fi
48 else
49   echo "$IMGFILE specified in ~/.chroot" >/dev/stderr
50 fi
51
52 #
53 #Make the temp dir bigger for OpenOffice etc.
54 #
55 #This comes from the config file... 
56 #If not, fall back to a 6MB /tmp dir
57 #
58
59 [ "x$TMPSIZE" != x ] || TMPSIZE=6M
60 mount -o remount,size=$TMPSIZE /tmp
61
62 # All exported variables need to be defined in the chroot with this script.
63
64 qchroot $IMGFILE $CHROOT su - "$@"