From 00133032ef7e0e0362f9803e89e265dfc202fa0f Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Thu, 30 Mar 2017 23:51:23 -0500 Subject: [PATCH] Add minor improvements to template processing * Determine envtpl using `command -v` instead of `which` (more portable) * Anchor the end of template file names in regex * Quote variables to allow for whitespace in file names --- yadm | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/yadm b/yadm index 0730292..d936fd2 100755 --- a/yadm +++ b/yadm @@ -33,6 +33,7 @@ YADM_BOOTSTRAP="bootstrap" GPG_PROGRAM="gpg" GIT_PROGRAM="git" LS_PROGRAM="/bin/ls" +ENVTPL_PROGRAM="envtpl" #; flag causing path translations with cygpath USE_CYGPATH=0 @@ -198,22 +199,23 @@ function alt() { #; loop over all "tracked" files #; for every file which is a *##yadm_tmpl create a real file local IFS=$'\n' - local match="^(.+)##yadm_tmpl" - local envtpl_bin=$(which envtpl) + local match="^(.+)##yadm_tmpl$" for tracked_file in $("$GIT_PROGRAM" ls-files | sort) $(cat "$YADM_ENCRYPT" 2>/dev/null); do tracked_file="$YADM_WORK/$tracked_file" if [ -e "$tracked_file" ] ; then if [[ $tracked_file =~ $match ]] ; then - if [[ -z "$envtpl_bin" ]]; then - debug "'envtpl' (pip install envtpl) not available, not creating $real_file from template $tracked_file" - [ -n "$loud" ] && echo "'envtpl' (pip install envtpl) not available, not creating $real_file from template $tracked_file" - else - real_file="${BASH_REMATCH[1]}" + real_file="${BASH_REMATCH[1]}" + if envtpl_available; then debug "Creating $real_file from template $tracked_file" [ -n "$loud" ] && echo "Creating $real_file from template $tracked_file" - YADM_CLASS="$local_class" YADM_OS="$local_system" \ - YADM_HOSTNAME="$local_host" YADM_USER="$local_user" \ - $envtpl_bin < $tracked_file > $real_file + YADM_CLASS="$local_class" \ + YADM_OS="$local_system" \ + YADM_HOSTNAME="$local_host" \ + YADM_USER="$local_user" \ + "$ENVTPL_PROGRAM" < "$tracked_file" > "$real_file" + else + debug "envtpl not available, not creating $real_file from template $tracked_file" + [ -n "$loud" ] && echo "envtpl not available, not creating $real_file from template $tracked_file" fi fi fi @@ -844,6 +846,10 @@ function bootstrap_available() { [ -f "$YADM_BOOTSTRAP" ] && [ -x "$YADM_BOOTSTRAP" ] && return return 1 } +function envtpl_available() { + command -v "$ENVTPL_PROGRAM" >/dev/null 2>&1 && return + return 1 +} #; ****** Directory tranlations ******