summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-10-28 10:59:59 +0100
committerPeter Wu <lekensteyn@gmail.com>2013-10-28 10:59:59 +0100
commit7867923e113c53472ffc9acbc55b80d167103161 (patch)
treef55b8fc4ca6515d8cd35d780afbe89a712cfd147
parentf2f5b446a4ee6b4d7f2647058e32325cc4d668bc (diff)
downloadscripts-7867923e113c53472ffc9acbc55b80d167103161.tar.gz
git-credential-kwallet-mailtransports: git helper
Useful for using git-send-email without storing typing the long passwords all the time.
-rwxr-xr-xgit-credential-kwallet-mailtransports75
1 files changed, 75 insertions, 0 deletions
diff --git a/git-credential-kwallet-mailtransports b/git-credential-kwallet-mailtransports
new file mode 100755
index 0000000..a1b9045
--- /dev/null
+++ b/git-credential-kwallet-mailtransports
@@ -0,0 +1,75 @@
+#!/bin/bash
+mtcnf=$HOME/.kde4/share/config/mailtransports
+walletname=mailtransports
+
+warn() {
+ echo "${0##*/}: $1" >&2
+}
+
+action=$1
+
+case $action in
+get|store|erase) ;;
+*)
+ warn "Unknown action $action"
+ exit 1
+esac
+
+while IFS== read key val; do
+ case $key in
+ protocol)
+ protocol=$val
+ ;;
+ host)
+ host=$val
+ ;;
+ path)
+ # ignoring path
+ ;;
+ username)
+ username=$val
+ ;;
+ password)
+ password=$val
+ ;;
+ url)
+ warn "URLs are not parsed"
+ ;;
+ *)
+ warn "Ignoring unrecognized key $key"
+ ;;
+ esac
+done
+
+if [[ $protocol != smtp ]]; then
+ warn "Only smtp protocol is supported"
+ exit 1
+fi
+
+transportid=
+while read tid; do
+ cfguser=$(kreadconfig --file "$mtcnf" --group "Transport $tid" --key user)
+ if [[ $cfguser == $username ]]; then
+ transportid=$tid
+ break
+ fi
+done < <(grep -Po '^\[Transport \K[0-9]+' "$mtcnf")
+
+if [ -z "$transportid" ]; then
+ warn "Mailtransport not found"
+ exit 1
+fi
+
+case $action in
+get)
+ password=$(kwalletcli -f "$walletname" -e "$transportid" 2>/dev/null)
+ if [ $? -ne 0 ]; then
+ warn "Cannot retrieve password"
+ exit 1
+ fi
+ echo "password=$password"
+ ;;
+store|erase)
+ warn "Ignored action $action"
+ ;;
+esac