重构代码, 统一项目入口为install.sh

This commit is contained in:
Olia Lisa 2026-01-15 13:21:40 +08:00
parent 8d96dab146
commit 771abcf074
10 changed files with 27 additions and 56 deletions

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
create_config_with_tls_cert() { create_config_with_tls_cert() {
@ -10,13 +9,13 @@ create_config_with_tls_cert() {
cp "$config_dir/template/tls_cert_config.json" "$config_file" cp "$config_dir/template/tls_cert_config.json" "$config_file"
# 设置端口 # 设置端口
bash "$script_dir/update_port.sh" change_port
# 设置密码 # 设置密码
bash "$script_dir/update_password.sh" update_password
# 设置混淆密码 # 设置混淆密码
bash "$script_dir/update_obfs_password.sh" update_obfs_password
# 获取邮箱 # 获取邮箱
read -p "请输入你的邮箱(可留空): " user_email read -p "请输入你的邮箱(可留空): " user_email
@ -57,16 +56,16 @@ create_self_tls_config() {
cp "$config_dir/template/self_cert_config.json" "$config_dir/config.json" cp "$config_dir/template/self_cert_config.json" "$config_dir/config.json"
# 设置端口 # 设置端口
bash "$script_dir/update_port.sh" change_port
# 设置密码 # 设置密码
bash "$script_dir/update_password.sh" update_password
# 设置混淆密码 # 设置混淆密码
bash "$script_dir/update_obfs_password.sh" update_obfs_password
# 生成自签名证书和设置域名 # 生成自签名证书和设置域名
bash "$script_dir/gen_self_tls.sh" "bing.com" gen_self_tls "bing.com"
green "创建配置成功" green "创建配置成功"
} }
@ -109,6 +108,3 @@ create_config(){
;; ;;
esac esac
} }
create_config

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/jq_util.sh"
# 生成自签名证书 # 生成自签名证书
@ -20,6 +19,3 @@ gen_self_tls() {
local config_file="$script_dir/../config/config.json" local config_file="$script_dir/../config/config.json"
modify_json_file "$config_file" "masquerade.proxy.url" "https://$domain" modify_json_file "$config_file" "masquerade.proxy.url" "https://$domain"
} }
# 调用函数,传入第一个参数作为域名
gen_self_tls "${1:-bing.com}"

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
print_share_link() { print_share_link() {
@ -55,5 +54,3 @@ print_share_link() {
echo "分享链接: $share_link" echo "分享链接: $share_link"
echo -e "\033[0m" echo -e "\033[0m"
} }
print_share_link # 输出分享链接

View File

@ -12,7 +12,5 @@ run() {
# 启动docker容器 # 启动docker容器
docker-compose -f "$compose_file" up -d docker-compose -f "$compose_file" up -d
}
run # 启动容器 }

View File

@ -23,6 +23,3 @@ update_docker_images() {
echo "正在启动容器.." echo "正在启动容器.."
docker-compose -f "$docker_compose_file" up -d docker-compose -f "$docker_compose_file" up -d
} }
# 调用函数
update_docker_images

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
source "$(dirname "$0")/utils/jq_util.sh"
# 修改域名 # 修改域名
@ -31,6 +29,3 @@ update_domain(){
echo "修改域名成功" echo "修改域名成功"
} }
update_domain

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
source "$(dirname "$0")/utils/jq_util.sh"
# 更新密码的函数 # 更新密码的函数
update_obfs_password() { update_obfs_password() {
@ -18,6 +16,3 @@ update_obfs_password() {
echo "更新混淆密码成功" echo "更新混淆密码成功"
} }
# 调用函数
update_obfs_password

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
source "$(dirname "$0")/utils/jq_util.sh"
# 更新密码的函数 # 更新密码的函数
update_password() { update_password() {
@ -18,6 +16,3 @@ update_password() {
echo "设置密码成功" echo "设置密码成功"
} }
# 调用函数
update_password

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/utils/base.sh"
source "$(dirname "$0")/utils/jq_util.sh"
# 查找随机空闲端口 # 查找随机空闲端口
# 用途: # 用途:
@ -84,5 +82,3 @@ change_port(){
modify_json_file "$config_file" ".listen" ":$port" modify_json_file "$config_file" ".listen" ":$port"
echo "已分配新的空闲端口, 设置端口成功" echo "已分配新的空闲端口, 设置端口成功"
} }
change_port

View File

@ -1,7 +1,13 @@
#!/bin/bash #!/bin/bash
source ./bin/utils/base.sh
source ./bin/utils/jq_util.sh
# 导入依赖脚本文件
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
for f in "$BASE_DIR"/bin/utils/*.sh; do
[ -f "$f" ] && source "$f"
done
for f in "$BASE_DIR"/bin/*.sh; do
[ -f "$f" ] && source "$f"
done
install(){ install(){
if ! command -v curl >/dev/null 2>&1; then if ! command -v curl >/dev/null 2>&1; then
@ -48,23 +54,23 @@ main(){
1) 1)
# 一键部署 # 一键部署
install install
bash ./bin/create_config.sh create_config
bash ./bin/run.sh run
bash ./bin/print_share_link.sh print_share_link
;; ;;
2) 2)
# 生成配置 # 生成配置
bash ./bin/create_config.sh create_config
;; ;;
3) 3)
# 查看分享链接 # 查看分享链接
check_config_file check_config_file
bash ./bin/print_share_link.sh print_share_link
;; ;;
4) 4)
# 启动容器 # 启动容器
bash ./bin/run.sh run
bash ./bin/print_share_link.sh print_share_link
;; ;;
5) 5)
# 停止容器 # 停止容器
@ -72,18 +78,18 @@ main(){
;; ;;
6) 6)
# 更新镜像 # 更新镜像
bash ./bin/update_docker_images.sh update_docker_images
;; ;;
7) 7)
# 修改域名 # 修改域名
check_config_file check_config_file
bash ./bin/update_domain.sh update_domain
restart_docker restart_docker
;; ;;
8) 8)
# 修改端口 # 修改端口
check_config_file check_config_file
bash ./bin/update_port.sh change_port
restart_docker restart_docker
;; ;;
*) *)