Skip to content

Commit

Permalink
added environment variable support to script
Browse files Browse the repository at this point in the history
  • Loading branch information
Cielquan committed Nov 27, 2019
1 parent 9ba775b commit 8cff59e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions start_doth_dns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ else
fi


# ##########################################################################################
# Grabbing EnvVars
if [[ ${_FLAG_FRESH} == 'y' ]]; then
printf "%bINFO: %b Skipped loading of Environment Variables.\n\n" "${CYAN}" "${BLANK}"
else
if \
_ENV_ARCHITECTURE=${DOTH_ARCHITECTURE} &&
_ENV_INTERFACE=${DOTH_INTERFACE} &&
_ENV_HOST_IP=${DOTH_HOST_IP} &&
_ENV_HOST_NAME=${DOTH_HOST_NAME} &&
_ENV_TIMEZONE=${DOTH_TIMEZONE} &&
_ENV_DOMAIN=${DOTH_DOMAIN}
then
printf "%bINFO: %b Environment Variables loaded.\n\n" "${CYAN}" "${BLANK}"
else
printf "%bWARNING:%b No Environment Variables could be loaded. Falling back to self gather information.\n\n" \
"${ORANGE}" "${BLANK}"
fi
fi


# ##########################################################################################
### Check and set ENV Vars
# Set ARCHITECTURE
Expand All @@ -191,6 +212,13 @@ elif [[ -n "${ARCHITECTURE}" ]]; then
printf "%bERROR: %b Failed to set ARCHITECTURE by .env file.\n" "${RED}" "${BLANK}"
exit_err
fi
elif [[ -n "${_ENV_ARCHITECTURE}" ]]; then
if _ARCHITECTURE="${_ENV_ARCHITECTURE}"; then
printf "%bINFO: %b ARCHITECTURE set by Environment Variable to '%s'.\n" "${CYAN}" "${BLANK}" "${_ARCHITECTURE}"
else
printf "%bERROR: %b Failed to set ARCHITECTURE by Environment Variable.\n" "${RED}" "${BLANK}"
exit_err
fi
if [[ -n "${_ARCHITECTURE}" ]]; then
if _ARCHITECTURE=$(lscpu | grep Architecture: | awk '{print $2}'); then
printf "%bINFO: %b ARCHITECTURE was determined and set to '%s'.\n" "${CYAN}" "${BLANK}" "${_ARCHITECTURE}"
Expand All @@ -217,6 +245,13 @@ elif [[ -n "${INTERFACE}" ]]; then
printf "%bERROR: %b Failed to set INTERFACE by .env file.\n" "${RED}" "${BLANK}"
exit_err
fi
elif [[ -n "${_ENV_INTERFACE}" ]]; then
if _INTERFACE="${_ENV_INTERFACE}"; then
printf "%bINFO: %b INTERFACE set by Environment Variable to '%s'.\n" "${CYAN}" "${BLANK}" "${_INTERFACE}"
else
printf "%bERROR: %b Failed to set INTERFACE by Environment Variable.\n" "${RED}" "${BLANK}"
exit_err
fi
if [[ -n "${_INTERFACE}" ]]; then
if _INTERFACE=$(route | grep '^default' | grep -o '[^ ]*$'); then
printf "%bINFO: %b INTERFACE was determined and set to '%s'.\n" "${CYAN}" "${BLANK}" "${_INTERFACE}"
Expand All @@ -243,6 +278,13 @@ elif [[ -n "${HOST_IP}" ]]; then
printf "%bERROR: %b Failed to set HOST_IP by .env file.\n" "${RED}" "${BLANK}"
exit_err
fi
elif [[ -n "${_ENV_HOST_IP}" ]]; then
if _HOST_IP="${_ENV_HOST_IP}"; then
printf "%bINFO: %b HOST_IP set by Environment Variable to '%s'.\n" "${CYAN}" "${BLANK}" "${_HOST_IP}"
else
printf "%bERROR: %b Failed to set HOST_IP by Environment Variable.\n" "${RED}" "${BLANK}"
exit_err
fi
if [[ -n "${_HOST_IP}" ]]; then
if _HOST_IP=$(ifconfig "${_INTERFACE}" | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'); then
printf "%bINFO: %b HOST_IP was determined and set to '%s'.\n" "${CYAN}" "${BLANK}" "${_HOST_IP}"
Expand Down Expand Up @@ -270,6 +312,13 @@ elif [[ -n "${HOST_NAME}" ]]; then
printf "%bERROR: %b Failed to set HOST_NAME by .env file.\n" "${RED}" "${BLANK}"
exit_err
fi
elif [[ -n "${_ENV_HOST_NAME}" ]]; then
if _HOST_NAME="${_ENV_HOST_NAME}"; then
printf "%bINFO: %b HOST_NAME set by Environment Variable to '%s'.\n" "${CYAN}" "${BLANK}" "${_HOST_NAME}"
else
printf "%bERROR: %b Failed to set HOST_NAME by Environment Variable.\n" "${RED}" "${BLANK}"
exit_err
fi
if [[ -n "${_HOST_NAME}" ]]; then
if _HOST_NAME=$(hostname); then
printf "%bINFO: %b HOST_NAME was determined and set to '%s'.\n" "${CYAN}" "${BLANK}" "${_HOST_NAME}"
Expand All @@ -296,6 +345,13 @@ elif [[ -n "${TIMEZONE}" ]]; then
printf "%bERROR: %b Failed to set TIMEZONE by .env file.\n" "${RED}" "${BLANK}"
exit_err
fi
elif [[ -n "${_ENV_TIMEZONE}" ]]; then
if _TIMEZONE="${_ENV_TIMEZONE}"; then
printf "%bINFO: %b TIMEZONE set by Environment Variable to '%s'.\n" "${CYAN}" "${BLANK}" "${_TIMEZONE}"
else
printf "%bERROR: %b Failed to set TIMEZONE by Environment Variable.\n" "${RED}" "${BLANK}"
exit_err
fi
if [[ -n "${_TIMEZONE}" ]]; then
if _TIMEZONE=$(timedatectl | grep 'Time zone' | awk '{print $3}'); then
printf "%bINFO: %b TIMEZONE was determined and set to '%s'.\n" "${CYAN}" "${BLANK}" "${_TIMEZONE}"
Expand All @@ -322,6 +378,13 @@ elif [[ -n "${DOMAIN}" ]]; then
printf "%bERROR: %b Failed to set DOMAIN by .env file.\n" "${RED}" "${BLANK}"
exit_err
fi
elif [[ -n "${_ENV_DOMAIN}" ]]; then
if _DOMAIN="${_ENV_DOMAIN}"; then
printf "%bINFO: %b DOMAIN set by Environment Variable to '%s'.\n" "${CYAN}" "${BLANK}" "${_DOMAIN}"
else
printf "%bERROR: %b Failed to set DOMAIN by Environment Variable.\n" "${RED}" "${BLANK}"
exit_err
fi
if [[ -n "${_DOMAIN}" ]]; then
if _DOMAIN="${_HOST_NAME}.dns"; then
printf "%bINFO: %b DOMAIN was determined and set to '%s'.\n" "${CYAN}" "${BLANK}" "${_DOMAIN}"
Expand Down

0 comments on commit 8cff59e

Please sign in to comment.