I didn't include the "try again" part, so if the password entries don't match, the script just continues without changing the password.
It only works with yad. Zenity uses different options, and it might be possible, but I didn't try it.
- Code: Select all
#!/bin/bash
pass_2=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")
if [ $(echo $pass_2 | awk -F"@_@" '{print $1}') != $(echo $pass_2 | awk -F"@_@" '{print $2}') ] ; then
yad --title "Errore" --text "Le password sono differenti; password will not be changed."
exit 1
else
echo "Passwords are the same"
pass=$(echo $pass_2 | awk -F"@_@" '{print $1}')
echo "$pass"
fi
echo "${USER}:${pass}" > /tmp/passfile
# Then maybe this replaces line 1457: chroot /target passwd "$newname"
# chroot /target chpasswd < /tmp/passfile
cat /tmp/passfile
rm /tmp/passfile
exit 0
If you want to test it in the installer script, find this section:
- Code: Select all
# Change user password
if [[ $change_user = "yes" ]]; then
yad --title="Change user password" --button=Yes:0 --button=No:1 \
--text="Would you like to change the user's password? The new user still has
the old user's password. You'll need to go to the terminal again to do this."
ans="$?"
if [[ $ans = 0 ]]; then
#xterm -fa monaco -fs 12 -geometry 80x20+0+0 -e chroot /target passwd "$newname"
# # Redirect stderr so we can see the output of dd
exec 2>&1
chroot /target passwd "$newname"
# # Resume logging errors in file
exec 2>>"$error_log"
fi
fi
And replace it with this:
- Code: Select all
# Change user password
if [[ $change_user = "yes" ]]; then
yad --title="Change user password" --button=Yes:0 --button=No:1 \
--text="Would you like to change the user's password? The new user
still has the old user's password. "
ans="$?"
if [[ $ans = 0 ]]; then
pass_2=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")
if [ $(echo $pass_2 | awk -F"@_@" '{print $1}') != $(echo $pass_2 | awk -F"@_@" '{print $2}') ] ; then
yad --title "Errore" --text "Le password sono differenti; password will not be changed."
else
pass=$(echo $pass_2 | awk -F"@_@" '{print $1}')
echo "${newname}:${pass}" > /tmp/passfile
chroot /target chpasswd < /tmp/passfile
rm /tmp/passfile
fi
fi
fi
Oh, I just noticed that the comment in the script regarding the redirect is misleading - it refers to the dd command. I didn't change the comment when I copied the code. No big deal, but I figured I'd mention it in case someone noticed and had a question about it.