重构代码, 抽取变量
This commit is contained in:
parent
542c7e8994
commit
0c860eb78d
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
create_config_with_tls_cert() {
|
create_config_with_tls_cert() {
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
||||||
|
local config_file="$script_dir/../config/config.json"
|
||||||
|
|
||||||
cp "$script_dir/../config/template/tls_cert_config.json" "$script_dir/../config/config.json"
|
cp "$script_dir/../config/template/tls_cert_config.json" "$config_file"
|
||||||
|
|
||||||
# 设置端口
|
# 设置端口
|
||||||
bash "$script_dir/update_port.sh"
|
bash "$script_dir/update_port.sh"
|
||||||
@ -35,9 +36,6 @@ create_config_with_tls_cert() {
|
|||||||
read -p "请输入你的 Cloudflare API Token: " cloudflare_token
|
read -p "请输入你的 Cloudflare API Token: " cloudflare_token
|
||||||
done
|
done
|
||||||
|
|
||||||
# 替换配置文件中的占位符
|
|
||||||
local config_file="$script_dir/../config/config.json"
|
|
||||||
|
|
||||||
# 使用 sed 替换邮箱
|
# 使用 sed 替换邮箱
|
||||||
sed -i "s/你的邮箱/$user_email/g" "$config_file"
|
sed -i "s/你的邮箱/$user_email/g" "$config_file"
|
||||||
|
|
||||||
@ -72,14 +70,15 @@ create_self_tls_config() {
|
|||||||
|
|
||||||
create_config(){
|
create_config(){
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
||||||
|
local config_file="$script_dir/../config/config.json"
|
||||||
|
|
||||||
# 如果配置文件不存在, 创建空白配置文件
|
# 如果配置文件不存在, 创建空白配置文件
|
||||||
if [ ! -e "$script_dir/../config/config.json" ]; then
|
if [ ! -e "$config_file" ]; then
|
||||||
touch "$script_dir/../config/config.json"
|
touch "$config_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local config_password=$(jq -r '.auth.password' "$script_dir/../config/config.json")
|
local config_password=$(jq -r '.auth.password' "$config_file")
|
||||||
if [ -s "$script_dir/../config/config.json" ] && [ "$config_password" != "你的密码" ]; then
|
if [ -s "$config_file" ] && [ "$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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user