#!/bin/sh

#set -e

# initramfs-tools header

PREREQ=""

prereqs()
{
	echo "${PREREQ}"
}

case "${1}" in
	prereqs)
		prereqs
		exit 0
		;;
esac

# live-initramfs header

. /scripts/live-functions

log_begin_msg "Moving mount points"

# live-initramfs script

# Move to the new root filesystem so that programs there can get at it.
if [ ! -d /root/live/image ]
then
	mkdir -p /root/live/image
	mount -n --move /live/image /root/live/image
fi

MOUNTED_ON=$(grep /live/image /proc/mounts 2>/dev/null | cut -f 1 -d " ")
if [ -n "$MOUNTED_ON" ] ; then
   echo "   -> Mounted live system on $MOUNTED_ON">/dev/console
fi

# Move findiso directory to the new root filesystem so that programs there can get at it.
if [ -d /live/findiso -a ! -d /root/live/findiso ]
then
	mkdir -p /root/live/findiso
	mount -n --move /live/findiso /root/live/findiso
fi

# if we do not unmount the ISO we can't run "fsck /dev/ice" later on
# because the mountpoint is left behind in /proc/mounts, so let's get
# rid of it when running from RAM
if [ -n "$FINDISO" ] && [ "${TORAM}" ]
then
  losetup -d /dev/loop0
  grep -q /live/findiso /proc/mounts && umount /root/live/findiso
fi


log_end_msg
