Skip to content

Commit

Permalink
Use sed to replace envsubst
Browse files Browse the repository at this point in the history
envsubst will replace all env var, when the var is empty, it will repalce with a empty string
  • Loading branch information
EkkoG committed Oct 21, 2023
1 parent 3026a84 commit bbe0af9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
fi
4 changes: 2 additions & 2 deletions modules/openclash/files/etc/uci-defaults/90-openclash
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit bbe0af9

Please sign in to comment.