run中自动生成新的.env.example文件

This commit is contained in:
wandoubaba 2023-10-30 10:29:22 +08:00
parent 95e81c0f1f
commit 1762a0a7b7
2 changed files with 37 additions and 9 deletions

View File

@ -15,7 +15,7 @@ JSONRPC_SERVER_COUNT = cpu_count()
# REDIS配置
REDIS_HOST = 127.0.0.1
REDIS_PORT = 6379
REDIS_PASSWORD = null
REDIS_PASSWORD =
REDIS_DATABASE = 0
# 数据库
@ -43,4 +43,3 @@ SQLITE_PREFIX =
# log
LOG_MAX_FIlES = 30
LOG_MAX_FILES_DEBUG = 3
LOG_MAX_FIlES_ERROR = 90

29
run
View File

@ -15,6 +15,35 @@ if [ ! -f "docker-compose.yml" ]; then
exit 1
fi
# 自动生成.env文件对应的.env.example文件
generate_env_example() {
# 清空原有的.env.example文件中的内容
> .env.example
# 逐行读取.env文件
while IFS= read -r line; do
# 去除首尾空格
line=$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# 如果是注释行或空白行,直接写入.env.example文件
if [[ $line == \#* || -z $line ]]; then
echo "$line" >> .env.example
# 如果是键值对行,判断键名是否包含指定字符串
elif [[ $line == *=* ]]; then
key=$(echo "$line" | cut -d= -f1)
value=$(echo "$line" | cut -d= -f2-)
# 如果键名包含指定字符串,将值清空写入.env.example文件
if [[ $key == *KEY || $key == *PASSWORD || $key == *SECRET || $key == *PASS || $key == *TOKEN || $key == *ID ]]; then
echo "$key=" >> .env.example
# 否则,清除首尾空格后原样写入.env.example文件
else
echo "$key=$value" >> .env.example
fi
fi
done < .env
}
# 每次run后都自动生成.env.example文件
generate_env_example
# 定义帮助函数
show_help() {
echo "Usage: ./run [COMMAND] [OPTION]"