重构代码, 迁移导入依赖文件语句位置

This commit is contained in:
Olia Lisa 2026-01-14 23:11:26 +08:00
parent 1dffa963e2
commit 29365de75a
9 changed files with 15 additions and 17 deletions

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/bin/utils/base.sh"
create_config_with_tls_cert() { create_config_with_tls_cert() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
@ -64,7 +65,6 @@ create_self_tls_config() {
bash "$script_dir/gen_self_tls.sh" "bing.com" bash "$script_dir/gen_self_tls.sh" "bing.com"
green "成功创建配置" green "成功创建配置"
} }
create_config(){ create_config(){

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/bin/utils/jq_util.sh"
# 生成自签名证书 # 生成自签名证书
gen_self_tls() { gen_self_tls() {
@ -7,9 +8,6 @@ gen_self_tls() {
local key_dir="$script_dir/../tls/self-tls" local key_dir="$script_dir/../tls/self-tls"
local config_file="$script_dir/../config/config.json" local config_file="$script_dir/../config/config.json"
# 导入utils文件夹中的jq_util.sh脚本
source "$script_dir/utils/jq_util.sh"
# 创建存放证书的目录 # 创建存放证书的目录
mkdir -p "$key_dir" mkdir -p "$key_dir"

View File

@ -1,9 +1,10 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/bin/utils/base.sh"
print_share_link() { print_share_link() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir=$(readlink -f "$script_dir/../config") local config_dir=$(readlink -f "$script_dir/../config")
source "${script_dir}/utils/base.sh"
# 检查jq是否安装 # 检查jq是否安装
check_jq check_jq

View File

@ -1,10 +1,11 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
source "$(dirname "$0")/utils/jq_util.sh"
# 修改域名 # 修改域名
update_domain(){ update_domain(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
source "$script_dir/utils/jq_util.sh"
source "$script_dir/utils/base.sh"
local config_file="$script_dir/../config/config.json" local config_file="$script_dir/../config/config.json"
# 检查jq是否安装 # 检查jq是否安装
@ -36,5 +37,4 @@ update_domain(){
} }
update_domain update_domain

View File

@ -1,12 +1,11 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
# 更新密码的函数 # 更新密码的函数
update_password() { update_password() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_file="$script_dir/../config/config.json" local config_file="$script_dir/../config/config.json"
# 加载工具脚本
source "$script_dir/utils/base.sh"
# 生成一个长度为16的随机密码 # 生成一个长度为16的随机密码
local new_password=$(gen_password 16) local new_password=$(gen_password 16)

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/jq_util.sh"
# 查找随机空闲端口 # 查找随机空闲端口
@ -78,7 +79,6 @@ update_port(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir="$script_dir/../config" local config_dir="$script_dir/../config"
source "$script_dir/utils/jq_util.sh"
local port=$(find_free_port) local port=$(find_free_port)
modify_json_file "$config_dir/config.json" ".inbounds[0].listen_port" "$port" modify_json_file "$config_dir/config.json" ".inbounds[0].listen_port" "$port"

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/jq_util.sh"
update_uuid(){ update_uuid(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# 修改json文件的属性值 # 修改json文件的属性值
# 案例1modify_json_file "/foo/bar.json" "person.name" "张三" # 案例1modify_json_file "/foo/bar.json" "person.name" "张三"
# 案例2modify_json_file "/foo/bar.json" "servers" '["a.com", "b.com"]' # 案例2modify_json_file "/foo/bar.json" "servers" '["a.com", "b.com"]'

View File

@ -1,9 +1,8 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/bin/utils/base.sh"
source "$(dirname "$0")/bin/utils/jq_util.sh"
install(){ install(){
local script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录
source "${script_dir}/utils/base.sh"
if ! command -v curl >/dev/null 2>&1; then if ! command -v curl >/dev/null 2>&1; then
install_package curl install_package curl
fi fi
@ -31,9 +30,6 @@ install(){
main(){ main(){
local script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录
source "${script_dir}/utils/base.sh"
# 显示菜单 # 显示菜单
echo "请选择一个操作:" echo "请选择一个操作:"
echo "1. 一键部署" echo "1. 一键部署"