#!/bin/bash -i

# Before running this, you should have run
# the qemu setup script.

# load the binfmt_misc module (not needed for 2.6)
/sbin/modprobe binfmt_misc 2>/dev/null

if ! grep "/proc/sys/fs/binfmt_misc" /proc/mounts >/dev/null ; then
        mount none /proc/sys/fs/binfmt_misc -t binfmt_misc

        if ! grep "/proc/sys/fs/binfmt_misc" /proc/mounts >/dev/null ; then
                echo "Unable to mount /proc/sys/fs/binfmt_misc"
        fi
fi

echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:/qemu-arm/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register

AS=/mnt/armedslack
umount $AS/mnt/pris
#umount $AS/proc

# Create the mountpoint for turrican. turrican is the server I use
# that hosts the master armedslack tree and serves it out via NFS to
# the dev boxes.  Because you cannot mount stuff inside qemu, I mount
# the actual partition inside the chroot location so that it can be found
# once you're in the ARMedslack chroot.
mkdir -p $AS/{mnt/pris,proc}

# Mount turrican's root file system inside ARMedslack chroot:
# You can comment this out if you're not me :-)
#mount /dev/hda3 $AS/mnt/turrican
mount pris:/ $AS/mnt/pris

# mount host's /proc inside ARMedslack chroot:
mount proc $AS/proc -t proc

# Now chroot into armedslack:
chroot $AS /bin/bash -i

# unmount stuff:
umount $AS/mnt/pris
# If we mounted /proc then we don't need another one when
# we exit the qemu environment:
#umount $AS/proc
