Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [[ -z $TARGET ]] || PASS=`python -c "import keyring; print(keyring.get_password("$TARGET", "(printf '%q' $USERNAME)"))"`
- #!/bin/bash
- SAVE=FALSE
- case $# in
- 1)
- USERVAR=USER
- PASSVAR=PASS
- USERNAME=$1
- ;;
- 3)
- USERVAR=$1
- PASSVAR=$2
- USERNAME=$3
- ;;
- 4)
- USERVAR=$1
- PASSVAR=$2
- USERNAME=$3
- TARGET=$4
- ;;
- *)
- echo '
- getpasswd: invalid number of arguments.
- Presents a username and password prompt dialog, with keyring support.
- The user can accept the offered username or change it, and enter a password.
- Use: getpasswd [usernamevar passwordvar] initial_username [targetname]
- usernamevar defaults to USER
- passwordvar defaults to PASS
- User name and password will be returned in usernamevar and passwordvar
- If targetname is specified,
- - the password wil be taken from the keyring if the user/target combination exists.
- - if the combination does not exist, the caller will be prompted
- and given the option to store it in the keyring.
- '
- exit 1
- ;;
- esac
- #echo USERVAR=$USERVAR
- #echo PASSVAR=$PASSVAR
- #echo USERNAME=$USERNAME
- #echo TARGET=$TARGET
- [[ -z $TARGET ]] || PASS=`python -c "import keyring; print(keyring.get_password("$TARGET", "(printf '%q' $USERNAME)"))"`
- #echo from keyring: $PASS
- if [[ -z $PASS || $PASS == "None" ]]
- then
- if [[ -z $TARGET ]]
- then
- FORM=$(yad --center --width=380
- --window-icon="gtk-execute" --image="gcr-password"
- --title "Login"
- --form --field="User name" "$USERNAME"
- --field="Password":H
- --focus-field=2)
- else
- FORM=$(yad --center --width=380
- --window-icon="gtk-execute" --image="gcr-password"
- --title "Login"
- --form --field="User name" "$USERNAME"
- --field="Password":H
- --field="Save in keyring?":CHK
- --focus-field=2)
- printf -v SAVE "%s" $(echo $FORM | awk -F '|' '{ print $3 }')
- fi
- #echo $FORM
- printf -v USERNAME "%s" $(echo $FORM | awk -F '|' '{ print $1 }')
- printf -v PASS "%s" $(echo $FORM | awk -F '|' '{ print $2 }')
- fi
- #echo eval $USERVAR=$(printf '%q' $USERNAME)
- #echo eval $PASSVAR=$(printf '%q' $PASS)
- eval $USERVAR=$(printf '%q' $USERNAME)
- eval $PASSVAR=$(printf '%q' $PASS)
- #echo .
- #echo TARGET=$TARGET
- #echo USERNAME=$USERNAME
- #echo PASS=$PASS
- #echo SAVE=$SAVE
- if [[ -n $TARGET && -n $PASS && $PASS != "None" && $SAVE != "FALSE" ]]
- then
- #echo saving to keyring
- python -c "import keyring; keyring.set_password("$TARGET", "(printf '%q' $USERNAME)", "$PASS")"
- fi
- . getpasswd USER PASS domain\user computername
- [[ -z $PASS || $PASS == "None" ]] && exit 1
- xfreerdp /v:hostname_or_ip /f /u:$USER /p:$PASS /cert-ignore +fonts /drive:ubuntu-home,$HOME /printer
Add Comment
Please, Sign In to add comment