#!/bin/sh
#
# This script is a part of the live-install package to copy ALT Linux system from LiveCD to harddisk
#
# Copyright (C) 2010-2011 Eugene Prokopiev  <enp@altlinux.org>
# Copyright (C) 2011      Michael Pozhidaev <msp@altlinux.org>

# argv1 - mounted partition to chroot;

THIS=${0##*/}
DESTDIR="${1%%/}"

if [ -z "$DESTDIR" ]; then
    echo "$THIS:chroot directory is not specified" >&2
    exit 1
fi

MOUNT_PROBLEM=0

for i in dev proc sys; do
    if ! /bin/mount --bind "/$i" "$DESTDIR/$i"; then
	MOUNT_PROBLEM=1
    fi
done

if [ "$MOUNT_PROBLEM" == 0 ]; then
    /sbin/chroot "$DESTDIR" installkernel --nolaunch "$(uname -r)"
EXITCODE="$?"
else
    echo "$THIS:mount problems detected, skipping lilo execution" >&2
fi

for i in dev proc sys; do
    /bin/umount "$DESTDIR/$i"
done

exit "$EXITCODE"
