I have a script that adds the root passwd to an new install. It was written in dialog. My issue is that my passwd version doesn't support --stdin option. I need help with some sort of redirection and to pass crypted data to add the root user. I've read up on expect and it seems it wont fit with what I want to accomplish.
Any suggestions?
Code:
root_password()
{
PASSWORD=""
PWD_MESSAGE1="Please enter a new root password or press Enter \
to keep the current root password. \
(Please note, an empty root password is NOT recommended !)"
PWD_MESSAGE2="Retype new password:"
while [ ! $PASSWORD ]; do
$DIALOG --backtitle $BTITLE --title "Root Passwd" --insecure --no-cancel --passwordbox \
"$PWD_MESSAGE1" 15 60 2>$OUTPUT
PASSWORD1=$( cat $OUTPUT )
rm -f $OUTPUT
[ ! $PASSWORD1 ] && break
$DIALOG --backtitle $BTITLE --title "Root Passwd" --insecure --no-cancel --passwordbox \
"$PWD_MESSAGE2" 15 60 2>$OUTPUT
PASSWORD2=$( cat $OUTPUT )
rm -f $OUTPUT
if [ "$PASSWORD1" = "$PASSWORD2" ]; then
PASSWORD=$PASSWORD1
echo $PASSWORD | passwd --stdin root >/dev/null
fi
done
}