#!/bin/sh
#
#    Copyright (c) 2001 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   timeout.sh.in 
#    Module name: fabos/src/utils/sys
#     
#    This program can be used to change the IDLE Timeout
#    value for a login session
#
setswitch () 
{ 
    eval `diagenv -b writed SWITCH_ENV 0 $1`
}

export PATH=/fabos/sbin:/fabos/bin:/bin:/usr/bin:/sbin

# let us set our switch to switch 0 -- timeout value always stored in sw0
setswitch 0
USERNAME=`set | grep LOGNAME | cut -d= -f2`

if [ "$USERNAME" = "user" ] || [ $# -eq 0 ]; then
	TIMESEC=`config get system.login.timeout 2`
	# if the timeout value is not defined we will make it zero
	[ -z $TIMESEC ] && TIMESEC=0
	TIMEMIN=`expr $TIMESEC \/ 60`
	echo Current IDLE Timeout is $TIMEMIN minutes
	exit
fi
	
if [ $# -ne 1 ]; then
	echo Invalid Number of arguments
	echo Please just specify the timeout in minutes
	exit
fi

choice=$1
if [ -z "$choice" ]
then
	choice=invalid
fi
nchoice=`echo $choice | /usr/bin/tr -cd "[0-9]\n"`
if [ "$nchoice" != "$choice" ]
then
	printf "Please specify a numeric timeout value in minutes\n"
	exit
fi
if [ $nchoice -gt 99999 ]
then
	printf "Please specify a timeout value in [0-99999]minutes\n"
	exit
fi
TIMESEC=`expr $nchoice \* 60`
if [ $TIMESEC -lt 0 ]
then
	printf "Please specify a timeout value in [0-99999]minutes\n"
	exit
fi
config set system.login.timeout 2 $TIMESEC

config update > /dev/null
echo IDLE Timeout Changed to $nchoice minutes
echo The modified IDLE Timeout will be in effect after NEXT login
