Welcome
Welcome to refracta

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

Refracta Installer on Debian Distro - Makululinux

Refracta Development, Scripts, etc.

Re: Refracta Installer on Debian Distro - Makululinux

Postby fsmithred » Sat Jan 11, 2014 12:03 pm

Here's a test script, adapted from this example - http://stackoverflow.com/questions/1052 ... command-mv
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.
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: Refracta Installer on Debian Distro - Makululinux

Postby dzz » Sat Jan 11, 2014 1:28 pm

There is a way to use zenity/yad to set passwords. I did this before before in my ExeGNU installers. A plain text box is used (sounds insecure but the file it's stored in gets deleted after use). There is also a dialog "--hide-text" option but then you would also need a confirmation box and a comparison check.

Code: Select all
# set user password
set_userpass () {
# what is the point of starring out passwords now? the config file gets deleted later
NEWUSERPASS=$($DIALOG --width=400 --height=160 --title="$TITLE" --entry --text=$"\nPlease enter a password for your new user\n")

   if [ "$NEWUSERPASS" = "" ]; then
   REPEAT_FUNCTION=set_userpass
   input_error
   fi
}

set_userpass
echo "NEWUSERPASS=\"$NEWUSERPASS\"" >>userinput

"userinput" is a config file which gets copied to the new installation containing other stuff. Later in chroot:

Code: Select all
echo -e "$NEWUSERPASS\n$NEWUSERPASS\n" | passwd $NEWUSERNAME

These are only snips of what I did.. how to (or if it makes sense to) incorporate something like that in refractainstaller is another matter. I do agree having to use the terminal might be a bit clunky, for inexperienced users.
dzz
 
Posts: 629
Joined: Wed Apr 27, 2011 11:53 am
Location: Devon, England

Re: Refracta Installer on Debian Distro - Makululinux

Postby fsmithred » Sun Jan 12, 2014 9:02 pm

Here's another version, combining what I posted above with some of what dzz posted. I didn't know you could feed the password twice to the passwd command by using line breaks. Thanks, dzz.

"pass_2" was replaced with "newpass", it uses passwd instead of chpasswd, and it does not make a temporary file (that might accidentally not get deleted.)

This is for the yad version of the installer. Just replace the relevant section. (same as above)

I haven't tested this in the installer. I did use a test script that changed the password, but I didn't try it in a chroot. And I might actually use this in the installer. I've always wanted a graphical solution to entering the passwords, but it was never high enough on the list to do anything about it. I might try it with cryptsetup, too.

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
      newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")

      if [ $(echo $newpass | awk -F"@_@" '{print $1}') != $(echo $newpass | awk -F"@_@" '{print $2}') ] ; then
         yad --image="gtk-dialog-warning" --title "Error" --text "Entries do not match. Password will not be changed.\nYou can Use the passwd command to change passwords \nwhen you reboot into the new system."
      else
         echo $newpass | sed 's/@_@/\n/g' | chroot /target passwd "$newname"
      fi
   fi
fi
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: Refracta Installer on Debian Distro - Makululinux

Postby fsmithred » Mon Jan 13, 2014 2:58 am

Correction - need to disable the error log for passwd to work.

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
      newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")

      if [ $(echo $newpass | awk -F"@_@" '{print $1}') != $(echo $newpass | awk -F"@_@" '{print $2}') ] ; then
         yad --image="gtk-dialog-warning" --title "Error" --text "Entries do not match. Password will not be changed.\nYou can Use the passwd command to change passwords \nwhen you reboot into the new system."
      else
         # Redirect stderr to keep the output of the passwd command.
         exec 2>&1
            echo $newpass | sed 's/@_@/\n/g' | chroot /target passwd "$newname"
          # Resume logging errors in file
         exec 2>>"$error_log"
      fi
   fi
fi
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: Refracta Installer on Debian Distro - Makululinux

Postby raymerjacque » Mon Jan 13, 2014 8:44 am

Thank you for all the help, ill try some of the suggestions above and let you know how it goes :)
raymerjacque
 
Posts: 105
Joined: Sun Nov 03, 2013 9:37 am

Re: Refracta Installer on Debian Distro - Makululinux

Postby raymerjacque » Sat Jan 18, 2014 8:15 pm

It works flawless thank you :)

but this is only for user password. i edited the script to add for root password as well.

for root i changed to this :

# Change/create root password
if [[ $install = "expert" ]]; then
yad title="Change/create root password" --button=Yes:0 --button=No:1 \
--text="Would you like to change the root password? (Recommended)"
ans="$?"
if [[ $ans = 0 ]]; then
newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")

