修改配置文件模板和配置文件位置

This commit is contained in:
Olia Lisa 2025-12-30 12:43:36 +08:00
parent a404a704da
commit 542c7e8994
11 changed files with 27 additions and 29 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
config.json config/config.json

View File

@ -3,7 +3,7 @@
create_config_with_tls_cert() { create_config_with_tls_cert() {
local script_dir=$(cd "$(dirname "$0")"; pwd) 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" bash "$script_dir/update_port.sh"
@ -36,7 +36,7 @@ create_config_with_tls_cert() {
done done
# 替换配置文件中的占位符 # 替换配置文件中的占位符
local config_file="$script_dir/../config.json" 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"
@ -53,7 +53,7 @@ create_config_with_tls_cert() {
create_self_tls_config() { create_self_tls_config() {
local script_dir=$(cd "$(dirname "$0")"; pwd) 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" bash "$script_dir/update_port.sh"
@ -74,12 +74,12 @@ create_config(){
local script_dir=$(cd "$(dirname "$0")"; pwd) local script_dir=$(cd "$(dirname "$0")"; pwd)
# 如果配置文件不存在, 创建空白配置文件 # 如果配置文件不存在, 创建空白配置文件
if [ ! -e "$script_dir/../config.json" ]; then if [ ! -e "$script_dir/../config/config.json" ]; then
touch "$script_dir/../config.json" touch "$script_dir/../config/config.json"
fi fi
local config_password=$(jq -r '.auth.password' "$script_dir/../config.json") local config_password=$(jq -r '.auth.password' "$script_dir/../config/config.json")
if [ -s "$script_dir/../config.json" ] && [ "$config_password" != "你的密码" ]; then if [ -s "$script_dir/../config/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
@ -110,5 +110,3 @@ create_config(){
create_config create_config

View File

@ -5,7 +5,7 @@ gen_self_tls() {
local domain="${1:-bing.com}" local domain="${1:-bing.com}"
local script_dir="$(dirname "$(realpath "$0")")" local script_dir="$(dirname "$(realpath "$0")")"
local key_dir="$script_dir/../key" 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脚本 # 导入utils文件夹中的jq_util.sh脚本
source "$script_dir/utils/jq_util.sh" source "$script_dir/utils/jq_util.sh"

View File

@ -9,14 +9,14 @@ print_share_link() {
check_jq check_jq
# 检查配置文件是否存在 # 检查配置文件是否存在
if [ ! -f "$config_dir/config.json" ]; then if [ ! -f "$config_dir/config/config.json" ]; then
red "error: 配置文件未生成, 查看配置失败" red "error: 配置文件未生成, 查看配置失败"
echo '请选择"生成配置 / 重置配置"' echo '请选择"生成配置 / 重置配置"'
exit 1 exit 1
fi 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 if [ "$password" = "你的密码" ]; then
red "error: 容器未启动过, 查看配置失败" red "error: 容器未启动过, 查看配置失败"
echo '请选择"启动容器"' echo '请选择"启动容器"'
@ -25,12 +25,12 @@ print_share_link() {
# 检查是否使用ACME证书 # 检查是否使用ACME证书
local allowInsecure=1 # 默认跳过证书验证 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 # 不跳过证书验证 allowInsecure=0 # 不跳过证书验证
fi fi
# 读取配置文件内容 # 读取配置文件内容
local config=$(cat "$config_dir/config.json") local config=$(cat "$config_dir/config/config.json")
# 提取所需信息 # 提取所需信息
password=$(echo "$config" | jq -r '.auth.password') password=$(echo "$config" | jq -r '.auth.password')

View File

@ -14,11 +14,11 @@ run() {
check_bash_installed check_bash_installed
# 如果配置没有创建 # 如果配置没有创建
if [ ! -e "$config_dir/config.json" ]; then if [ ! -e "$config_dir/config/config.json" ]; then
touch "$config_dir/config.json" touch "$config_dir/config/config.json"
fi fi
local password=$(jq -r '.auth.password' "$config_dir/config.json") local password=$(jq -r '.auth.password' "$config_dir/config/config.json")
if [ ! -s "$config_dir/config.json" ] || [ "$password" = "你的密码" ]; then if [ ! -s "$config_dir/config/config.json" ] || [ "$password" = "你的密码" ]; then
bash "$script_dir/create_config.sh" # 创建配置 bash "$script_dir/create_config.sh" # 创建配置
fi fi

View File

@ -3,7 +3,7 @@
# 更新密码的函数 # 更新密码的函数
update_obfs_password() { update_obfs_password() {
local script_dir="$(dirname "$(realpath "$0")")" 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" source "$script_dir/utils/jq_util.sh"

View File

@ -3,7 +3,7 @@
# 更新密码的函数 # 更新密码的函数
update_password() { update_password() {
local script_dir="$(dirname "$(realpath "$0")")" 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" source "$script_dir/utils/jq_util.sh"

View File

@ -50,7 +50,7 @@ change_port(){
source "$script_dir/utils/jq_util.sh" source "$script_dir/utils/jq_util.sh"
local port=$(find_free_port) 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 "已分配新的空闲端口, 设置端口成功" echo "已分配新的空闲端口, 设置端口成功"
} }

View File

@ -6,7 +6,7 @@ services:
network_mode: "host" network_mode: "host"
volumes: volumes:
- acme:/acme - acme:/acme
- ./config.json:/etc/hysteria/config.json - ./config/config.json:/etc/hysteria/config.json
- ./key/server.crt:/etc/hysteria/server.crt - ./key/server.crt:/etc/hysteria/server.crt
- ./key/server.key:/etc/hysteria/server.key - ./key/server.key:/etc/hysteria/server.key
command: ["server", "-c", "/etc/hysteria/config.json"] command: ["server", "-c", "/etc/hysteria/config.json"]