-
Notifications
You must be signed in to change notification settings - Fork 0
/
kpassman-git-credential-helper
executable file
·66 lines (61 loc) · 2.22 KB
/
kpassman-git-credential-helper
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
#!/bin/bash
# kpassman-git-credential-helper - Credential helper for use with git.
# Decrypts stored gpg password files and passes the password to git when set as credential.helper
# Written by simonizor https://www.simonizor.gq
# Dependencies: gpg, kdialog
# License: GPL v2 Only
if type kdialog >/dev/null 2>&1; then
KDIALOG='kdialog'
elif [ -f "$RUNNING_DIR/pydialog/pydialog.py" ]; then
KDIALOG="$RUNNING_DIR/pydialog/pydialog.py"
else
echo "Missing dependencies needed to run!"
exit 1
fi
if [ -d "$HOME/.gpgpassman" ] && [ -f "$HOME/.gpgpassman/.kpassman.config" ]; then
KPASS_DIR="$HOME/.gpgpassman"
elif [ -d "$HOME/.kpassman" ] && [ -f "$HOME/.kpassman/.kpassman.config" ]; then
KPASS_DIR="$HOME/.kpassman"
else
mkdir "$HOME"/.kpassman
KPASS_DIR="$HOME/.kpassman"
echo "KPASS_DIR="\"$KPASS_DIR\""" > "$KPASS_DIR"/.kpassman.config
fi
. "$KPASS_DIR"/.kpassman.config
gitpasssaveconffunc () {
echo "TIMES_RAN=$TIMES_RAN" > "$KPASS_DIR"/.githelper.config
echo "GIT_USERNAME="\"$GIT_USERNAME\""" >> "$KPASS_DIR"/.githelper.config
echo "GIT_GPGFILE="\"$GIT_GPGFILE\""" >> "$KPASS_DIR"/.githelper.config
}
if [ ! -f "$KPASS_DIR/.githelper.config" ]; then
TIMES_RAN=1
GIT_USERNAME="$($KDIALOG --title "kpassman" --inputbox "<h2 align="center">kpassman</h2><h2 align="center"><img src='/opt/kpassman/kpassman.png' width=50></h2><h4 align="center">First time configuration for kpassman's git credential helper</h4><h4 align="center">Enter your Github username:</h4>")"
case $? in
1)
exit 0
;;
esac
GIT_GPGFILE="$($KDIALOG --title "Select encrypted gpg password for github" --getopenfilename "$KPASS_DIR")"
case $? in
1)
exit 0
;;
esac
gitpasssaveconffunc
exit 0
fi
. "$KPASS_DIR"/.githelper.config
case $TIMES_RAN in
0)
echo -n "username=$GIT_USERNAME"
TIMES_RAN=1
gitpasssaveconffunc
exit 0
;;
1)
echo -n "password="$(echo -n $($KDIALOG --title "kpassman" --password "Enter your password to decrypt Github $GIT_USERNAME:") | gpg --passphrase-fd 0 --batch --yes -d "$GIT_GPGFILE")""
TIMES_RAN=0
gitpasssaveconffunc
exit 0
;;
esac