Skip to content

Instantly share code, notes, and snippets.

@io41
Created January 30, 2012 17:29
Show Gist options
  • Save io41/1705556 to your computer and use it in GitHub Desktop.
Save io41/1705556 to your computer and use it in GitHub Desktop.
__profile_d()
{
# i.e. __profile_d_mysql_ssl/foo/bar
local d=$1
[ "$d" ] || exit 0
if [ "${d%__profile_d*}" ]; then
echo "$d"
exit 0
fi
# i.e. foo/bar
local path=${d#*/}
# i.e. __profile_d_mysql_ssl
d=${d%%/*}
local var="\${$d"
local end="}"
while true; do
# Strip off the last _*
d=${d%_*}
# Build up variable evaluation
var="${var}-\${$d"
end="${end}}"
[ "$d" = "__profile_d" ] && break # No more name spaces left
done
var="${var}${end}"
[ "$path" ] && var="${var}/$path"
eval "echo \"${var}\""
}
__eval_paths()
{
eval "$(set | grep "^__fa_" | sed 's/^\([^=]*\)=.*/\1=$(__profile_d "$\1");/')"
}
# set/override where to find files
__profile_d=production.d/mysql
# The config vars
__fa_mysql_mycnf=__profile_d_mysql_mycnf/my.cnf
__fa_mysql_client_ssl_ca=__profile_d_mysql_ssl_ca/example.ca
__fa_mysql_client_ssl_cert=__profile_d_mysql_ssl_cert/example.cert
__fa_mysql_client_ssl_key=__profile_d_mysql_ssl_cert/example.key
__fa_mysql_client_user=root
# override just a specific set of files
__profile_d_mysql_ssl=tim.d/mysql
__profile_d_mysql_ssl_key=old.d/mysql
__eval_paths
# view vars and their values
set | grep "^__fa_"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment