From ce0acf1505f49994c07a26460d78a21b91c8ae57 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Sat, 13 Aug 2016 17:17:16 -0500 Subject: [PATCH] Support alternate gpg program (#19) --- yadm | 20 ++++++++++++++++---- yadm.1 | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/yadm b/yadm index cbf8e80..d5170ff 100755 --- a/yadm +++ b/yadm @@ -29,6 +29,8 @@ YADM_CONFIG="config" YADM_ENCRYPT="encrypt" YADM_ARCHIVE="files.gpg" +GPG_PROGRAM="gpg" + #; flag when something may have changes (which prompts auto actions to be performed) CHANGES_POSSIBLE=0 @@ -214,7 +216,7 @@ function decrypt() { fi #; decrypt the archive - (gpg -d "$YADM_ARCHIVE" || echo 1) | tar v${tar_option}f - -C "$YADM_WORK" + ($GPG_PROGRAM -d "$YADM_ARCHIVE" || echo 1) | tar v${tar_option}f - -C "$YADM_WORK" if [ $? = 0 ] ; then [ ! "$DO_LIST" = "YES" ] && echo "All files decrypted." else @@ -261,7 +263,7 @@ function encrypt() { echo #; encrypt all files which match the globs - tar -f - -c "${GLOBS[@]}" | gpg --yes "${GPG_OPTS[@]}" --output "$YADM_ARCHIVE" + tar -f - -c "${GLOBS[@]}" | $GPG_PROGRAM --yes "${GPG_OPTS[@]}" --output "$YADM_ARCHIVE" if [ $? = 0 ]; then echo "Wrote new file: $YADM_ARCHIVE" else @@ -574,8 +576,18 @@ function require_git() { error_out "This functionality requires Git to be installed, but the command git cannot be located." } function require_gpg() { - command -v gpg >/dev/null 2>&1 || \ - error_out "This functionality requires GPG to be installed, but the command gpg cannot be located." + local alt_gpg + alt_gpg="$(config yadm.gpg-program)" + + local more_info + more_info="" + + if [ "$alt_gpg" != "" ] ; then + GPG_PROGRAM="$alt_gpg" + more_info="\nThis command has been set via the yadm.gpg-program configuration." + fi + command -v "$GPG_PROGRAM" >/dev/null 2>&1 || \ + error_out "This functionality requires GPG to be installed, but the command '$GPG_PROGRAM' cannot be located.$more_info" } function require_repo() { [ -d "$YADM_REPO" ] || error_out "Git repo does not exist. did you forget to run 'init' or 'clone'?" diff --git a/yadm.1 b/yadm.1 index a23514f..b9fe242 100644 --- a/yadm.1 +++ b/yadm.1 @@ -301,6 +301,10 @@ If left blank or not provided, symmetric encryption is used instead. If set to "ASK", gpg will interactively ask for recipients. See the ENCRYPTION section for more details. This feature is disabled by default. +.TP +.B yadm.gpg-program +Specify an alternate program to use instead of "gpg". +By default, the first "gpg" found in $PATH is used. .SH ALTERNATES When managing a set of files across different systems, it can be useful to have an automated way of choosing an alternate version of a file for a different