#!/bin/sh

PREREQ=""

prereqs()
{
    echo "$PREREQ"
}

case $1 in
    prereqs)
	prereqs
	exit 0
	;;
esac

. /scripts/functions
. /scripts/functions-uniklu

chvt 1

log_begin_msg "Initializing/Mounting local disks"

# important for mkfs.extX:
touch /etc/mtab

MOUNTFAILED=""
mkdir -p /target

#if [ "$PART" != "killall" -a "$PART" != "killext" -a "$PART" != "killlnx" ]; then
#    fsck.ext3 -y -C 0 -F LABEL=UNIKLU
#fi

modprobe ext3
modprobe ext4

hd0dev=$(find_hd0)
if [ "$PART" = "killlnx" ]; then
    kill_ext2fs_parts  $hd0dev
    kill_swap_parts  $hd0dev
fi

if [ "$PART" = "killall" ]; then
    kill_all_parts $hd0dev
fi

if [ "$PART" = "killext" ]; then
    kill_ext_part  $hd0dev
fi

find_part_by_label $PART1LABEL  || MOUNTFAILED="yes"


if [ "$MOUNTFAILED" = "yes" ]; then
    _log_msg "trying to autopartition and autoformat ..."

    auto_partition install

  # retry:
    MOUNTFAILED=""
    find_part_by_label $PART1LABEL  || MOUNTFAILED="yes"
    if [ "$MOUNTFAILED" = "yes" ]; then
        panic "searching install partition ($PART1LABEL) failed!"
    fi
fi

log_end_msg
