Skip to content

Commit

Permalink
Update env_update.sh & .env.example
Browse files Browse the repository at this point in the history
Remove extra newline at end of `.env.example`, add the newline in the app headings instead.

Fix up naming of variables slightly.

Select a heading format instead of the heading itself when looping between `BUILTIN` and `USER_DEFINED` headings.
  • Loading branch information
CLHatch committed Jun 5, 2024
1 parent d48aaf4 commit f1596f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
21 changes: 11 additions & 10 deletions .scripts/env_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ env_update() {

# Clear lists before processing an app's variables
local APP_LABELS=()
local ENV_BUILTIN_VARS=()
local ENV_USER_DEFINED_VARS=()
local ENV_VARS_BUILTIN=()
local ENV_VARS_USER_DEFINED=()

# Process lines for one app
for index in "${!CURRENT_ENV_VARS[@]}"; do
Expand Down Expand Up @@ -104,10 +104,10 @@ env_update() {
# shellcheck disable=SC2199
if [[ " ${APP_LABELS[@]} " == *" ${VAR} "* ]]; then
# Variable is in label file, add it to the built in list
ENV_BUILTIN_VARS+=("$VAR")
ENV_VARS_BUILTIN+=("$VAR")
else
# Variable is not in label file, add it to the user defined list
ENV_USER_DEFINED_VARS+=("$VAR")
ENV_VARS_USER_DEFINED+=("$VAR")
fi
fi
# Remove processed var from array
Expand All @@ -116,16 +116,17 @@ env_update() {

# Add the lines to the env file from the built in list and user defined list for the last app being processed
# shellcheck disable=SC2034 # Variable is used indirectly
local BUILTIN_HEADING="${LAST_APPNAME-}"
local HEADING_FORMAT_BUILTIN="\n##\n## %s\n##"
# shellcheck disable=SC2034 # Variable is used indirectly
local USER_DEFINED_HEADING="${LAST_APPNAME-} (User Defined)"
local HEADING_FORMAT_USER_DEFINED="\n##\n## %s (User Defined)\n##"
for section in BUILTIN USER_DEFINED; do
local VARS="ENV_${section}_VARS[@]"
local VARS="ENV_VARS_${section}[@]"
if [[ -n ${!VARS-} ]]; then
# Add all app variables for section to updated .env
local HEADING="${section}_HEADING"
printf -v ${HEADING} '#\n# %s\n#' "${!HEADING}"
UPDATED_ENV_LINES+=("${!HEADING}")
local HEADING_FORMAT="HEADING_FORMAT_${section}"
local HEADING
printf -v HEADING "${!HEADING_FORMAT}" "${LAST_APPNAME-}"
UPDATED_ENV_LINES+=("${HEADING}")
for VAR in "${!VARS}"; do
UPDATED_ENV_LINES+=("${CURRENT_ENV_VAR_LINE[$VAR]}")
#UPDATED_ENV_VAR_INDEX[$VAR]=$((${#UPDATED_ENV_LINES[@]} - 1))
Expand Down
1 change: 0 additions & 1 deletion compose/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ PUID=1000
TZ=America/Chicago

# END OF DEFAULT SETTINGS

0 comments on commit f1596f9

Please sign in to comment.