Skip to content

Instantly share code, notes, and snippets.

@pamtrak06
Created November 26, 2017 00:16
Show Gist options
  • Save pamtrak06/90699e1bae728a68d592fea54a30f812 to your computer and use it in GitHub Desktop.
Save pamtrak06/90699e1bae728a68d592fea54a30f812 to your computer and use it in GitHub Desktop.
generate list of variables from a properties file, for envsubst
# generate list of variables from a properties file
# form : \$VARIABLE
# give it to envsubst command to avoid escaping others variable in template file
function generate-parameters-list-for-envsubst {
type=$1
local pts
local pindex
unset parameters
pts=$(cat $properties|grep export|cut -d "=" -f 1|sed "s/export //g")
declare -a plist
pindex=0
for p in $(echo $pts); do
plist[pindex]=$(echo ${p})
let "pindex = $pindex + 1"
done
parameters=""
for s in $(seq 0 $(( ${#plist[@]} -1 )) ); do
[ -n "$parameters" ] && \
parameters=$(echo "$parameters,\\\$${plist[$s]}")
[ -z "$envp" ] && \
parameters=$(echo "\\\$${plist[$s]}")
#echo "Element : " ${plist[$s]}
done
#echo "properties : " ${parameters}
echo -n ""
}
function update-from-template {
properties=$1
template=$2
result=$3
generate-parameters-list-for-envsubst "$properties"
#echo "properties : " ${envp}
[ -f "${template}" ] && \
. ${properties} && envsubst ${parameters} < "${template}" | tee "${result}" > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment