#!/bin/sh 

curdir=`dirname "$0"`
absolute=`expr "$0" : '/.*'`
if [ $absolute = 0 ]; then
    curdir=`pwd`/"$curdir"
fi

rundir="${curdir}/../bin-${MWCONFIG_NAME}_optimized"

if [ $# -eq 0 ]; then
    # no arguments, give dummy name and fall through to usage. 
    prog=xxxxx
else
    prog=$1
    shift 
fi

# We had a problem with keys that had embedded spaces.
# We split the arguments into their expected parts for the regch* utilities
allargs=$*
if [ $# -gt 0 ]; then
	if [ $1 = "-r" ]; then
		recursive='-r'
		shift
	fi
fi
  
if [ $# -gt 0 ]; then
	arg=$1
	shift
fi
rest=$*
    
case "$prog" in
'-ls')
    "${rundir}/regls" "$allargs"
    exit $?
    ;;
'-chmod')
    "${rundir}/regchmod" $recursive $arg "$rest"
    exit $?
    ;;
'-chown')
    "${rundir}/regchown" $recursive $arg "$rest"
    exit $?
    ;;
'-chgrp')
    "${rundir}/regchgrp" $recursive $arg "$rest"
    exit $?
    ;;
'-quota')
    "${rundir}/regquota" $allargs
    exit $?
    ;;
'-ps')
    # regps takes no arguments
    "${rundir}/regps"
    exit $?
    ;;
'-backup')
    "${rundir}/regbackup" "$allargs"
    exit $?
    ;;
'-auto_backup')
	"${rundir}/regautobackup" $allargs
	exit $?
	;;
    
'-restore')
	MWADM_UTILITY=1
	export MWADM_UTILITY
	"${rundir}/mwrestore_reg" $allargs
	exit $?
	;;

*)
    echo "Usage: mwadm reg -<utility> [arguments]"
    echo "Known reg utilities are:"
    echo "    ls"
    echo "    chmod"
    echo "    chown"
    echo "    chgrp"
    echo "    quota"
    echo "    ps"
    echo "    backup"
    echo "    auto_backup"
    echo "    restore"
    

    exit 2
    ;;

esac
