aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/password-store.sh
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-03-22 13:26:04 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2014-03-22 13:26:08 -0600
commita41ce86e2315202311765cba144be71b36f90e82 (patch)
treeff10cd9f6eb39275675c3c8556a8ea6e12308023 /src/password-store.sh
parentclip: rename SELECTION to X_SELECTION (diff)
downloadpassword-store-a41ce86e2315202311765cba144be71b36f90e82.tar.xz
password-store-a41ce86e2315202311765cba144be71b36f90e82.zip
gpg: allow the use of gpg1 with or without agent
Suggested-by: Matthieu Weber <mweber@free.fr>
Diffstat (limited to 'src/password-store.sh')
-rwxr-xr-xsrc/password-store.sh25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/password-store.sh b/src/password-store.sh
index 5b5d36e..b0c0422 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -5,10 +5,15 @@
umask 077
-GPG_OPTS="--quiet --yes --batch --compress-algo=none"
+GPG_OPTS="--quiet --yes --compress-algo=none"
+GPG="gpg"
+which gpg2 &>/dev/null && GPG="gpg2"
+[[ -n $GPG_AGENT_INFO || $GPG == "gpg2" ]] && GPG_OPTS="$GPT_OPTS --batch --use-agent"
+
PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
+
export GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git"
export GIT_WORK_TREE="${PASSWORD_STORE_GIT:-$PREFIX}"
@@ -204,7 +209,7 @@ case "$command" in
passfile_dir=${passfile_dir#$PREFIX}
passfile_dir=${passfile_dir#/}
set_gpg_recipients "$passfile_dir"
- gpg2 -d $GPG_OPTS "$passfile" | gpg2 -e "${gpg_recipient_args[@]}" -o "$passfile.new" $GPG_OPTS &&
+ $GPG -d $GPG_OPTS "$passfile" | $GPG -e "${gpg_recipient_args[@]}" -o "$passfile.new" $GPG_OPTS &&
mv -v "$passfile.new" "$passfile"
done
git_add_file "$PREFIX/$id_path" "Reencrypted password store using new GPG id ${id_print}."
@@ -239,9 +244,9 @@ case "$command" in
passfile="$PREFIX/$path.gpg"
if [[ -f $passfile ]]; then
if [[ $clip -eq 0 ]]; then
- exec gpg2 -d $GPG_OPTS "$passfile"
+ exec $GPG -d $GPG_OPTS "$passfile"
else
- pass="$(gpg2 -d $GPG_OPTS "$passfile" | head -n 1)"
+ pass="$($GPG -d $GPG_OPTS "$passfile" | head -n 1)"
[[ -n $pass ]] || exit 1
clip "$pass" "$path"
fi
@@ -287,7 +292,7 @@ case "$command" in
if [[ $multiline -eq 1 ]]; then
echo "Enter contents of $path and press Ctrl+D when finished:"
echo
- gpg2 -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS
+ $GPG -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS
elif [[ $noecho -eq 1 ]]; then
while true; do
read -r -p "Enter password for $path: " -s password
@@ -295,7 +300,7 @@ case "$command" in
read -r -p "Retype password for $path: " -s password_again
echo
if [[ $password == "$password_again" ]]; then
- gpg2 -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS <<<"$password"
+ $GPG -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS <<<"$password"
break
else
echo "Error: the entered passwords do not match."
@@ -303,7 +308,7 @@ case "$command" in
done
else
read -r -p "Enter password for $path: " -e password
- gpg2 -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS <<<"$password"
+ $GPG -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS <<<"$password"
fi
git_add_file "$passfile" "Added given password for $path to store."
;;
@@ -326,11 +331,11 @@ case "$command" in
action="Added"
if [[ -f $passfile ]]; then
- gpg2 -d -o "$tmp_file" $GPG_OPTS "$passfile" || exit 1
+ $GPG -d -o "$tmp_file" $GPG_OPTS "$passfile" || exit 1
action="Edited"
fi
${EDITOR:-vi} "$tmp_file"
- while ! gpg2 -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS "$tmp_file"; do
+ while ! $GPG -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS "$tmp_file"; do
echo "GPG encryption failed. Retrying."
sleep 1
done
@@ -369,7 +374,7 @@ case "$command" in
pass="$(pwgen -s $symbols $length 1)"
[[ -n $pass ]] || exit 1
- gpg2 -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS <<<"$pass"
+ $GPG -e "${gpg_recipient_args[@]}" -o "$passfile" $GPG_OPTS <<<"$pass"
git_add_file "$passfile" "Added generated password for $path to store."
if [[ $clip -eq 0 ]]; then