forked from pool/obs-service-replace_using_env
e338628f5a
OBS-URL: https://build.opensuse.org/package/show/Virtualization/obs-service-replace_using_env?expand=0&rev=1
51 lines
732 B
Bash
51 lines
732 B
Bash
#!/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
|