Sync from SUSE:SLFO:Main obs-service-replace_using_env revision 59a65364d3f7b15c1f21bde2795f4080
This commit is contained in:
50
replace_using_env
Normal file
50
replace_using_env
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
VARS=()
|
||||
FILES=()
|
||||
VERBOSE=
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
param="$1"
|
||||
arg="$2"
|
||||
|
||||
case "${param}" in
|
||||
--eval)
|
||||
eval "${arg}"
|
||||
shift 2
|
||||
;;
|
||||
--var)
|
||||
VARS+=(${arg})
|
||||
shift 2
|
||||
;;
|
||||
--file)
|
||||
FILES+=(${arg})
|
||||
shift 2
|
||||
;;
|
||||
--verbose)
|
||||
VERBOSE=1
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
echo "Ignoring unknown parameter: ${param}"
|
||||
shift
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ${#FILES[@]} -eq 0 ]; then
|
||||
echo "No input files"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for var in ${VARS[@]}; do
|
||||
echo "Replacing '${var}' with '${!var}'"
|
||||
sed -i"" \
|
||||
-e "s#%%${var}%%#${!var}#g" \
|
||||
"${FILES[@]}"
|
||||
done
|
||||
|
||||
if [ -n "${VERBOSE}" ]; then
|
||||
cat ${FILES[@]}
|
||||
fi
|
Reference in New Issue
Block a user