#!/bin/sh
CONFIG_FILE=""
CONFIG="--config-file"
PARAMETER=""
CONFIF_FILE_GIVEN="FALSE"
SPACE=" "
returnval=0

print_usage()
{
        str=`gettext nds "Usage:"`
        echo $str
        echo ""
        str=`gettext nds "To backup"`
        echo $str
        echo ""
	str1=`gettext nds "file name"`
	str2=`gettext nds "size"`
	str3=`gettext nds "password"`
	str4=`gettext nds "backup stream files"`
	str5=`gettext nds "directory name"`
        echo "		dsbk backup [-f <$str1>] [-l $str1>] [-s <$str2>] [-u <$str1>] [-e <$str3>] [-t <$str4>] [-w][-b|-i|-c][-o][-d]"
        echo ""
        str=`gettext nds "  Backup file name"`
	printf "\t-f$str\n"
        str=`gettext nds "  Log file name"`
	printf "\t-l$str\n"
        str=`gettext nds "  Backup file size limit (MB)"`
	printf "\t-s$str\n"
        str=`gettext nds "  User includes file name"`
	printf "\t-u$str\n"
        str=`gettext nds "  Overwrite backup file"`
	printf "\t-w$str\n"
        str=`gettext nds "  Backup stream files"`
	printf "\t-t$str\n"
        str=`gettext nds "  Perform a full backup"`
	printf "\t-b$str\n"
        str=`gettext nds "  Perform incremental backup"`
	printf "\t-i$str\n"
        str=`gettext nds "  Perform a cold backup"`
	printf "\t-c$str\n"
        str=`gettext nds "  Leave database closed after cold backup"`
	printf "\t-o$str\n"
        str=`gettext nds "  Disable database after a cold backup"`
	printf "\t-d$str\n"
        str=`gettext nds "  Repair the local database"`
	printf "\t-R$str\n"
        str=`gettext nds "  Stop logging backup progress (status)"`
	printf "\t-S$str\n"
        str=`gettext nds "  Perform a NICI backup using the NICI backup password (<password>)"`
	printf "\t-e$str\n"
        str=`gettext nds "  Delete old roll forward log files in current RFL directory"`
	printf "\t-a$str\n"
	echo ""
        str=`gettext nds "To restore"`
	echo $str
        echo ""
        echo "		dsbk restore [-f <$str1>] [-l <$str1>] [-d <$str5>] [-e <$str3>] [-r][-a][-o][-u][-n][-v] [-i]"
        echo ""
	str=`gettext nds "  Backup file name"`
	printf "\t-f$str\n"
        str=`gettext nds "  Log file name"`
	printf "\t-l$str\n"
        str=`gettext nds "  Roll forward log directory"`
	printf "\t-d$str\n"
        str=`gettext nds "  Comma seperated list of incremental files in order"`
	printf "\t-i$str\n"
        str=`gettext nds "  Restore user included files"`
	printf "\t-u$str\n"
        str=`gettext nds "  Restore DIB set"`
	printf "\t-r$str\n"
        str=`gettext nds "  Activate DIB after verify"`
	printf "\t-a$str\n"
        str=`gettext nds "  Open database when finished"`
	printf "\t-o$str\n"
        str=`gettext nds "  Restore the NICI files using the input password (<password>)"`
	printf "\t-e$str\n"
        echo ""
	str=`gettext nds "To get RFL location"`
	printf "\n$str\n"
	printf "\n		dsbk getconfig"
        echo ""
	str=`gettext nds "To set RFL location"`
	printf "\n$str\n"
	echo ""
	echo "		dsbk setconfig [-L|-l][-T|-t][-r <$str5>][-n <$str2>][-m <$str2>][-s]"
        echo ""
        str=`gettext nds "  Start keeping roll forward logs"`
	printf "\t-L$str\n"
        str=`gettext nds "  Stop keeping roll forward logs"`
	printf "\t-l$str\n"
        str=`gettext nds "  Start logging of stream files"`
	printf "\t-T$str\n"
        str=`gettext nds "  Stop logging of stream files"`
	printf "\t-t$str\n"
        str=`gettext nds "  Set roll forward log directory"`
	printf "\t-r$str\n"
        str=`gettext nds "  Set minimum roll forward log size"`
	printf "\t-n$str\n"
        str=`gettext nds "  Set maximum roll forward log size"`
	printf "\t-m$str\n"
        str=`gettext nds "  Start a new roll forward log"`
	printf "\t-s$str\n"
        echo ""
}

# Display help
if [ "$1" = "--help" -o "$1" = "help" -o "$1" = "-h" -o "$1" = "" ]
then
#    man dsbk
    print_usage
    exit
fi


while test "$1" != "" ;
do
        if [ "$1" = "$CONFIG" ]
	then
		if [ "$2" = "" ]
		then	
			str=`gettext nds "Provide Config File name after --config-file"`
			echo $str
			CONFIG_FILE="NOFILE"
		else
			CONFIF_FILE_GIVEN="TRUE"	
			CONFIG_FILE=$2
			shift
		fi
		shift
	else	
		PARAMETER=$PARAMETER$SPACE$1
	        shift
	fi
done

if [ "$PARAMETER" = "" ]
then
	str=`gettext nds "Invalid Option !!! Check man page of dsbk for options"`
	echo $str
	echo ""
	exit 1;
fi

if [ "$CONFIF_FILE_GIVEN" = "TRUE" ]
then
	if [ ! -f $CONFIG_FILE ]
	then
		str=`gettext nds "Config File does not exists"`
		echo $str
		exit 1;
	else
		ndstrace -c "load dsbk $PARAMETER" --config-file $CONFIG_FILE
		returnval=$?;
		if [ "$returnval" = "0" ]
		then
			str=`gettext nds "DSBK Backup/Restore has been started, output is in ndsd.log"`
			echo $str
		fi
	fi
else
	ndstrace -c "load dsbk $PARAMETER"
	returnval=$?;
	if [ "$returnval" = "0" ]
	then
		str=`gettext nds "DSBK Backup/Restore has been started, output is in ndsd.log"`
		echo $str
	fi
fi
exit $returnval;
