重构代码, 抽取变量
This commit is contained in:
parent
0fcb985e2d
commit
8b32dc3ebe
@ -3,20 +3,21 @@
|
|||||||
print_share_link() {
|
print_share_link() {
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
||||||
local config_dir=$(readlink -f "$script_dir/../")
|
local config_dir=$(readlink -f "$script_dir/../")
|
||||||
|
local config_file="$config_dir/config/config.json"
|
||||||
source "${script_dir}/utils/base.sh"
|
source "${script_dir}/utils/base.sh"
|
||||||
|
|
||||||
# 检查jq是否安装
|
# 检查jq是否安装
|
||||||
check_jq
|
check_jq
|
||||||
|
|
||||||
# 检查配置文件是否存在
|
# 检查配置文件是否存在
|
||||||
if [ ! -f "$config_dir/config/config.json" ]; then
|
if [ ! -f "$config_file" ]; then
|
||||||
red "error: 配置文件未生成, 查看配置失败"
|
red "error: 配置文件未生成, 查看配置失败"
|
||||||
echo '请选择"生成配置 / 重置配置"'
|
echo '请选择"生成配置 / 重置配置"'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查是否已启动过容器
|
# 检查是否已启动过容器
|
||||||
local password=$(jq -r '.auth.password' "$config_dir/config/config.json")
|
local password=$(jq -r '.auth.password' "$config_file")
|
||||||
if [ "$password" = "你的密码" ]; then
|
if [ "$password" = "你的密码" ]; then
|
||||||
red "error: 容器未启动过, 查看配置失败"
|
red "error: 容器未启动过, 查看配置失败"
|
||||||
echo '请选择"启动容器"'
|
echo '请选择"启动容器"'
|
||||||
@ -25,12 +26,12 @@ print_share_link() {
|
|||||||
|
|
||||||
# 检查是否使用ACME证书
|
# 检查是否使用ACME证书
|
||||||
local allowInsecure=1 # 默认跳过证书验证
|
local allowInsecure=1 # 默认跳过证书验证
|
||||||
if jq -e '.acme' "$config_dir/config/config.json" > /dev/null 2>&1; then
|
if jq -e '.acme' "$config_file" > /dev/null 2>&1; then
|
||||||
allowInsecure=0 # 不跳过证书验证
|
allowInsecure=0 # 不跳过证书验证
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 读取配置文件内容
|
# 读取配置文件内容
|
||||||
local config=$(cat "$config_dir/config/config.json")
|
local config=$(cat "$config_file")
|
||||||
|
|
||||||
# 提取所需信息
|
# 提取所需信息
|
||||||
password=$(echo "$config" | jq -r '.auth.password')
|
password=$(echo "$config" | jq -r '.auth.password')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user