Support alternate gpg program (#19)

This commit is contained in:
Tim Byrne 2016-08-13 17:17:16 -05:00
parent e4d1b3a165
commit ce0acf1505
No known key found for this signature in database
GPG Key ID: 6CBE24C2FD8CF76E
2 changed files with 20 additions and 4 deletions

20
yadm
View File

@ -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'?"

4
yadm.1
View File

@ -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