Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3b39e0c3eab40098a3d5f71d1a6f47d7a0b49e20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/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

Back to the top