#!/bin/sh

#Ask for old password
#ask for new password1
#ask for new password2
#compare password1 & 2
#error if not the same, exit 1 for error
#if the same, echo command to be run prior to actually doing it.


#Get existing password

OLDPASSWORD=$(zenity --entry --title="Old Password"  \
--text="Existing Password on svcedfp01.addm.ads.brm.pri:" --entry-text "" --hide-text)

if [ $OLDPASSWORD ]
then
echo "Password entered is $OLDPASSWORD"
else
zenity --warning  --text="No password entered."
exit 1
fi

#zenity --info --text "Password is $OLDPASSWORD"

#Get new password the first time
PASSWORD1=$(zenity --entry --title="New Password"  \
--text="New Password on svcedfp01.addm.ads.brm.pri:" --entry-text "" --hide-text)

if [ $PASSWORD1 ]
then
echo "Password entered is $PASSWORD1"
else
zenity --warning  --text="No password entered."
exit 1
fi

#zenity --info --text "Password is $PASSWORD1"


#Get new password the second time
PASSWORD2=$(zenity --entry --title="New Password Again"  \
--text="Retype Password on svcedfp01.addm.ads.brm.pri:" --entry-text "" --hide-text)

if [ $PASSWORD2 ]
then
echo "Password entered is $PASSWORD2"
else
zenity --warning  --text="No password entered."
exit 1
fi

#zenity --info --text "1st Password is $PASSWORD1, 2nd Password is $PASSWORD2"


#Check passwords are the same
if [ $PASSWORD1 = $PASSWORD2 ];
then 
zenity --info --title="Passwords Match" --text "Passwords Match"
else
zenity --warning  --title="Password Mis-Match" --text="1st Password is $PASSWORD1, 2nd Password is $PASSWORD2"
exit 1
fi


#If we are here, the new passwords match
#feed in to smbpasswd example
#(echo $2; echo $2) | smbpasswd -s -a $1

echo "echo -e \"$OLDPASSWORD \n$PASSWORD1 \n$PASSWORD2\" > /usr/bin/smbpasswd -r svcedfp01.addm.ads.brm.pri -U bccaawsr -D 3 -s"

echo "Now doing it!"
echo -e "$OLDPASSWORD \n$PASSWORD1 \n$PASSWORD2" > /usr/bin/smbpasswd -r svcedfp01.addm.ads.brm.pri -U bccaawsr -D 3 -s 




