From a648fb8e46e2b2dea8133c246d9157757f70f6ca Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Sun, 28 Jun 2015 19:26:47 -0400 Subject: [PATCH 01/11] Added / Pruned quotes and separated local variable declaration from assignment. --- bin/_blackbox_common.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index fb93f18..1f43b6e 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -105,7 +105,7 @@ function fail_if_not_on_cryptlist() { if ! is_on_cryptlist "$name" ; then echo "ERROR: $name not found in $BB_FILES" >&2 - echo "PWD="$(/bin/pwd) >&2 + echo "PWD=""$(/bin/pwd)" >&2 echo 'Exiting...' >&2 exit 1 fi @@ -131,12 +131,12 @@ function get_pubring_path() { # Output the unencrypted filename. function get_unencrypted_filename() { - echo $(dirname "$1")/$(basename "$1" .gpg) | sed -e 's#^\./##' + echo "$(dirname "$1")"/"$(basename "$1" .gpg)" | sed -e 's#^\./##' } # Output the encrypted filename. function get_encrypted_filename() { - echo $(dirname "$1")/$(basename "$1" .gpg).gpg | sed -e 's#^\./##' + echo "$(dirname "$1")"/"$(basename "$1" .gpg)".gpg | sed -e 's#^\./##' } # Prepare keychain for use. @@ -150,7 +150,8 @@ function prepare_keychain() { function add_filename_to_cryptlist() { # If the name is already on the list, this is a no-op. # However no matter what the datestamp is updated. - local name=$(vcs_relative_path "$1") + local name + name=$(vcs_relative_path "$1") if file_contains_line "$BB_FILES" "$name" ; then echo "========== File is registered. No need to add to list." @@ -164,19 +165,20 @@ function add_filename_to_cryptlist() { # Removes a file from the list of encrypted files function remove_filename_from_cryptlist() { # If the name is not already on the list, this is a no-op. - local name=$(vcs_relative_path "$1") + local name + name=$(vcs_relative_path "$1") if ! file_contains_line "$BB_FILES" "$name" ; then - echo ========== File is not registered. No need to remove from list. + echo "========== File is not registered. No need to remove from list." else - echo ========== Removing file from list. + echo "========== Removing file from list." remove_line "$BB_FILES" "$name" fi } # Print out who the current BB ADMINS are: function disclose_admins() { - echo ========== blackbox administrators are: + echo "========== blackbox administrators are:" cat "$BB_ADMINS" } @@ -188,7 +190,7 @@ function encrypt_file() { encrypted="$2" echo "========== Encrypting: $unencrypted" >&2 - $GPG --use-agent --yes --trust-model=always --encrypt -o "$encrypted" $(awk '{ print "-r" $1 }' < "$BB_ADMINS") "$unencrypted" >&2 + $GPG --use-agent --yes --trust-model=always --encrypt -o "$encrypted" "$(awk '{ print "-r" $1 }' < "$BB_ADMINS")" "$unencrypted" >&2 echo '========== Encrypting: DONE' >&2 } @@ -200,7 +202,7 @@ function decrypt_file() { encrypted="$1" unencrypted="$2" - echo '========== EXTRACTING ''"'$unencrypted'"' >&2 + echo "========== EXTRACTING $unencrypted" >&2 old_umask=$(umask) umask "$DECRYPT_UMASK" @@ -425,15 +427,15 @@ function vcs_commit() { } # Mercurial function vcs_commit_hg() { - hg commit -m"$@" + hg commit -m "$@" } # Git function vcs_commit_git() { - git commit -m"$@" + git commit -m "$@" } # Subversion function vcs_commit_svn() { - svn commit -m"$@" + svn commit -m "$@" } # Perforce function vcs_commit_p4() { From 26eb8e48cc4c2c91c0f792fb29302850957fcd00 Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 13:00:12 -0400 Subject: [PATCH 02/11] Added is_blackbox_repo enumerate_bloackbox_repos and set in change_vcs_root --- bin/_blackbox_common.sh | 39 +++++++++++++++++++++++++++++++++++++-- bin/blackbox_recurse | 6 ++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100755 bin/blackbox_recurse diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 1f43b6e..109ed8e 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -64,6 +64,15 @@ SECRING="${KEYRINGDIR}/secring.gpg" : "${DECRYPT_UMASK:=0022}" ; # : ${DECRYPT_UMASK:=o=} ; +# Is this a blackbox repo? +function is_blackbox_repo() { + if [[ -d "$1/keyrings" ]] && [[ -n "$1" ]]; then + return 0 # Yep, its a repo + else + return 1 + fi +} + # Return error if not on cryptlist. function is_on_cryptlist() { # Assumes $1 does NOT have the .gpg extension @@ -86,7 +95,6 @@ function fail_if_not_exists() { echo Exiting... >&2 exit 1 fi -} # Exit we we aren't in a VCS repo. function fail_if_not_in_repo() { @@ -276,10 +284,37 @@ function enumerate_subdirs() { done done <"$listfile" | sort -u } + # chdir to the base of the repo. function change_to_vcs_root() { - cd "$REPOBASE" + # if vcs_root not explicitly defined, use $REPOBASE + if [[ -z "$1" ]]; then + cd "$REPOBASE" + + elif is_blackbox_repo "$1"; then + cd "$1" + + else + echo 'ERROR: $1 is not a blackbox Repo' + exit 1 + fi + +} + +# $1 is a string pointing to a directory. Outputs a +# list of valid blackbox repos,relative to $1 +function enumerate_blackbox_repos() { + if [[ -z "$1" ]]; then + echo "enumerate_blackbox_repos: ERROR: No Repo provided to Enumerate" + else + # https://github.com/koalaman/shellcheck/wiki/Sc2045 + for dir in $1*/; do + if is_blackbox_repo "$dir"; then + echo "$dir" + fi + done + fi } # Output the path of a file relative to the repo base diff --git a/bin/blackbox_recurse b/bin/blackbox_recurse new file mode 100755 index 0000000..9ab4b1f --- /dev/null +++ b/bin/blackbox_recurse @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# proposed space for blackbox recurion...coming soon +set -e +source "${0%/*}/_blackbox_common.sh" + +echo "$REBOBASE" From 38b8ced5dd9281e4a49db52adf1f46357719f8ac Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:21:00 -0400 Subject: [PATCH 03/11] check if is null before checking for dir --- bin/_blackbox_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 109ed8e..7b08161 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -66,7 +66,7 @@ SECRING="${KEYRINGDIR}/secring.gpg" # Is this a blackbox repo? function is_blackbox_repo() { - if [[ -d "$1/keyrings" ]] && [[ -n "$1" ]]; then + if [[ -n "$1" ]] && [[ -d "$1/keyrings" ]]; then return 0 # Yep, its a repo else return 1 From 805f66b6b3c0ef7374d9452f995b194a2b31dabd Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:21:26 -0400 Subject: [PATCH 04/11] Add missing } --- bin/_blackbox_common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 7b08161..673772c 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -95,6 +95,7 @@ function fail_if_not_exists() { echo Exiting... >&2 exit 1 fi +} # Exit we we aren't in a VCS repo. function fail_if_not_in_repo() { From 97030854fad6041d4093de467339091b567ae925 Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:23:34 -0400 Subject: [PATCH 05/11] fewer double quotes in fail_if_not_on_cryptlist() --- bin/_blackbox_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 673772c..0e4ba69 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -114,7 +114,7 @@ function fail_if_not_on_cryptlist() { if ! is_on_cryptlist "$name" ; then echo "ERROR: $name not found in $BB_FILES" >&2 - echo "PWD=""$(/bin/pwd)" >&2 + echo "PWD=$(/bin/pwd)" >&2 echo 'Exiting...' >&2 exit 1 fi From a5bf8a5a81eed6f68902be443580f74be0be6cf5 Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:27:17 -0400 Subject: [PATCH 06/11] better linting in get_unencrypted_filename() --- bin/_blackbox_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 0e4ba69..5a2c648 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -140,7 +140,7 @@ function get_pubring_path() { # Output the unencrypted filename. function get_unencrypted_filename() { - echo "$(dirname "$1")"/"$(basename "$1" .gpg)" | sed -e 's#^\./##' + echo "$(dirname "$1")/$(basename "$1" .gpg)" | sed -e 's#^\./##' } # Output the encrypted filename. From b56300a8c78b6f707106b9f1cb8bd64355b8a8f3 Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:28:49 -0400 Subject: [PATCH 07/11] better linting in get_encrypted_filename() --- bin/_blackbox_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 5a2c648..b120048 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -145,7 +145,7 @@ function get_unencrypted_filename() { # Output the encrypted filename. function get_encrypted_filename() { - echo "$(dirname "$1")"/"$(basename "$1" .gpg)".gpg | sed -e 's#^\./##' + echo "$(dirname "$1")/$(basename "$1" .gpg).gpg" | sed -e 's#^\./##' } # Prepare keychain for use. From 2b432e1f3abb30d326df563523850d9f5e3cc7ae Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:41:21 -0400 Subject: [PATCH 08/11] document SC2155 --- bin/_blackbox_common.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index b120048..dfc6076 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -159,6 +159,8 @@ function prepare_keychain() { function add_filename_to_cryptlist() { # If the name is already on the list, this is a no-op. # However no matter what the datestamp is updated. + + # https://github.com/koalaman/shellcheck/wiki/SC2155 local name name=$(vcs_relative_path "$1") @@ -174,6 +176,8 @@ function add_filename_to_cryptlist() { # Removes a file from the list of encrypted files function remove_filename_from_cryptlist() { # If the name is not already on the list, this is a no-op. + + # https://github.com/koalaman/shellcheck/wiki/SC2155 local name name=$(vcs_relative_path "$1") From 53c686fc57db3cdc35b91ebbb7870b1d7385bb28 Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:41:46 -0400 Subject: [PATCH 09/11] document is_blackbox_repo --- bin/_blackbox_common.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index dfc6076..372a3b1 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -64,7 +64,8 @@ SECRING="${KEYRINGDIR}/secring.gpg" : "${DECRYPT_UMASK:=0022}" ; # : ${DECRYPT_UMASK:=o=} ; -# Is this a blackbox repo? +# Checks if $1 is 0 bytes, and if $1/keyrings +# is a directory function is_blackbox_repo() { if [[ -n "$1" ]] && [[ -d "$1/keyrings" ]]; then return 0 # Yep, its a repo From 96c71e3254d688e8b20041e04b272fdf6446d7dd Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:46:18 -0400 Subject: [PATCH 10/11] Better logic for change_to_vcs_root --- bin/_blackbox_common.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 372a3b1..3c99583 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -295,17 +295,13 @@ function enumerate_subdirs() { # chdir to the base of the repo. function change_to_vcs_root() { # if vcs_root not explicitly defined, use $REPOBASE - if [[ -z "$1" ]]; then - cd "$REPOBASE" - elif is_blackbox_repo "$1"; then - cd "$1" - - else - echo 'ERROR: $1 is not a blackbox Repo' + local rbase=${1:-$REPOBASE} # use $1 but if unset use $REPOBASE + + if ! is_blackbox_repo "$rbase"; then + echo "ERROR: $rbase is not a blackbox Repo" exit 1 fi - } # $1 is a string pointing to a directory. Outputs a From 76884eb3966afe64b1f0be5afe44821a52211a72 Mon Sep 17 00:00:00 2001 From: Dan OBoyle Date: Fri, 3 Jul 2015 17:50:00 -0400 Subject: [PATCH 11/11] better logic in enumerate_blackbox_repos --- bin/_blackbox_common.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 3c99583..148b0b4 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -309,14 +309,15 @@ function change_to_vcs_root() { function enumerate_blackbox_repos() { if [[ -z "$1" ]]; then echo "enumerate_blackbox_repos: ERROR: No Repo provided to Enumerate" - else - # https://github.com/koalaman/shellcheck/wiki/Sc2045 - for dir in $1*/; do - if is_blackbox_repo "$dir"; then - echo "$dir" - fi - done + exit 1 fi + + # https://github.com/koalaman/shellcheck/wiki/Sc2045 + for dir in $1*/; do + if is_blackbox_repo "$dir"; then + echo "$dir" + fi + done } # Output the path of a file relative to the repo base