# Local filesystem mounting			-*- shell-script -*-

. /scripts/functions-uniklu

# Parameter: Where to mount the filesystem
mountroot ()
{
	[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/createimage-top"
	run_scripts /scripts/createimage-top
	[ "$quiet" != "y" ] && log_end_msg


	[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/createimage-premount"
	run_scripts /scripts/createimage-premount
	[ "$quiet" != "y" ] && log_end_msg

        touch /etc/mtab
        # mount image path
        if  [ -z "$IMAGETYPE"  ]; then
          panic "IMAGETYPE should be disk: or cifs: !"
        fi

	mkdir -p /target
        if  [ "$IMAGETYPE" = "cifs"  ]; then
          /sbin/mount.cifs $IMAGELOCATION /target -o ip=$IMAGEIP,user=$IMAGEUSER
        fi
        if  [ "$IMAGETYPE" = "disk"  ]; then
          mount -t ext2 $IMAGELOCATION /target
        fi
	fsck.ext2 -f $IMAGESOURCEDEV
	swapon -L SWAP
	rm -f /target/$IMAGENAME.*
	partimage -b -V 8388608 -z 1 -comd save $IMAGESOURCEDEV /target/$IMAGENAME
	chmod 644 /target/$IMAGENAME

	[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/createimage-bottom"
	run_scripts /scripts/createimage-bottom
	[ "$quiet" != "y" ] && log_end_msg
    # reboot:
    
    /bin/umount /target
    echo s > /proc/sysrq-trigger
    echo u > /proc/sysrq-trigger
    echo b > /proc/sysrq-trigger
    
}
