#!/bin/sh
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL
# Description: set the default pxe image for simple menu format.

# Load DRBL setting and functions
if [ ! -f "/opt/drbl/sbin/drbl-conf-functions" ]; then
  echo "Unable to find /opt/drbl/sbin/drbl-conf-functions! Program terminated!" 
  exit 1
fi
. /opt/drbl/sbin/drbl-conf-functions

#
PXE_CONF_DEF="$PXELINUX_DIR/default"

#
USAGE() {
    echo "Usage:"
    echo "To set the default PXE client menu:"
    echo "`basename $0` [OPTION]"
    echo " Options:"
    echo " -i, --image IMG   set IMG as the default one"
    echo " -c, --config CONF use the CONF file instead of default one ($PXE_CONF_DEF)"
    echo " -v, --verbose     show verbose messages"
    echo " -h, --help        display this help and exit"
}

# Parse command-line options
while [ $# -gt 0 ]; do
  case "$1" in
    -i|--image)  
            shift;
            # skip the -xx option, in case 
            [ -z "$(echo $1 |grep ^-.)" ] && IMG="$1"
	    shift;;
    -c|--config)  
            shift;
            # skip the -xx option, in case 
            [ -z "$(echo $1 |grep ^-.)" ] && PXE_CONF="$1" 
	    shift;;
    -h|--help)  
            USAGE >& 2
            exit 2 ;;
    -l|--label)  
            shift;
            # skip the -xx option, in case 
            [ -z "$(echo $1 |grep ^-.)" ] && MENU_LABEL="$1" 
	    shift;;
    -v|--verbose)  
            VERBOSE="on"
	    shift;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done

[ -z "$PXE_CONF" ] && PXE_CONF=$PXE_CONF_DEF
if [ -z "$IMG" ]; then
   [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
   echo "You must specify the image name! Program terminated!!!"
   [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
   USAGE
   exit 1
fi

sub_default_pxe_img $IMG $PXE_CONF "$MENU_LABEL"
