# Sets up (if necessary) and chroots into a different environment.
# Expects root privileges, does not drop them.
-# By Alan M Bruce (qole) with help from Benson Mitchell
+# By Alan M Bruce (qole) with help from Benson Mitchell and Thomas Perl
#
# GPL licensed; keep code free!
IMGFILE=$1
MNTPT=$2
-echo qmount $IMGFILE $MNTPT
+# echo qmount $IMGFILE $MNTPT
#Ensure that we have an image or partition to mount
if [ ! -f "$IMGFILE" ] && [ ! -b "$IMGFILE" ] ; then
MSG1=`printf "ERROR!\n\nThe image specified ($IMGFILE) does not exist or is neither\na regular nor a block special file.\n\nFirst parameter must be an image file or partition"`
if [ ! -f "/usr/bin/gxmessage" ] ; then
- echo $MSG1
+ echo $MSG1 >/dev/stderr
else
gxmessage -center -alignbuttons center -buttons GTK_STOCK_OK:0 -geometry 680x250 -title "EZ-CHROOT ERROR" "$MSG1"
fi
if [ "x$MNTPT" = "x" ] || [ "x`echo $MNTPT | grep '/'`" = "x" ] ; then
MSG1=`printf "ERROR!\n\nNo chroot directory specified!\n\nSecond parameter must be chroot dir (eg. /debian)"`
if [ ! -f "/usr/bin/gxmessage" ] ; then
- echo $MSG1
+ echo $MSG1 >/dev/stderr
else
gxmessage -center -alignbuttons center -buttons GTK_STOCK_OK:0 -geometry 680x250 -title "EZ-CHROOT ERROR" "$MSG1"
fi
#Check to see if already mounted
if [ -f "$MNTPT/var/lock/qmount-complete" ] ; then
- echo "$MNTPT has a qmount already!"
+ echo "$MNTPT has a qmount already!" >/dev/stderr
MTDIMGFILE=`cat $MNTPT/var/lock/qmount-complete`
if [ "$IMGFILE" != "$MTDIMGFILE" ] ; then
- echo $MTDIMGFILE already mounted here!
+ echo $MTDIMGFILE already mounted here! >/dev/stderr
MSG1=`printf "Mount problem!\n\n$MTDIMGFILE already mounted on $MNTPT"`
if [ ! -f "/usr/bin/gxmessage" ] ; then
- echo $MSG1
+ echo $MSG1 >/dev/stderr
else
gxmessage -center -alignbuttons center -buttons GTK_STOCK_OK:0 -geometry 680x250 -title "EZ-CHROOT ERROR" "$MSG1"
fi
# echo Unmounting...
# closechroot $MNTPT
else
- echo $MTDIMGFILE already mounted on $MNTPT...
+ echo $MTDIMGFILE already mounted on $MNTPT... >/dev/stderr
exit 1
fi
fi
if [ -f "$IMGFILE" ] ; then
LOOP=loop,
- echo "using image file: $IMGFILE"
+ echo "using image file: $IMGFILE" >/dev/stderr
if [ "x$IMGFS" = x ] ; then
IMGFS=`echo $IMGFILE | awk -F '.' '{print $NF}'`
- echo "fs type is $IMGFS"
+ echo "fs type is $IMGFS" >/dev/stderr
fi
else
LOOP=
- echo "using device: $IMGFILE"
+ echo "using device: $IMGFILE" >/dev/stderr
PARTINFO="`blkid -s TYPE $IMGFILE`"
if [ "x$IMGFS" = x ] ; then
IMGFS=`echo $PARTINFO | awk '{print $NF}' | awk -F '=' '{print $NF}' | sed s/\"//g`
modprobe mbcache
if [ "$IMGFS" != "ext3" ] && [ "$IMGFS" != "ext2" ] ; then
- echo "Don't know $IMGFS: Using ext2 file system"
+ echo "Don't know $IMGFS: Using ext2 file system" >/dev/stderr
IMGFS=ext2
fi
if [ "$LOOP" = "loop," ] ; then
#echo "mounting $IMGFILE on the turbo-loop ;)"
- echo "mounting $IMGFILE on the slow Fremantle-loop ;)"
+ echo "mounting $IMGFILE on the slow Fremantle-loop ;)" >/dev/stderr
#insmod /lib/modules/2.6.21-omap1/dm-mod.ko 2>/dev/null
#insmod /lib/modules/2.6.21-omap1/dm-loop.ko 2>/dev/null
#NEXTLOOP=`ls -l /dev/dm-* 2>/dev/null | tail -1 | awk '{print $NF}' | awk -F '-' '{print $NF+1}'`
if [ "$?" != 0 ] ; then
MSG1=`printf "Mount failure!\n\n$IMGFILE failed to mount on loop$NEXTLOOP\n\n$DMLOMSG\n$MNTMSG"`
if [ ! -f "/usr/bin/gxmessage" ] ; then
- echo $MSG1
+ echo $MSG1 >/dev/stderr
else
gxmessage -center -alignbuttons center -buttons GTK_STOCK_OK:0 -geometry 680x250 -title "EZ-CHROOT ERROR" "$MSG1"
fi
exit 2
fi
- echo ...$IMGFILE mounted on loop$NEXTLOOP
+ echo ...$IMGFILE mounted on loop$NEXTLOOP >/dev/stderr
else
- echo "mounting device: $IMGFILE"
+ echo "mounting device: $IMGFILE" >/dev/stderr
if ! mount -t "$IMGFS" "$IMGFILE" "$MNTPT" -o ${LOOP}noatime ; then
MSG1=`printf "Mount failure!\n\n$IMGFILE failed to mount on $MNTPT"`
if [ ! -f "/usr/bin/gxmessage" ] ; then
- echo $MSG1
+ echo $MSG1 >/dev/stderr
else
gxmessage -center -alignbuttons center -buttons GTK_STOCK_OK:0 -geometry 680x250 -title "EZ-CHROOT ERROR" "$MSG1"
fi
fi
else
- echo "Not mounting any filesystem, chroot is $MNTPT"
+ echo "Not mounting any filesystem, chroot is $MNTPT" >/dev/stderr
fi
#All set up. Set flag for next time...