From 5a05be06c7eed00ce8b276d27055d89629fbf7d7 Mon Sep 17 00:00:00 2001 From: Simon Gate Date: Wed, 26 Apr 2017 14:34:20 +0200 Subject: [PATCH] Don't complain about GPG_AGENT_INFO if using newer gpg-agent (#189) --- bin/_blackbox_common.sh | 17 ++++++ bin/_stack_lib.sh | 106 +++++++++++++++++++++++++++++++++ bin/blackbox_decrypt_all_files | 6 +- bin/blackbox_diff | 8 +-- bin/blackbox_update_all_files | 8 +-- bin/blackbox_whatsnew | 8 +-- 6 files changed, 128 insertions(+), 25 deletions(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 6ff377a..a987d84 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -681,3 +681,20 @@ function vcs_notice_generic_file() { echo "WARNING: If so, manually update the ignore file" fi } + +function gpg_agent_version_check() { + if ! hash 'gpg-agent' &> /dev/null; then + return 1 + fi + local gpg_agent_version=$(gpg-agent --version | head -1 | awk '{ print $3 }' | tr -d '\n') + semverLT $gpg_agent_version "2.1.0" +} + +function gpg_agent_notice() { + if [[ $(gpg_agent_version_check) == '0' && -z $GPG_AGENT_INFO ]];then + echo 'WARNING: You probably want to run gpg-agent as' + echo 'you will be asked for your passphrase many times.' + echo 'Example: $ eval $(gpg-agent --daemon)' + read -r -p 'Press CTRL-C now to stop. ENTER to continue: ' + fi +} diff --git a/bin/_stack_lib.sh b/bin/_stack_lib.sh index b51b138..8ca801a 100755 --- a/bin/_stack_lib.sh +++ b/bin/_stack_lib.sh @@ -180,3 +180,109 @@ function fail_if_in_root_directory() { ;; esac } + +function semverParseInto() { + local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' + #MAJOR + eval $2=`echo $1 | sed -e "s#$RE#\1#"` + #MINOR + eval $3=`echo $1 | sed -e "s#$RE#\2#"` + #MINOR + eval $4=`echo $1 | sed -e "s#$RE#\3#"` + #SPECIAL + eval $5=`echo $1 | sed -e "s#$RE#\4#"` +} + +function semverEQ() { + local MAJOR_A=0 + local MINOR_A=0 + local PATCH_A=0 + local SPECIAL_A=0 + + local MAJOR_B=0 + local MINOR_B=0 + local PATCH_B=0 + local SPECIAL_B=0 + + semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A + semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B + + if [ $MAJOR_A -ne $MAJOR_B ]; then + return 1 + fi + + if [ $MINOR_A -ne $MINOR_B ]; then + return 1 + fi + + if [ $PATCH_A -ne $PATCH_B ]; then + return 1 + fi + + if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then + return 1 + fi + + + return 0 + +} + +function semverLT() { + local MAJOR_A=0 + local MINOR_A=0 + local PATCH_A=0 + local SPECIAL_A=0 + + local MAJOR_B=0 + local MINOR_B=0 + local PATCH_B=0 + local SPECIAL_B=0 + + semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A + semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B + + if [ $MAJOR_A -lt $MAJOR_B ]; then + return 0 + fi + + if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then + return 0 + fi + + if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then + return 0 + fi + + if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then + return 1 + fi + if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then + return 1 + fi + if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then + return 0 + fi + + if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then + return 0 + fi + + return 1 + +} + +function semverGT() { + semverEQ $1 $2 + local EQ=$? + + semverLT $1 $2 + local LT=$? + + if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then + return 0 + else + return 1 + fi +} + diff --git a/bin/blackbox_decrypt_all_files b/bin/blackbox_decrypt_all_files index 667c9d3..479bb54 100755 --- a/bin/blackbox_decrypt_all_files +++ b/bin/blackbox_decrypt_all_files @@ -14,9 +14,7 @@ export PATH=/usr/bin:/bin:"$PATH" set -e +source "${0%/*}/_blackbox_common.sh" -if [[ -z $GPG_AGENT_INFO ]]; then - eval $(gpg-agent --daemon) -fi - +gpg_agent_notice exec blackbox_postdeploy "$@" diff --git a/bin/blackbox_diff b/bin/blackbox_diff index 7133900..069e6e7 100755 --- a/bin/blackbox_diff +++ b/bin/blackbox_diff @@ -7,13 +7,7 @@ set -e source "${0%/*}/_blackbox_common.sh" -if [[ -z $GPG_AGENT_INFO ]]; then - echo 'WARNING: You probably want to run gpg-agent as' - echo 'you will be asked for your passphrase many times.' - echo 'Example: $ eval $(gpg-agent --daemon)' - read -r -p 'Press CTRL-C now to stop. ENTER to continue: ' -fi - +gpg_agent_notice prepare_keychain modified_files=() diff --git a/bin/blackbox_update_all_files b/bin/blackbox_update_all_files index fc5eb90..aae485d 100755 --- a/bin/blackbox_update_all_files +++ b/bin/blackbox_update_all_files @@ -7,13 +7,7 @@ set -e source "${0%/*}/_blackbox_common.sh" -if [[ -z $GPG_AGENT_INFO ]]; then - echo 'WARNING: You probably want to run gpg-agent as' - echo 'you will be asked for your passphrase many times.' - echo 'Example: $ eval $(gpg-agent --daemon)' - read -r -p 'Press CTRL-C now to stop. ENTER to continue: ' -fi - +gpg_agent_notice disclose_admins prepare_keychain diff --git a/bin/blackbox_whatsnew b/bin/blackbox_whatsnew index d0fdee0..9f85390 100755 --- a/bin/blackbox_whatsnew +++ b/bin/blackbox_whatsnew @@ -14,13 +14,7 @@ then fi fail_if_not_in_repo - -if [[ -z $GPG_AGENT_INFO ]]; then - echo 'WARNING: You probably want to run gpg-agent as' - echo 'you will be asked for your passphrase many times.' - echo 'Example: $ eval $(gpg-agent --daemon)' - read -r -p 'Press CTRL-C now to stop. ENTER to continue: ' -fi +gpg_agent_notice COLUMNS=`tput cols` FILE=$1