#!/bin/sh
#
#    Copyright (c) 2001 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   passwd 
#    Module name: fabos/src/utils/sys
#
#    This script is wrapper to the traditional /bin/passwd command 
#    to be able to save the changed passwd into flash.
#

# we will net let the standby user user this command, if this is Ulyses

HWMODEL=`/sbin/sin | /bin/grep "Platform" | /bin/sed -e"s/[ ]*//g" | /usr/bin/cut -d, -f1 | /usr/bin/cut -d: -f2 2> /dev/null`

if [ "$HWMODEL" = "SWBD10" ]; then
	ACTIVE=`/fabos/sbin/hashow | /bin/grep Local | /bin/sed -e "s/[ ]*//g" | /usr/bin/cut -d: -f2`
	if [ "$ACTIVE" != "Active" ]; then
		echo "password can not be changed on standby CP."
		exit
	fi
fi

export PATH=/fabos/sbin:/fabos/bin:/bin:/sbin
/bin/passwd $*
if [ $? -eq 0 ]; then
trap "" INT
echo "Saving password to stable storage."
config save /etc/passwd
configsave_result=$?
if [ $configsave_result -eq 0 ]; then
echo "Password saved to stable storage successfully."
else
echo "Failed to update password in stable storage."
fi
fi
