You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
827 B
32 lines
827 B
#!/bin/sh
|
|
set -e
|
|
|
|
usage() {
|
|
echo "usage: $0 [-h] -c CONFIG NAME=DEFAULT..."
|
|
}
|
|
|
|
while getopts hc: opt; do
|
|
case "$opt" in
|
|
c) __cfgfile="$OPTARG";;
|
|
h) echo "source variables from configuration file without clobbering the environment"; usage; exit 0;;
|
|
?) usage; exit 255;;
|
|
esac
|
|
done
|
|
shift $(($OPTIND - 1))
|
|
[ "$#" -ge 1 ] || { usage; exit 255; }
|
|
|
|
(
|
|
# clear old out exports by un-exporting them manually
|
|
while read -r var; do
|
|
eval "__tmp=\"\$$var\"; unset $var; $var=\"\$__tmp\""
|
|
done <<EOI
|
|
$(export -p | sed -e 's/^export //g' | cut -d= -f1)
|
|
EOI
|
|
# introduce our config variables as new exports
|
|
for item; do
|
|
eval "export ${item%%=*}='${item#*=}'"
|
|
done
|
|
# load config file
|
|
[ -z "$__cfgfile" ] || . "$__cfgfile"
|
|
export -p
|
|
) | sed -e '/=/!d' -e 's/^export //g'
|
|
|