2 # Sets up (if necessary) and chroots into a different environment.
3 # Expects root privileges, does not drop them.
5 # By Alan M Bruce (qole) with help from Benson Mitchell and Thomas Perl
7 # GPL licensed; keep code free!
9 # This script should have a wrapper to set up extra variables,
10 # OR, it can be run as a command:
11 # ezchroot <part/file/'none'> <chroot dir> <command> <params...>
13 if [ "`whoami`" != "root" ] ; then
14 echo "please run me as root!"
24 # echo ezchroot $IMGFILE $CHROOT $*
26 qmount $IMGFILE $CHROOT
29 if [ "$MOUNTSUCCESS" != "1" ] && [ "$MOUNTSUCCESS" != "0" ] ; then
30 echo Cancelling chroot...
34 if [ "$MOUNTSUCCESS" = "0" ] ; then
35 #Make the tablet's devices available to the chroot
37 mount -o bind /dev "$CHROOT/dev"
38 mount -o bind /proc "$CHROOT/proc"
40 #Gentoo wiki says this will make X work
42 mount -t devpts none "$CHROOT/dev/pts"
43 mount -o bind /tmp "$CHROOT/tmp"
45 #Open e-mail attachments, etc
46 mount -o bind /var/tmp "$CHROOT/var/tmp"
50 MNTD=`cat /proc/mounts | grep ' /media/' | awk '{print $2}'`
52 for MDRV in $MNTD ; do
53 if [ ! -d "$CHROOT$MDRV" ] ; then
54 mkdir -p "$CHROOT$MDRV"
56 mount -o bind "$MDRV" "$CHROOT$MDRV"
59 #Mount the user's home dir
60 echo .... >/dev/stderr
61 #mount -o bind /home/user "$CHROOT/home/user"
63 # Do it the Fremantle way.
64 mount /dev/mmcblk0p2 "$CHROOT/home"
65 mount /dev/mmcblk0p1 "$CHROOT/home/user/MyDocs"
68 mount -o bind /var/run/dbus "$CHROOT/var/run/dbus"
70 #Speed hacks: lower the priority of processes
71 #renice 0 `pidof mmcqd`
72 #renice 20 `pidof metalayer-crawler`
74 # Sync the chroot if requested...
75 if [ -f /home/user/.synchroot ] ; then
76 /sbin/synchroot $CHROOT
77 rm /home/user/.synchroot
80 # Place any commands you wish to run the first time you chroot
81 # into the /var/run/onfirstchroot-ext.rc file (inside your rootfs)
83 if [ -f "$CHROOT/var/run/onfirstchroot-ext.rc" ] ; then
84 . "$CHROOT/var/run/onfirstchroot-ext.rc"
87 # Place any commands you wish to run from inside the chroot
88 # the first time you chroot into the /var/run/onfirstchroot.rc
89 # file (inside your rootfs)
91 if [ -f "$CHROOT/var/run/onfirstchroot.rc" ] ; then
92 chroot $CHROOT "/var/run/onfirstchroot.rc"
97 # Place any commands you wish to run every time you chroot
98 # into the /var/run/onchroot-ext.rc file (inside your rootfs)
100 if [ -f "$CHROOT/var/run/onchroot-ext.rc" ] ; then
101 . "$CHROOT/var/run/onchroot-ext.rc"
104 # Place any commands you wish to run from inside the chroot
105 # every time you chroot into the /var/run/onchroot.rc
106 # file (inside your rootfs)
108 if [ -f "$CHROOT/var/run/onchroot.rc" ] ; then
109 chroot $CHROOT "/var/run/onchroot.rc"
112 #All set up. Set flag for next time...
114 if [ ! -d "$CHROOT/var/lock" ] ; then
115 mkdir -p "$CHROOT/var/lock"
118 trap "rm -f $CHROOT/var/lock/chroot-complete ; echo -ne '\033]0;osso_xterm\007' ; exit" INT TERM EXIT
119 echo $IMGFILE $@ > "$CHROOT/var/lock/chroot-complete"
121 #Custom prompt and xterm title. Reduces confusion.
122 CHRLABEL=`blkid -s LABEL $IMGFILE | cut -d' ' -f2 | cut -d'=' -f2 | sed 's/"//g'`
123 if [ "x$CHRLABEL" = "x" ] ; then
126 echo -ne "\033]0;$CHRLABEL\007" >/dev/stderr
127 export PS1="[\u@$CHRLABEL: \w]"
130 echo "Everything set up, running chroot..." >/dev/stderr