From 542c7e89946319263d8bb8c17a67eef9ca63b06a Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Tue, 30 Dec 2025 12:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E6=9D=BF=E5=92=8C=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- bin/create_config.sh | 16 +++++++--------- bin/gen_self_tls.sh | 4 ++-- bin/print_share_link.sh | 10 +++++----- bin/run.sh | 8 ++++---- bin/update_obfs_password.sh | 4 ++-- bin/update_password.sh | 4 ++-- bin/update_port.sh | 6 +++--- .../template}/self_cert_config.json | 0 .../template}/tls_cert_config.json | 0 docker-compose.yml | 2 +- 11 files changed, 27 insertions(+), 29 deletions(-) rename {config_template => config/template}/self_cert_config.json (100%) rename {config_template => config/template}/tls_cert_config.json (100%) diff --git a/.gitignore b/.gitignore index d344ba6..58144c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -config.json +config/config.json diff --git a/bin/create_config.sh b/bin/create_config.sh index 436c7ee..e61d8a6 100644 --- a/bin/create_config.sh +++ b/bin/create_config.sh @@ -3,7 +3,7 @@ create_config_with_tls_cert() { local script_dir=$(cd "$(dirname "$0")"; pwd) - cp "$script_dir/../config_template/tls_cert_config.json" "$script_dir/../config.json" + cp "$script_dir/../config/template/tls_cert_config.json" "$script_dir/../config/config.json" # 设置端口 bash "$script_dir/update_port.sh" @@ -36,7 +36,7 @@ create_config_with_tls_cert() { done # 替换配置文件中的占位符 - local config_file="$script_dir/../config.json" + local config_file="$script_dir/../config/config.json" # 使用 sed 替换邮箱 sed -i "s/你的邮箱/$user_email/g" "$config_file" @@ -53,7 +53,7 @@ create_config_with_tls_cert() { create_self_tls_config() { local script_dir=$(cd "$(dirname "$0")"; pwd) - cp "$script_dir/../config_template/self_cert_config.json" "$script_dir/../config.json" + cp "$script_dir/../config/template/self_cert_config.json" "$script_dir/../config/config.json" # 设置端口 bash "$script_dir/update_port.sh" @@ -74,12 +74,12 @@ create_config(){ local script_dir=$(cd "$(dirname "$0")"; pwd) # 如果配置文件不存在, 创建空白配置文件 - if [ ! -e "$script_dir/../config.json" ]; then - touch "$script_dir/../config.json" + if [ ! -e "$script_dir/../config/config.json" ]; then + touch "$script_dir/../config/config.json" fi - local config_password=$(jq -r '.auth.password' "$script_dir/../config.json") - if [ -s "$script_dir/../config.json" ] && [ "$config_password" != "你的密码" ]; then + local config_password=$(jq -r '.auth.password' "$script_dir/../config/config.json") + if [ -s "$script_dir/../config/config.json" ] && [ "$config_password" != "你的密码" ]; then local regenerate read -p "检测到配置已存在,是否重新生成配置?(y/n): " regenerate if [ "$regenerate" != "y" ] && [ "$regenerate" != "Y" ]; then @@ -110,5 +110,3 @@ create_config(){ create_config - - diff --git a/bin/gen_self_tls.sh b/bin/gen_self_tls.sh index 4143607..5ae1075 100644 --- a/bin/gen_self_tls.sh +++ b/bin/gen_self_tls.sh @@ -5,7 +5,7 @@ gen_self_tls() { local domain="${1:-bing.com}" local script_dir="$(dirname "$(realpath "$0")")" local key_dir="$script_dir/../key" - local config_file="$script_dir/../config.json" + local config_file="$script_dir/../config/config.json" # 导入utils文件夹中的jq_util.sh脚本 source "$script_dir/utils/jq_util.sh" @@ -22,4 +22,4 @@ gen_self_tls() { } # 调用函数,传入第一个参数作为域名 -gen_self_tls "${1:-bing.com}" \ No newline at end of file +gen_self_tls "${1:-bing.com}" diff --git a/bin/print_share_link.sh b/bin/print_share_link.sh index 6e85f18..3052f0b 100644 --- a/bin/print_share_link.sh +++ b/bin/print_share_link.sh @@ -9,14 +9,14 @@ print_share_link() { check_jq # 检查配置文件是否存在 - if [ ! -f "$config_dir/config.json" ]; then + if [ ! -f "$config_dir/config/config.json" ]; then red "error: 配置文件未生成, 查看配置失败" echo '请选择"生成配置 / 重置配置"' exit 1 fi # 检查是否已启动过容器 - local password=$(jq -r '.auth.password' "$config_dir/config.json") + local password=$(jq -r '.auth.password' "$config_dir/config/config.json") if [ "$password" = "你的密码" ]; then red "error: 容器未启动过, 查看配置失败" echo '请选择"启动容器"' @@ -25,12 +25,12 @@ print_share_link() { # 检查是否使用ACME证书 local allowInsecure=1 # 默认跳过证书验证 - if jq -e '.acme' "$config_dir/config.json" > /dev/null 2>&1; then + if jq -e '.acme' "$config_dir/config/config.json" > /dev/null 2>&1; then allowInsecure=0 # 不跳过证书验证 fi - + # 读取配置文件内容 - local config=$(cat "$config_dir/config.json") + local config=$(cat "$config_dir/config/config.json") # 提取所需信息 password=$(echo "$config" | jq -r '.auth.password') diff --git a/bin/run.sh b/bin/run.sh index 98b9c92..6ddb420 100644 --- a/bin/run.sh +++ b/bin/run.sh @@ -14,11 +14,11 @@ run() { check_bash_installed # 如果配置没有创建 - if [ ! -e "$config_dir/config.json" ]; then - touch "$config_dir/config.json" + if [ ! -e "$config_dir/config/config.json" ]; then + touch "$config_dir/config/config.json" fi - local password=$(jq -r '.auth.password' "$config_dir/config.json") - if [ ! -s "$config_dir/config.json" ] || [ "$password" = "你的密码" ]; then + local password=$(jq -r '.auth.password' "$config_dir/config/config.json") + if [ ! -s "$config_dir/config/config.json" ] || [ "$password" = "你的密码" ]; then bash "$script_dir/create_config.sh" # 创建配置 fi diff --git a/bin/update_obfs_password.sh b/bin/update_obfs_password.sh index e68db3e..7872abb 100644 --- a/bin/update_obfs_password.sh +++ b/bin/update_obfs_password.sh @@ -3,7 +3,7 @@ # 更新密码的函数 update_obfs_password() { local script_dir="$(dirname "$(realpath "$0")")" - local config_file="$script_dir/../config.json" + local config_file="$script_dir/../config/config.json" # 加载工具脚本 source "$script_dir/utils/jq_util.sh" @@ -22,4 +22,4 @@ update_obfs_password() { } # 调用函数 -update_obfs_password \ No newline at end of file +update_obfs_password diff --git a/bin/update_password.sh b/bin/update_password.sh index 2d132f7..ef8996f 100644 --- a/bin/update_password.sh +++ b/bin/update_password.sh @@ -3,7 +3,7 @@ # 更新密码的函数 update_password() { local script_dir="$(dirname "$(realpath "$0")")" - local config_file="$script_dir/../config.json" + local config_file="$script_dir/../config/config.json" # 加载工具脚本 source "$script_dir/utils/jq_util.sh" @@ -22,4 +22,4 @@ update_password() { } # 调用函数 -update_password \ No newline at end of file +update_password diff --git a/bin/update_port.sh b/bin/update_port.sh index 279a655..f0726e4 100644 --- a/bin/update_port.sh +++ b/bin/update_port.sh @@ -48,10 +48,10 @@ change_port(){ local script_dir=$(cd "$(dirname "$0")"; pwd) local config_dir=$(readlink -f "$script_dir/../") source "$script_dir/utils/jq_util.sh" - + local port=$(find_free_port) - modify_json_file "$config_dir/config.json" ".listen" ":$port" + modify_json_file "$config_dir/config/config.json" ".listen" ":$port" echo "已分配新的空闲端口, 设置端口成功" } -change_port \ No newline at end of file +change_port diff --git a/config_template/self_cert_config.json b/config/template/self_cert_config.json similarity index 100% rename from config_template/self_cert_config.json rename to config/template/self_cert_config.json diff --git a/config_template/tls_cert_config.json b/config/template/tls_cert_config.json similarity index 100% rename from config_template/tls_cert_config.json rename to config/template/tls_cert_config.json diff --git a/docker-compose.yml b/docker-compose.yml index a1c484d..262f9d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: network_mode: "host" volumes: - acme:/acme - - ./config.json:/etc/hysteria/config.json + - ./config/config.json:/etc/hysteria/config.json - ./key/server.crt:/etc/hysteria/server.crt - ./key/server.key:/etc/hysteria/server.key command: ["server", "-c", "/etc/hysteria/config.json"]