#!/bin/sh

set -e

# Make sure we're not working on the root directory
if [ -z "$TARGET" -o "$TARGET" = "/" ]; then
    echo "Invalid target directory '$TARGET', aborting." 1>&2
    exit 1
fi

if [ "$(mountpoint -d /)" = "$(mountpoint -d "$TARGET")" ]; then
    echo "The target directory seems to be the root dir, aborting."  1>&2
    exit 1
fi

# Fix the console information for xen-pvm mode
if [ "$HYPERVISOR" = "xen-pvm" ]; then
    echo "xen-pvm hypervisor detected, adding getty on hvc0"
    cat >> "$TARGET"/etc/inittab <<EOF
hvc0:2345:respawn:/sbin/getty 38400 hvc0
EOF
fi

exit 0
