From ef88c20cdcfa2c3396ed7ce63915765fee088af6 Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Tue, 17 May 2016 17:43:19 +0200 Subject: First draft PoC at tidier env wrangling --- kerl | 102 ++++++++++++------------------------------------------------------- 1 file changed, 18 insertions(+), 84 deletions(-) diff --git a/kerl b/kerl index 58cc66e..a28657e 100755 --- a/kerl +++ b/kerl @@ -28,98 +28,32 @@ GREP_OPTIONS='' ERLANG_DOWNLOAD_URL="http://www.erlang.org/download" # Default values -: ${OTP_GITHUB_URL:="https://github.com/erlang/otp"} -: ${KERL_BASE_DIR:="$HOME"/.kerl} : ${KERL_CONFIG:="$HOME"/.kerlrc} + +# Take a snapshot of the env +_FULL_ENV="$(env)" +# By restoring the env after .kerlrc, we can set system defaults in .kerlrc +# but session defaults in env. + +# source the config file if available +if [ -f "$KERL_CONFIG" ]; then . "$KERL_CONFIG"; fi + +# Restore the env over .kerlrc's contents +echo "$_FULL_ENV" | while read -r e ; do + # This doesn't work, probably because eval is a subshell + eval "export \"$e\"" + done + +# By holding defaults until now, we are sure not to clobber settings from env or .kerlrc +: ${KERL_BASE_DIR:="$HOME"/.kerl} : ${KERL_DOWNLOAD_DIR:="${KERL_BASE_DIR:?}"/archives} : ${KERL_BUILD_DIR:="${KERL_BASE_DIR:?}"/builds} : ${KERL_GIT_DIR:="${KERL_BASE_DIR:?}"/gits} - -if [ -n "$OTP_GITHUB_URL" ]; then - _OGU="$OTP_GITHUB_URL" -fi -if [ -n "$KERL_CONFIGURE_OPTIONS" ]; then - _KCO="$KERL_CONFIGURE_OPTIONS" -fi -if [ -n "$KERL_CONFIGURE_APPLICATIONS" ]; then - _KCA="$KERL_CONFIGURE_APPLICATIONS" -fi -if [ -n "$KERL_CONFIGURE_DISABLE_APPLICATIONS" ]; then - _KCDA="$KERL_CONFIGURE_DISABLE_APPLICATIONS" -fi -if [ -n "$KERL_SASL_STARTUP" ]; then - _KSS="$KERL_SASL_STARTUP" -fi -if [ -n "$KERL_DEPLOY_SSH_OPTIONS" ]; then - _KDSSH="$KERL_DEPLOY_SSH_OPTIONS" -fi -if [ -n "$KERL_DEPLOY_RSYNC_OPTIONS" ]; then - _KDRSYNC="$KERL_DEPLOY_RSYNC_OPTIONS" -fi -if [ -n "$KERL_INSTALL_MANPAGES" ]; then - _KIM="$KERL_INSTALL_MANPAGES" -fi -if [ -n "$KERL_BUILD_PLT" ]; then - _KBPLT="$KERL_BUILD_PLT" -fi -if [ -n "$KERL_BUILD_DOCS" ]; then - _KBD="$KERL_BUILD_DOCS" -fi -if [ -n "$KERL_BUILD_BACKEND" ]; then - _KBB="$KERL_BUILD_BACKEND" -fi -OTP_GITHUB_URL= -KERL_CONFIGURE_OPTIONS= -KERL_CONFIGURE_APPLICATIONS= -KERL_CONFIGURE_DISABLE_APPLICATIONS= -KERL_SASL_STARTUP= -KERL_DEPLOY_SSH_OPTIONS= -KERL_DEPLOY_RSYNC_OPTIONS= -KERL_INSTALL_MANPAGES= -KERL_BUILD_PLT= -KERL_BUILD_DOCS= -KERL_BUILD_BACKEND= +: ${OTP_GITHUB_URL:="https://github.com/erlang/otp"} # ensure the base dir exists mkdir -p "$KERL_BASE_DIR" || exit 1 -# source the config file if available -if [ -f "$KERL_CONFIG" ]; then . "$KERL_CONFIG"; fi - -if [ -n "$_OGU" ]; then - OTP_GITHUB_URL="$_OGU" -fi -if [ -n "$_KCO" ]; then - KERL_CONFIGURE_OPTIONS="$_KCO" -fi -if [ -n "$_KCA" ]; then - KERL_CONFIGURE_APPLICATIONS="$_KCA" -fi -if [ -n "$_KCDA" ]; then - KERL_CONFIGURE_DISABLE_APPLICATIONS="$_KCDA" -fi -if [ -n "$_KSS" ]; then - KERL_SASL_STARTUP="$_KSS" -fi -if [ -n "$_KDSSH" ]; then - KERL_DEPLOY_SSH_OPTIONS="$_KDSSH" -fi -if [ -n "$_KDRSYNC" ]; then - KERL_DEPLOY_RSYNC_OPTIONS="$_KDRSYNC" -fi -if [ -n "$_KIM" ]; then - KERL_INSTALL_MANPAGES="$_KIM" -fi -if [ -n "$_KBPLT" ]; then - KERL_BUILD_PLT="$_KBPLT" -fi -if [ -n "$_KBD" ]; then - KERL_BUILD_DOCS="$_KBD" -fi -if [ -n "$_KBB" ]; then - KERL_BUILD_BACKEND="$_KBB" -fi - if [ -z "$KERL_SASL_STARTUP" ]; then INSTALL_OPT=-minimal else -- cgit v1.2.3