-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-credential-kwalletcli
executable file
·41 lines (33 loc) · 1.16 KB
/
git-credential-kwalletcli
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
#!/usr/bin/env bash
#set -eux -o pipefail
#shopt -s failglob
# Refs
## https://github.com/gistya/expandr/blob/master/expandr.sh
## https://unix.stackexchange.com/questions/154485/how-do-i-capture-stdin-to-a-variable-without-stripping-any-trailing-newlines
KWALLET_NAME=kdewallet
FOLDER_NAME=git-credential-helper-kwalletcli
GIT_CREDENTIAL_INPUT=`cat; echo x`
getParam() {
PARAM_NAME=$1
printf "%s" "${GIT_CREDENTIAL_INPUT%x}" | grep -e "^$PARAM_NAME=" | sed "s/^$PARAM_NAME=//"
}
GIT_PROTOCOL=`getParam "protocol"`
GIT_HOST=`getParam "host"`
GIT_USERNAME=`getParam "username"`
GIT_PASSWORD=`getParam "password"`
logger -t git-credential-kwalletcli "current request : $1"
case $1 in
get)
storedPassword=`kwalletcli -f $FOLDER_NAME -e "$GIT_PROTOCOL://$GIT_USERNAME@$GIT_HOST"`
if [ ! -z "$storedPassword" ]
then
echo "protocol=${GIT_PROTOCOL}"
echo "host=${GIT_HOST}"
echo "username=${GIT_USERNAME}"
echo "password=${storedPassword}"
fi
;;
store)
printf '%s\n' "${GIT_PASSWORD}" | kwalletcli -f $FOLDER_NAME -e "$GIT_PROTOCOL://$GIT_USERNAME@$GIT_HOST" -P
;;
esac