From bbe0af9026d75f7335c8e76f24165fbc95a07fbd Mon Sep 17 00:00:00 2001 From: EkkoG Date: Sat, 21 Oct 2023 15:33:03 +0800 Subject: [PATCH] Use sed to replace envsubst envsubst will replace all env var, when the var is empty, it will repalce with a empty string --- build.sh | 18 ++++++++---------- .../files/etc/uci-defaults/90-openclash | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/build.sh b/build.sh index 30ae147..6fbcd18 100755 --- a/build.sh +++ b/build.sh @@ -24,7 +24,6 @@ done final_modules="$(echo "$final_modules" | tr '\n' ' ')" echo "Final modules: $final_modules" cp -r modules work_modules -ls work_modules for module in $final_modules; do @@ -33,15 +32,14 @@ for module in $final_modules; do fi if [ -f "work_modules/$module/.env" ]; then - echo "Running envsubst for $module" - mv work_modules/$module/.env work_modules/$module/.env.tmp - # add export to .env, every line - sed -i 's/^/export /' work_modules/$module/.env.tmp - . work_modules/$module/.env.tmp - # envsubst + . work_modules/$module/.env for file in $(find "work_modules/$module/files/etc/uci-defaults" -type f); do - envsubst < $file | sed -e 's/§/$/g' > $file.tmp - mv $file.tmp $file + all_env="$(cat work_modules/$module/.env)" + for env in $all_env; do + env_name="$(echo "$env" | cut -d '=' -f 1)" + env_value="$(echo "$env" | cut -d '=' -f 2)" + sed -e "s|\$$env_name|$env_value|g" -i $file + done done fi @@ -64,4 +62,4 @@ if [ -z "$PROFILE" ]; then make image PACKAGES="$all_packages" FILES="files" else make PROFILE="$PROFILE" image PACKAGES="$all_packages" FILES="files" -fi \ No newline at end of file +fi diff --git a/modules/openclash/files/etc/uci-defaults/90-openclash b/modules/openclash/files/etc/uci-defaults/90-openclash index 4493d8f..a0ab7f6 100755 --- a/modules/openclash/files/etc/uci-defaults/90-openclash +++ b/modules/openclash/files/etc/uci-defaults/90-openclash @@ -5,12 +5,12 @@ while uci -q delete openclash.@config_subscribe[0]; do :; done while uci -q delete openclash.@authentication[0]; do :; done password=$DASHBOARD_PASSWORD -if [ -z "§password" ]; then +if [ -z "$password" ]; then password=$(openssl rand -base64 12) fi uci batch << EOF -set openclash.config.dashboard_password='§password' +set openclash.config.dashboard_password='$password' add openclash authentication set openclash.@authentication[-1]=authentication set openclash.@authentication[-1].enabled='0'