summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-07-24 20:06:46 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-07-24 20:06:46 +0200
commit5f12b6443d362a3949f0c289d59c3acf2bc6c649 (patch)
treea9ae9364effc8b410c505d232b7e92c95bc2f7aa
parentee68d6ccf2224950eef655cdba4fed93e062f253 (diff)
downloadpass-5f12b6443d362a3949f0c289d59c3acf2bc6c649.tar.gz
pass-5f12b6443d362a3949f0c289d59c3acf2bc6c649.tar.bz2
pass-5f12b6443d362a3949f0c289d59c3acf2bc6c649.zip
Add git support.
-rw-r--r--README7
-rwxr-xr-xpassword-store.sh44
2 files changed, 48 insertions, 3 deletions
diff --git a/README b/README
index df900b5..b362a11 100644
--- a/README
+++ b/README
@@ -8,6 +8,9 @@ This is a very simple password store that encrypts passwords using gpg and
places the encrypted password in a directory. It can generate new passwords
and keep track of old ones.
+If the password storage directory ($HOME/.password-store) is also a git
+repository, add/remove/change operations will create a corresponding git
+commit.
Usage:
pass --init gpg-id
@@ -22,6 +25,10 @@ Usage:
Generate a new password of pass-length with optionally no symbols.
pass --remove pass-name
Remove existing password.
+ pass --push
+ If the password store is a git repository, push the latest changes.
+ pass --pull
+ If the password store is a git repository, pull the latest changes.
pass --help
Show help text.
diff --git a/password-store.sh b/password-store.sh
index 4730133..58e7dcd 100755
--- a/password-store.sh
+++ b/password-store.sh
@@ -4,6 +4,10 @@ umask 077
PREFIX="$HOME/.password-store"
ID="$PREFIX/.gpg-id"
+GIT="$PREFIX/.git"
+
+export GIT_DIR="$GIT"
+export GIT_WORK_TREE="$PREFIX"
usage() {
cat <<_EOF
@@ -24,6 +28,10 @@ Usage:
Generate a new password of pass-length with optionally no symbols.
$0 --remove pass-name
Remove existing password.
+ $0 --push
+ If the password store is a git repository, push the latest changes.
+ $0 --pull
+ If the password store is a git repository, pull the latest changes.
$0 --help
Show this text.
_EOF
@@ -68,13 +76,18 @@ elif [[ $1 == "--insert" ]]; then
fi
mkdir -p -v "$PREFIX/$(dirname "$2")"
+ passfile="$PREFIX/$2.gpg"
if [[ $ml -eq 0 ]]; then
echo -n "Enter password for $2: "
- head -n 1 | gpg -e -r "$ID" > "$PREFIX/$2.gpg"
+ head -n 1 | gpg -e -r "$ID" > "$passfile"
else
echo "Enter contents of $2 and press Ctrl+D when finished:"
echo
- cat | gpg -e -r "$ID" > "$PREFIX/$2.gpg"
+ cat | gpg -e -r "$ID" > "$passfile"
+ fi
+ if [[ -d $GIT ]]; then
+ git add "$passfile"
+ git commit -m "Added given password for $2 to store."
fi
elif [[ $1 == "--generate" ]]; then
if [[ $# -lt 3 ]]; then
@@ -92,7 +105,12 @@ elif [[ $1 == "--generate" ]]; then
fi
mkdir -p -v "$PREFIX/$(dirname "$2")"
pass="$(pwgen -s $symbols $3 1)"
- echo $pass | gpg -e -r "$ID" > "$PREFIX/$2.gpg"
+ passfile="$PREFIX/$2.gpg"
+ echo $pass | gpg -e -r "$ID" > "$passfile"
+ if [[ -d $GIT ]]; then
+ git add "$passfile"
+ git commit -m "Added generated password for $2 to store."
+ fi
echo "The generated password to $2 is:"
echo "$pass"
elif [[ $1 == "--remove" ]]; then
@@ -106,6 +124,26 @@ elif [[ $1 == "--remove" ]]; then
exit 1
fi
rm -i -v "$passfile"
+ if [[ -d $GIT ]] && ! [[ -f "$passfile" ]]; then
+ git rm -f "$passfile"
+ git commit -m "Removed $2 from store."
+ fi
+elif [[ $1 == "--push" ]]; then
+ if [[ -d $GIT ]]; then
+ shift
+ exec git push $@
+ else
+ echo "Error: the password store is not a git repository."
+ exit 1
+ fi
+elif [[ $1 == "--pull" ]]; then
+ if [[ -d $GIT ]]; then
+ shift
+ exec git pull $@
+ else
+ echo "Error: the password store is not a git repository."
+ exit 1
+ fi
elif [[ $# -eq 1 ]]; then
passfile="$PREFIX/$1.gpg"
if ! [[ -f $passfile ]]; then