if [ $(echo $newpass | awk -F"@_@" '{print $1}') != $(echo $newpass | awk -F"@_@" '{print $2}') ] ; then
yad --image="gtk-dialog-warning" --title "Error" --text "Entries do not match. Password will not be changed.\nYou can Use the passwd command to change passwords \nwhen you reboot into the new system."
else
# Redirect stderr to keep the output of the passwd command.
exec 2>&1
echo $newpass | sed 's/@_@/\n/g' | chroot /target passwd
# Resume logging errors in file
exec 2>>"$error_log"
fi
fi
fi


And simply removed the "$newname"

seems to work fine, just want to check if that is correct ?
raymerjacque
 
Posts: 105
Joined: Sun Nov 03, 2013 9:37 am

Re: Refracta Installer on Debian Distro - Makululinux

Postby fsmithred » Sun Jan 19, 2014 12:36 am

Yes, I think all you have to do is remove $newname from the passwd command to use it for root. And change the wording. Everything else should be the same. I can only think of one potential problem - if you had the code for selecting both passwords come before the code for changing both passwords, you'd only get the last selection. In that case, you'd need to change the variable from $newpass to something else for either root or user. But it's fine the way it is.
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: Refracta Installer on Debian Distro - Makululinux

Postby raymerjacque » Sun Jan 19, 2014 9:04 am

one last issue.

If the passwords the user types mismatch it tells the user to change it manually after reboot.

The question i have is this : is it possible instead to ask the user to retype the passwords if they mismatch ? and add some sort of check in place to see if passwords match and if they dont it goes back to enter password box again ?

and if so, how would i do that ?

i tried looping the password box:

# Change/create root password
if [[ $install = "expert" ]]; then
yad title="Change/create root password" --button=Yes:0 --button=No:1 \
--text="Would you like to change the root password? (Recommended)"
ans="$?"
if [[ $ans = 0 ]]; then
newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")

if [ $(echo $newpass | awk -F"@_@" '{print $1}') != $(echo $newpass | awk -F"@_@" '{print $2}') ] ; then
newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Passwords dont match, Retype Pass" --image="dialog-password")
else
# Redirect stderr to keep the output of the passwd command.
exec 2>&1
echo $newpass | sed 's/@_@/\n/g' | chroot /target passwd
# Resume logging errors in file
exec 2>>"$error_log"
fi
fi
fi


# 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? (Recommended)"
ans="$?"
if [[ $ans = 0 ]]; then
newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")

if [ $(echo $newpass | awk -F"@_@" '{print $1}') != $(echo $newpass | awk -F"@_@" '{print $2}') ] ; then
newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Passwords dont match, Retype Pass" --image="dialog-password")
else
# Redirect stderr to keep the output of the passwd command.
exec 2>&1
echo $newpass | sed 's/@_@/\n/g' | chroot /target passwd "$newname"
# Resume logging errors in file
exec 2>>"$error_log"
fi
fi
fi


but it doesnt seem to save the password after i purposefully enter it wrong and re-enter it the second time.
raymerjacque
 
Posts: 105
Joined: Sun Nov 03, 2013 9:37 am

Re: Refracta Installer on Debian Distro - Makululinux

Postby fsmithred » Sun Jan 19, 2014 3:12 pm

I think the way to do it would be to put the change-password section into a function, and if the passwords don't match, a second function is called. The second function would give the error message and then call the first function.

Like this. Note: you'll need two more functions - change_root_pass and try_again_2 for the root password.
Code: Select all
# Change user password
change_user_pass () {
      newpass=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password" --button=OK:0 --button=Cancel:1)
      if [[ $? = 1 ]] ; then
         return
      fi
      
      if [ $(echo $newpass | awk -F"@_@" '{print $1}') != $(echo $newpass | awk -F"@_@" '{print $2}') ] ; then
         try_again_1
         return
      else
         # Redirect stderr to keep the output of the passwd command.
         exec 2>&1
            echo $newpass | sed 's/@_@/\n/g' # | chroot /target passwd "$newname"
          # Resume logging errors in file
         exec 2>>"$error_log"
      fi
}


try_again_1 () {
yad --image="gtk-dialog-warning" --title "Error" --button=Yes:0 --button=No:1 \
--text "Entries do not match. Do you want to try again?\n(If you say No, password will not be changed.)"
if [[ $? = 0 ]] ; then
   change_user_pass
fi
}


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. "
    if [[ $? = 0 ]]; then
      change_user_pass
   fi
fi


Edit: The above is what I was using for testing. Remember to uncomment the last part of this line:
Code: Select all
echo $newpass | sed 's/@_@/\n/g' # | chroot /target passwd "$newname"
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: Refracta Installer on Debian Distro - Makululinux

Postby raymerjacque » Sun Jan 19, 2014 4:17 pm

Thank you, Ill try it when i get home and let you know :)
raymerjacque
 
Posts: 105
Joined: Sun Nov 03, 2013 9:37 am

PreviousNext

Return to Discuss

Who is online

Users browsing this forum: No registered users and 0 guests

suspicion-preferred