#!/bin/sh
#---------------------------------------------------------------
# Project         : pxemngr
# File            : pxemngr
# Copyright       : 2009 Splitted-Desktop Systems
# Author          : Frederic Lepied
# Created On      : Fri Feb  6 09:12:51 2009
# Purpose         : execute pxemngr sub-commands according to the
#                  configuration file.
#---------------------------------------------------------------

CONF=${PXEMNGR_CONF=/etc/pxemngr.conf}

. $CONF

if [ -z "$BASEDIR" ]; then
    echo "BASEDIR not defined in $CONF" 1>&2
    exit 1
fi

print_subcommands() {
    echo "Available sub-commands:"
    cd "$BASEDIR"/pxe/$1
    find . -perm -111 -a -type f|sed 's@./@    @'
    cd "$BASEDIR"/tester/$1
    find . -perm -111 -a -type f|sed 's@./@    @'
}

if [ $# -lt 1 ]; then
    echo "Usage: `basename $0` <sub-command> [<args>...]" 1>&2
    print_subcommands
    exit 1
fi

if [ ! -x "$BASEDIR"/pxe/$1 -a ! -x "$BASEDIR"/tester/$1 ]; then
    echo "Invalid pxemngr sub-command $1" 1>&2
    print_subcommands
    exit 1
fi

PYTHONPATH="$BASEDIR":$PYTHONPATH
DJANGO_SETTINGS_MODULE=settings
export PYTHONPATH
export DJANGO_SETTINGS_MODULE

cmd="$1"
shift

if [ -x "$BASEDIR"/pxe/$cmd ]; then
    exec "$BASEDIR/pxe/$cmd" "$@"
else
    exec "$BASEDIR/tester/$cmd" "$@"
fi

# pxemngr ends here

