| #!/bin/bash |
| |
| umask 0077 |
| |
| #logFile="$HOME/.managePasswords.log" |
| #echo "first arg $0" 1>"$logFile" |
| #echo "second arg $1" 1>>"$logFile" |
| |
| inputDialog="$HOME/inputDialog.tcl" |
| passFile="$HOME/.gitPwdData" |
| |
| originUrl=`git config --get remote.origin.url` |
| containsUsername=`git config --get remote.origin.url | grep -c "@"` |
| |
| getPassword() { |
| |
| #echo "File: $passFile" 1>>"$logFile" |
| if [ -e "$passFile" ] |
| then |
| # echo "Storage File - Found" 1>>"$logFile" |
| password=`git config --file "$passFile" --get remote."$originUrl".password` |
| # echo "From file: $password" 1>>"$logFile" |
| else |
| # echo "Storage File - Not Found" 1>>"$logFile" |
| echo "#Git Passwords" 1>"$passFile" |
| fi |
| |
| |
| if [ -z "$password" ] |
| then |
| # echo "Password From File Null - [$password]" 1>>"$logFile" |
| password=`exec wish "$inputDialog" -- "Git Password" "Enter Password" | sed 's/^{//' | sed 's/}$//'` |
| fi |
| |
| |
| #Save password in file |
| if [ -n "$password" ] |
| then |
| # echo "Password Not Null - [$password]" 1>>"$logFile" |
| git config --file "$passFile" remote."$originUrl".password ""$password"" |
| fi |
| |
| echo "$password" |
| } |
| |
| getUsername() { |
| |
| #echo "File: $passFile" 1>>"$logFile" |
| if [ -e "$passFile" ] |
| then |
| # echo "Storage File - Found" 1>>"$logFile" |
| username=`git config --file "$passFile" --get remote."$originUrl".username` |
| # echo "From file: $username" 1>>"$logFile" |
| else |
| # echo "Storage File - Not Found" 1>>"$logFile" |
| echo "#Git Passwords" 1>"$passFile" |
| fi |
| |
| |
| if [ -z "$username" ] |
| then |
| # echo "Username From File Null - [$username]" 1>>"$logFile" |
| username=`exec wish "$inputDialog" -- "Git UserName" "Enter UserName" | sed 's/^{//' | sed 's/}$//'` |
| fi |
| |
| |
| #Save username in file |
| if [ -n "$username" ] |
| then |
| # echo "Password Not Null - [$username]" 1>>"$logFile" |
| git config --file "$passFile" remote."$originUrl".username ""$username"" |
| fi |
| |
| echo "$username" |
| } |
| |
| changePassword(){ |
| |
| if [ ! -e "$passFile" ] |
| then |
| echo "#Git Passwords" 1>"$passFile" |
| fi |
| |
| if [ "0" -eq "$containsUsername" ] |
| then |
| new_username=`exec wish "$inputDialog" -- "Git UserName" "Enter UserName" | sed 's/^{//' | sed 's/}$//'` |
| if [ -n "$new_username" ] |
| then |
| git config --file "$passFile" remote."$originUrl".username ""$new_username"" |
| fi |
| fi |
| |
| new_password=`exec wish "$inputDialog" -- "Git Password" "Enter Password" | sed 's/^{//' | sed 's/}$//'` |
| if [ -n "$new_password" ] |
| then |
| git config --file "$passFile" remote."$originUrl".password ""$new_password"" |
| fi |
| } |
| |
| |
| case "$1" in |
| update) |
| changePassword |
| ;; |
| *) |
| if [[ $1 == P* ]] |
| then |
| getPassword |
| else |
| getUsername |
| fi |
| exit 0 |
| esac |