From c029b8ad112799c8b565d4384db89d5b19d12586 Mon Sep 17 00:00:00 2001 From: Craig Andera Date: Fri, 6 Jul 2018 11:46:40 -0400 Subject: [PATCH 1/4] Support -v switch for debugging. --- zerkenv | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zerkenv b/zerkenv index 3357f89..b05dea4 100755 --- a/zerkenv +++ b/zerkenv @@ -453,10 +453,11 @@ install_bash() { cat <<'EOT' |envsubst '$prog $name' $name() { local OPTIND OPTARG o newshell=false - while getopts "hn" o; do + while getopts "hnv" o; do case "${o}" in h) echo "USAGE: $name [-hn] ..." ; return ;; n) newshell=true ;; + v) set -xf ;; ?) return 1 ;; esac done @@ -512,7 +513,7 @@ opt_update_cache=false opt_delete_cache=false opt_delete_s3=false -while getopts "cdhi:lruw:W:x:X:" o; do +while getopts "cdhi:lruw:W:x:X:v" o; do case "${o}" in c) opt_completions=true ; break ;; d) opt_resolve_deps=true ; break ;; @@ -525,6 +526,7 @@ while getopts "cdhi:lruw:W:x:X:" o; do W) put_s3 $OPTARG ; exit $? ;; x) opt_delete_cache=true ; : $((OPTIND--)) ; break ;; X) opt_delete_s3=true ; : $((OPTIND--)) ; break ;; + v) set -xv ; break ;; ?) exit 1 ;; esac done From d4015cd2b95e85f1601da10608b7dd8af37d31ea Mon Sep 17 00:00:00 2001 From: Craig Andera Date: Fri, 6 Jul 2018 11:46:51 -0400 Subject: [PATCH 2/4] Source does not work with process redirection Under OS X, you can't do `. <(echo whatever)` - it just fails. Looks to be a bug in OS X's version of bash. Workaround: use a tempfile. --- zerkenv | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zerkenv b/zerkenv index b05dea4..4346ac3 100755 --- a/zerkenv +++ b/zerkenv @@ -466,7 +466,10 @@ $name() { if $newshell; then eval "( $name $* ; exec $BASH )" else - . <(colors=true $prog -d "$@") + local ZERKENV_TEMPFILE=$(mktemp) + colors=true $prog -d "$@" > $ZERKENV_TEMPFILE + . $ZERKENV_TEMPFILE + rm $ZERKENV_TEMPFILE fi } _$prog() { From 993d7813df773fa085770de51c529ce172c7d983 Mon Sep 17 00:00:00 2001 From: Craig Andera Date: Tue, 7 Aug 2018 14:31:30 -0400 Subject: [PATCH 3/4] Buncha fixes to address OS X bash lameness. --- zerkenv | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/zerkenv b/zerkenv index 4346ac3..c6c5385 100755 --- a/zerkenv +++ b/zerkenv @@ -372,8 +372,9 @@ update_cache() { } rm_cache() { - local module file - for module in "$@"; do + local modules module file + modules="$@" + for module in "$modules"; do file=$(cache_file $module) if [ -f "$file" ]; then info "* $module" @@ -385,9 +386,10 @@ rm_cache() { } rm_s3() { - local module file + local modules module file + modules="$@" assert_s3 - for module in "$@"; do + for module in "$modules"; do file=$(s3_file $module) if aws s3 rm "$file" --region $ZERKENV_REGION; then info "* $module" @@ -398,21 +400,26 @@ rm_s3() { } resolve_dependencies_impl() { - local deps module ZERKENV_DEPENDENCIES + local modules deps module ZERKENV_DEPENDENCIES MODULE_LIST + modules="$@" + + for module in $modules; do + ZERKENV_MODULE_TEMP=$(mktemp) + get_cache_or_s3 $module > $ZERKENV_MODULE_TEMP + source $ZERKENV_MODULE_TEMP + rm $ZERKENV_MODULE_TEMP - for module in "$@"; do - . <(get_cache_or_s3 $module) for dep in $module $ZERKENV_DEPENDENCIES; do deps="$deps $dep $module" done ZERKENV_DEPENDENCIES= done - echo "$deps" |tsort + echo "$deps" |tsort | sort } resolve_dependencies() { - local i deps prev=$(for i in "$@"; do echo $i; done) + local i deps prev=$(for i in "$@"; do echo $i; done | sort) export ZERKENV_RESOLVING_DEPENDENCIES=true while true; do From 976c4937c8298a9a7dc15b6a4704160e77e0f679 Mon Sep 17 00:00:00 2001 From: Craig Andera Date: Tue, 7 Aug 2018 14:57:25 -0400 Subject: [PATCH 4/4] Go back to using "$@" - it's not broken. --- zerkenv | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/zerkenv b/zerkenv index c6c5385..adca93d 100755 --- a/zerkenv +++ b/zerkenv @@ -353,12 +353,12 @@ get_cache_or_s3() { } update_cache() { - local module found modules="$@" local_modules=$(ls_cache) remote_modules + local module found local_modules=$(ls_cache) remote_modules remote_modules=$(ls_s3) if [ $# -eq 0 ]; then modules=$(sort <(echo "$remote_modules") <(echo "$local_modules") |uniq -d) fi - for module in $modules; do + for module in "$@"; do found=$(sort <(echo "$module") <(echo "$remote_modules") |uniq -d) if ! not_private $module; then warn "* $module is private so cannot be updated from S3" @@ -372,9 +372,9 @@ update_cache() { } rm_cache() { - local modules module file - modules="$@" - for module in "$modules"; do + local module file + + for module in "$@"; do file=$(cache_file $module) if [ -f "$file" ]; then info "* $module" @@ -386,10 +386,9 @@ rm_cache() { } rm_s3() { - local modules module file - modules="$@" + local module file assert_s3 - for module in "$modules"; do + for module in "$@"; do file=$(s3_file $module) if aws s3 rm "$file" --region $ZERKENV_REGION; then info "* $module" @@ -400,10 +399,9 @@ rm_s3() { } resolve_dependencies_impl() { - local modules deps module ZERKENV_DEPENDENCIES MODULE_LIST - modules="$@" + local deps module ZERKENV_DEPENDENCIES - for module in $modules; do + for module in "$@"; do ZERKENV_MODULE_TEMP=$(mktemp) get_cache_or_s3 $module > $ZERKENV_MODULE_TEMP source $ZERKENV_MODULE_TEMP