fix: enhance config file checks to prevent errors on missing or empty files
Add checks using `-s` flag to verify config.json existence and non-emptiness before processing passwords, avoiding potential script failures when the file is absent or zero-length, improving robustness.
This commit is contained in:
parent
ed4a86997d
commit
c91e4935c3
@ -73,7 +73,7 @@ create_self_tls_config() {
|
|||||||
create_config(){
|
create_config(){
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
||||||
local config_password=$(jq -r '.auth.password' "$script_dir/../config.json")
|
local config_password=$(jq -r '.auth.password' "$script_dir/../config.json")
|
||||||
if [ "$config_password" != "你的密码" ]; then
|
if [ -s "$script_dir/../config.json" ] && [ "$config_password" != "你的密码" ]; then
|
||||||
local regenerate
|
local regenerate
|
||||||
read -p "检测到配置已存在,是否重新生成配置?(y/n): " regenerate
|
read -p "检测到配置已存在,是否重新生成配置?(y/n): " regenerate
|
||||||
if [ "$regenerate" != "y" ] && [ "$regenerate" != "Y" ]; then
|
if [ "$regenerate" != "y" ] && [ "$regenerate" != "Y" ]; then
|
||||||
|
|||||||
@ -15,7 +15,7 @@ run() {
|
|||||||
|
|
||||||
# 如果配置没有创建
|
# 如果配置没有创建
|
||||||
local password=$(jq -r '.auth.password' "$config_dir/config.json")
|
local password=$(jq -r '.auth.password' "$config_dir/config.json")
|
||||||
if [ "$password" = "你的密码" ]; then
|
if [ ! -s "$config_dir/config.json" ] || [ "$password" = "你的密码" ]; then
|
||||||
bash "$script_dir/create_config.sh" # 创建配置
|
bash "$script_dir/create_config.sh" # 创建配置
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user