重构代码, 统一项目入口为install.sh.
This commit is contained in:
parent
d5833833e0
commit
3715554dc2
@ -1,10 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导入依赖脚本文件
|
||||
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
|
||||
create_config_with_tls_cert() {
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
@ -106,7 +101,3 @@ create_config(){
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
create_config
|
||||
|
||||
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导入依赖脚本文件
|
||||
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
|
||||
# 生成自签名证书
|
||||
gen_self_tls() {
|
||||
local domain="${1:-bing.com}"
|
||||
@ -27,5 +21,3 @@ gen_self_tls() {
|
||||
modify_json_file "$config_file" "inbounds[0].tls.server_name" "$domain"
|
||||
}
|
||||
|
||||
# 调用函数,传入第一个参数作为域名
|
||||
gen_self_tls "${1:-bing.com}"
|
||||
|
||||
@ -56,4 +56,3 @@ print_share_link() {
|
||||
echo -e "\033[0m"
|
||||
}
|
||||
|
||||
print_share_link # 输出分享链接
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
run() {
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
|
||||
@ -14,4 +13,3 @@ run() {
|
||||
docker-compose -f "$script_dir/../docker-compose.yml" up -d
|
||||
}
|
||||
|
||||
run # 启动容器
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
update_docker_images(){
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径
|
||||
local docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径
|
||||
|
||||
# 检查是否存在 docker-compose.yml 文件
|
||||
if [ ! -f $docker_compose_file ]; then
|
||||
@ -24,4 +24,3 @@ update_docker_images(){
|
||||
docker-compose -f $docker_compose_file up -d
|
||||
}
|
||||
|
||||
update_docker_images
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导入依赖脚本文件
|
||||
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
|
||||
# 修改域名
|
||||
update_domain(){
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
|
||||
@ -1,10 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导入依赖脚本文件
|
||||
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
# 更新密码的函数
|
||||
update_password() {
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
|
||||
@ -1,10 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导入依赖脚本文件
|
||||
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
# 查找随机空闲端口
|
||||
# 用途:
|
||||
# 在指定端口范围内,随机选择一个当前未被监听(TCP/UDP)的端口
|
||||
|
||||
@ -1,10 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导入依赖脚本文件
|
||||
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
update_uuid(){
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
local config_file="$script_dir/../config/config.json"
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
|
||||
# 修改json文件的属性值
|
||||
# 案例1:modify_json_file "/foo/bar.json" "person.name" "张三"
|
||||
# 案例2:modify_json_file "/foo/bar.json" "servers" '["a.com", "b.com"]'
|
||||
|
||||
35
install.sh
35
install.sh
@ -1,6 +1,13 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/bin/utils/base.sh"
|
||||
source "$(dirname "$0")/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(){
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
@ -12,17 +19,18 @@ install(){
|
||||
fi
|
||||
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
echo 安装jq...
|
||||
install_package jq
|
||||
fi
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo 安装docker...
|
||||
sleep 1
|
||||
curl -fsSL https://get.docker.com | bash -s docker
|
||||
fi
|
||||
|
||||
if ! command -v docker-compose >/dev/null 2>&1; then
|
||||
echo 安装docker-compose...
|
||||
sleep 1
|
||||
wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-linux-x86_64
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
fi
|
||||
@ -42,6 +50,7 @@ main(){
|
||||
echo "8. 更新镜像"
|
||||
|
||||
# 读取用户选择
|
||||
local choice
|
||||
read -p "输入您的选择: " choice
|
||||
|
||||
# 根据用户选择执行相应的操作
|
||||
@ -49,36 +58,36 @@ main(){
|
||||
1)
|
||||
# 一键部署
|
||||
install
|
||||
bash ./bin/create_config.sh
|
||||
bash ./bin/run.sh
|
||||
bash ./bin/print_share_link.sh
|
||||
create_config
|
||||
run
|
||||
printf_share_link
|
||||
;;
|
||||
2)
|
||||
# 生成配置 / 重置配置
|
||||
bash ./bin/create_config.sh
|
||||
create_config
|
||||
;;
|
||||
3)
|
||||
# 查看分享链接
|
||||
check_config_file
|
||||
bash ./bin/print_share_link.sh
|
||||
printf_share_link
|
||||
;;
|
||||
4)
|
||||
# 修改域名
|
||||
check_config_file
|
||||
bash ./bin/update_domain.sh
|
||||
update_domain
|
||||
restart_docker
|
||||
;;
|
||||
5)
|
||||
# 修改端口
|
||||
check_config_file
|
||||
bash ./bin/update_port.sh
|
||||
update_port
|
||||
restart_docker
|
||||
;;
|
||||
6)
|
||||
# 启动容器
|
||||
check_config_file
|
||||
bash ./bin/run.sh
|
||||
bash ./bin/print_share_link.sh
|
||||
run
|
||||
printf_share_link
|
||||
;;
|
||||
7)
|
||||
# 停止容器
|
||||
@ -86,7 +95,7 @@ main(){
|
||||
;;
|
||||
8)
|
||||
# 更新镜像
|
||||
bash ./bin/update_docker_images.sh
|
||||
update_docker_images
|
||||
restart_docker
|
||||
;;
|
||||
*)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user