需要测试相关功能
This commit is contained in:
@@ -14,14 +14,24 @@
|
||||
|
||||
set -e
|
||||
|
||||
# ---------- 颜色输出 ----------
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
MAGENTA='\033[0;35m'
|
||||
NC='\033[0m'
|
||||
# ---------- 颜色检测 ----------
|
||||
if [ -t 1 ]; then
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
MAGENTA='\033[0;35m'
|
||||
NC='\033[0m'
|
||||
else
|
||||
RED=''
|
||||
GREEN=''
|
||||
YELLOW=''
|
||||
BLUE=''
|
||||
CYAN=''
|
||||
MAGENTA=''
|
||||
NC=''
|
||||
fi
|
||||
|
||||
# ---------- 配置 ----------
|
||||
REPO_URL="https://git.whitetop.xyz/lxh2875931338/frpc-console.git"
|
||||
@@ -144,35 +154,30 @@ detect_arch() {
|
||||
|
||||
# ---------- 检测工具 ----------
|
||||
check_tools() {
|
||||
# git
|
||||
if command -v git &> /dev/null; then
|
||||
HAS_GIT=true
|
||||
else
|
||||
NEED_INSTALL_GIT=true
|
||||
fi
|
||||
|
||||
# curl
|
||||
if command -v curl &> /dev/null; then
|
||||
HAS_CURL=true
|
||||
else
|
||||
NEED_INSTALL_CURL=true
|
||||
fi
|
||||
|
||||
# wget
|
||||
if command -v wget &> /dev/null; then
|
||||
HAS_WGET=true
|
||||
else
|
||||
NEED_INSTALL_WGET=true
|
||||
fi
|
||||
|
||||
# Go
|
||||
if command -v go &> /dev/null; then
|
||||
HAS_GO=true
|
||||
else
|
||||
NEED_INSTALL_GO=true
|
||||
fi
|
||||
|
||||
# Docker
|
||||
if command -v docker &> /dev/null; then
|
||||
HAS_DOCKER=true
|
||||
fi
|
||||
@@ -188,30 +193,6 @@ check_container() {
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------- 获取系统包管理器 ----------
|
||||
get_package_manager() {
|
||||
case $OS in
|
||||
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll|opensuse-leap)
|
||||
echo "zypper"
|
||||
;;
|
||||
ubuntu|debian|linuxmint)
|
||||
echo "apt"
|
||||
;;
|
||||
centos|rhel|fedora|rocky|almalinux)
|
||||
echo "yum"
|
||||
;;
|
||||
alpine)
|
||||
echo "apk"
|
||||
;;
|
||||
arch|manjaro|endeavouros)
|
||||
echo "pacman"
|
||||
;;
|
||||
*)
|
||||
echo "unknown"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ---------- 检测结果汇总 ----------
|
||||
print_environment_summary() {
|
||||
print_title
|
||||
@@ -226,7 +207,7 @@ print_environment_summary() {
|
||||
if [ "$HAS_GIT" = true ]; then
|
||||
echo -e " git ✅ 已安装 ($(git --version | awk '{print $3}'))"
|
||||
else
|
||||
echo -e " git ❌ 未安装 (将自动安装)"
|
||||
echo " git ❌ 未安装 (将自动安装)"
|
||||
fi
|
||||
if [ "$HAS_CURL" = true ]; then
|
||||
echo " curl ✅ 已安装"
|
||||
@@ -262,15 +243,15 @@ print_environment_summary() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 容器状态
|
||||
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||
echo ""
|
||||
echo " ${CYAN}容器状态:${NC}"
|
||||
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||
echo -e " frpc-console ✅ 运行中"
|
||||
echo -e " frpc-console ✅ 运行中 (将停止并重建)"
|
||||
else
|
||||
echo -e " frpc-console ⏸️ 已存在但未运行"
|
||||
echo -e " frpc-console ⏸️ 已停止 (将重建)"
|
||||
fi
|
||||
echo -e " ${YELLOW}数据目录中的数据库文件将被保留${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -335,12 +316,17 @@ confirm_deploy() {
|
||||
echo -e "${GREEN}▶ 已启用 --yes,自动确认${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e -n "${CYAN}确认执行? 输入 Y 继续,输入 n 自定义配置 [Y/n]: ${NC}"
|
||||
# 强制从 /dev/tty 读取,而不是继承 stdin
|
||||
read -r CONFIRM </dev/tty
|
||||
|
||||
case $CONFIRM in
|
||||
n|N) return 1 ;;
|
||||
*) return 0 ;;
|
||||
n|N)
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -367,7 +353,7 @@ custom_config() {
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ---------- 实际执行部署 ----------
|
||||
# ---------- 执行部署 ----------
|
||||
do_deploy() {
|
||||
print_title
|
||||
print_subtitle "开始部署"
|
||||
@@ -383,7 +369,13 @@ do_deploy() {
|
||||
|
||||
case $OS in
|
||||
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll|opensuse-leap)
|
||||
zypper install -y $pkgs-core
|
||||
if [ "$NEED_INSTALL_GIT" = true ]; then
|
||||
zypper install -y git-core
|
||||
pkgs=$(echo "$pkgs" | sed -E 's/(^| )git( |$)/ /g' | sed 's/ */ /g' | sed 's/^ //;s/ $//')
|
||||
fi
|
||||
if [ -n "$pkgs" ]; then
|
||||
zypper install -y $pkgs
|
||||
fi
|
||||
;;
|
||||
ubuntu|debian|linuxmint)
|
||||
apt update -qq && apt install -y $pkgs
|
||||
@@ -454,7 +446,6 @@ do_deploy() {
|
||||
print_success "Go ${GO_VERSION} (${GO_ARCH}) 安装完成"
|
||||
fi
|
||||
|
||||
# 确保 go 在 PATH 中
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
|
||||
# ----- 拉取代码 -----
|
||||
@@ -496,11 +487,14 @@ do_deploy() {
|
||||
mkdir -p "$DEPLOY_DIR"
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
if [ ! -f "$DATA_DIR/frpc-console.db" ]; then
|
||||
touch "$DATA_DIR/frpc-console.db"
|
||||
print_info "新数据目录已创建"
|
||||
DB_FILE="$DATA_DIR/frpc-console.db"
|
||||
if [ "$CONTAINER_EXISTS" = true ] && [ -f "$DB_FILE" ] && [ -s "$DB_FILE" ]; then
|
||||
print_info "已有有效数据库文件,保留现有数据"
|
||||
elif [ -f "$DB_FILE" ] && [ -s "$DB_FILE" ]; then
|
||||
print_info "检测到有效数据库文件,保留现有数据"
|
||||
else
|
||||
print_info "已有数据目录,保留现有数据"
|
||||
touch "$DB_FILE"
|
||||
print_info "新数据目录已创建"
|
||||
fi
|
||||
|
||||
cp frpc-console "$DEPLOY_DIR/"
|
||||
@@ -574,32 +568,25 @@ do_deploy() {
|
||||
print_title
|
||||
}
|
||||
|
||||
# ---------- 主流程 ----------
|
||||
# ---------- 主流程 ----------
|
||||
main() {
|
||||
# 清屏,让输出从头开始
|
||||
clear 2>/dev/null || true
|
||||
|
||||
parse_args "$@"
|
||||
check_root
|
||||
|
||||
# ---- 环境检测 ----
|
||||
print_step "正在检测环境..."
|
||||
print_step "检测环境..."
|
||||
detect_os
|
||||
detect_arch
|
||||
check_tools
|
||||
check_container
|
||||
|
||||
# ---- 展示检测结果 ----
|
||||
print_environment_summary
|
||||
|
||||
# ---- 如果只检测 ----
|
||||
if [ "$CHECK_ONLY" = true ]; then
|
||||
print_info "环境检测完成(--check 模式,不执行部署)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ---- 如果 Docker 未安装 ----
|
||||
if [ "$HAS_DOCKER" = false ]; then
|
||||
print_error "Docker 未安装,请先安装 Docker"
|
||||
echo ""
|
||||
@@ -610,13 +597,10 @@ main() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ---- 生成部署计划 ----
|
||||
generate_plan
|
||||
|
||||
# ---- 展示部署计划 ----
|
||||
print_deployment_plan
|
||||
|
||||
# ---- 确认或自定义 ----
|
||||
if ! confirm_deploy; then
|
||||
custom_config
|
||||
print_deployment_plan
|
||||
@@ -626,15 +610,12 @@ main() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---- 如果只是演练 ----
|
||||
if [ "$DRY_RUN" = true ]; then
|
||||
print_info "演练模式(--dry-run),不实际执行部署"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ---- 执行部署 ----
|
||||
do_deploy
|
||||
}
|
||||
|
||||
# ---------- 入口 ----------
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user