#!/bin/bash

### BEGIN INIT INFO
# Provides:		extern-config
# Required-Start:	mdadm-raid lvm2 xend bootmisc
# Required-Stop:	
# Should-Start:		$local_fs
# Should-Stop:		halt reboot
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	external config script from claas felix beyersdorf
# Description:		external config script loaded from software raid and
#			lvm2 then executed try to execute before xend
### END INIT INFO

# Authors: Claas Felix Beyersdorf
#

set -e
CONFIG_DEVICE=/dev/lvm01/boot-disk
CONFIG_PATH=/boot

PATH=/usr/sbin:/usr/bin:/sbin:/bin
NAME=extern-config
SCRIPNAME=/etc/init.d/${NAME}

# Exit if system was not booted by live-boot
grep -qs boot=live /proc/cmdline || exit 0

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions


do_start() {
    mount $CONFIG_DEVICE $CONFIG_PATH

    if [[ -d "$CONFIG_PATH/xen-config/start.sh" ]]; then
	sh "$CONFIG_PATH/xen-config/start.sh" &
    fi

    ## In my setup I use this to get access on some pci devices so i can use
    ## them in domUs
    if [[ -d "/etc/xen/hide-pci-devices.sh" ]]; then
	sh /etc/xen/hide-pci-devices.sh &
    fi
}

case "${1}" in
    start)
	    do_start
	    ;;
    restart|reload|force-reload|status)
	    [ "${VERBOSE}" != no ] && log_end_msg 0
	    ;;
	    
    stop)
	    log_begin_msg "${NAME} isn't doing something"
esac

exit 0