#!/bin/sh

mount -t proc proc /proc
mount -o remount,rw /
cardmgr -o 
if [ "`dmesg | tail -3 |grep hda1`" != "" ]; then
	IDE1=/dev/hda1
else
	IDE1=/dev/hdc1
fi

echo "Internal harddrive is $IDE1"

if [ -f /sbin/e2fsck ]; then
	echo Checking $IDE1...
	e2fsck -p $IDE1 
fi

umount /proc
echo Mounting $IDE1.
mount -t ext3 $IDE1 /media/hdd

# For some reason the Spitz tar doesn't create the devices.
if [ ! -b /media/hdd${IDE1} ]; then
	echo Creating non existant device files.
	/media/hdd/sbin/makedevs -D /media/hdd/etc/device_table -r /media/hdd/ 2>/dev/null
fi

if [ -e /media/hdd/sbin/init -o -L /media/hdd/sbin/init ]; then
	echo "Found /sbin/init on HD; pivoting."
	cd /media/hdd
	pivot_root . media/realroot
	cd /
	exec /sbin/init
fi

echo Dropping to a shell due to problems.
exec /bin/sh
