Skip to content

Commit

Permalink
优化启动脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry committed Apr 23, 2024
1 parent 727d430 commit 2f53b85
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export VERSION=$(cat /app/version)

ENV_FILE="/app/.env"

# 读取 .env 文件并导出环境变量,跳过已存在的环境变量
grep -v -e '^#' -e '^$' "$ENV_FILE" | while read -r line; do
key=$(echo "$line" | cut -d '=' -f 1)
if [ -z "${!key+x}" ]; then
# 导出整个键值对
export "$line"
grep -v -e '^#' -e '^$' "$ENV_FILE" | while IFS='=' read -r key value; do
if [ -z "$key" ] || [ -z "$value" ]; then
continue
fi

if ! declare -p "$key" &>/dev/null; then
echo "Setting $key=$value"
export "$key=$value"
fi
done

Expand Down

0 comments on commit 2f53b85

Please sign in to comment.