#!/bin/sh -e
#
# The main script to install ALT LInux Homeros onto user computer
# Michael Pozhidaev <msp@altlinux.org>

THIS="${0##*/}"

BOOTDEV=
ROOTDEV=
HOMEDEV=
SYSUSER=
NOLILO=no

print_help()
{
cat <<EOF
The installer for ALT Linux Homeros distribution

Usage:
    $THIS [--help] [--no-lilo] [--user USERNAME] [--home DEVICE] [--boot DEVICE] [--root DEVICE]
EOF
}

while [ -n "$1" ]; do
    if [ "$1" == '--boot' ]; then
	BOOTDEV="$2"
	shift
	shift
    elif [ "$1" == '--root' ]; then
	ROOTDEV="$2"
	shift
	shift
    elif [ "$1" == '--home' ]; then
	HOMEDEV="$2"
	shift
	shift
    elif [ "$1" == '--no-lilo' ]; then
	NOLILO='yes'
	shift
    elif [ "$1" == '--user' ]; then
	SYSUSER="$2"
	shift
	shift
    elif [ "$1" == '--help' ]; then
	print_help
	exit 0
    else
	echo "$THIS:unknown parameter: $1" >&2
	exit 1
    fi
done

[ -z "$ROOTDEV" ] && echo "$THIS:the device for root file system is not specified" >&2 && exit 1
[ -z "$BOOTDEV" ] && echo "$THIS:the device for boot loader is not specified" >&2 && exit 1

if ! [ -e "$ROOTDEV" ]; then 
    echo "$THIS:$ROOTDEV is not a valid device for root file system" >&2
    exit 1
fi

if ! [ -e "$BOOTDEV" ]; then 
    echo "$THIS:$BOOTDEV is not a valid device for boot loader installation" >&2
    exit 1
fi

export HOMEROS_INSTALL_USER="$SYSUSER"
#FIXME:home directory device;

if [ "$NOLILO" == 'yes' ]; then
    exec live-install --no-lilo "$BOOTDEV" "$ROOTDEV"
else
    exec live-install "$BOOTDEV" "$ROOTDEV"
fi
