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
This commit is contained in:
parent
aaa4152fac
commit
00133032ef
1 changed files with 16 additions and 10 deletions
26
yadm
26
yadm
|
@ -33,6 +33,7 @@ YADM_BOOTSTRAP="bootstrap"
|
||||||
GPG_PROGRAM="gpg"
|
GPG_PROGRAM="gpg"
|
||||||
GIT_PROGRAM="git"
|
GIT_PROGRAM="git"
|
||||||
LS_PROGRAM="/bin/ls"
|
LS_PROGRAM="/bin/ls"
|
||||||
|
ENVTPL_PROGRAM="envtpl"
|
||||||
|
|
||||||
#; flag causing path translations with cygpath
|
#; flag causing path translations with cygpath
|
||||||
USE_CYGPATH=0
|
USE_CYGPATH=0
|
||||||
|
@ -198,22 +199,23 @@ function alt() {
|
||||||
#; loop over all "tracked" files
|
#; loop over all "tracked" files
|
||||||
#; for every file which is a *##yadm_tmpl create a real file
|
#; for every file which is a *##yadm_tmpl create a real file
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local match="^(.+)##yadm_tmpl"
|
local match="^(.+)##yadm_tmpl$"
|
||||||
local envtpl_bin=$(which envtpl)
|
|
||||||
for tracked_file in $("$GIT_PROGRAM" ls-files | sort) $(cat "$YADM_ENCRYPT" 2>/dev/null); do
|
for tracked_file in $("$GIT_PROGRAM" ls-files | sort) $(cat "$YADM_ENCRYPT" 2>/dev/null); do
|
||||||
tracked_file="$YADM_WORK/$tracked_file"
|
tracked_file="$YADM_WORK/$tracked_file"
|
||||||
if [ -e "$tracked_file" ] ; then
|
if [ -e "$tracked_file" ] ; then
|
||||||
if [[ $tracked_file =~ $match ]] ; then
|
if [[ $tracked_file =~ $match ]] ; then
|
||||||
if [[ -z "$envtpl_bin" ]]; then
|
real_file="${BASH_REMATCH[1]}"
|
||||||
debug "'envtpl' (pip install envtpl) not available, not creating $real_file from template $tracked_file"
|
if envtpl_available; then
|
||||||
[ -n "$loud" ] && echo "'envtpl' (pip install envtpl) not available, not creating $real_file from template $tracked_file"
|
|
||||||
else
|
|
||||||
real_file="${BASH_REMATCH[1]}"
|
|
||||||
debug "Creating $real_file from template $tracked_file"
|
debug "Creating $real_file from template $tracked_file"
|
||||||
[ -n "$loud" ] && echo "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_CLASS="$local_class" \
|
||||||
YADM_HOSTNAME="$local_host" YADM_USER="$local_user" \
|
YADM_OS="$local_system" \
|
||||||
$envtpl_bin < $tracked_file > $real_file
|
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
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -844,6 +846,10 @@ function bootstrap_available() {
|
||||||
[ -f "$YADM_BOOTSTRAP" ] && [ -x "$YADM_BOOTSTRAP" ] && return
|
[ -f "$YADM_BOOTSTRAP" ] && [ -x "$YADM_BOOTSTRAP" ] && return
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
function envtpl_available() {
|
||||||
|
command -v "$ENVTPL_PROGRAM" >/dev/null 2>&1 && return
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
#; ****** Directory tranlations ******
|
#; ****** Directory tranlations ******
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue