脚本更新了,用我这个
命名为
autman.sh
在linux里面运行:
bash autman.sh
#!/bin/bash
# 设置颜色变量
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
# 下载文件函数,带镜像选择
download_with_mirror() {
local original_url=$1
local download_path=$2
local description=$3
local mirrors=("${GITHUB_MIRRORS[@]}") # 默认使用 GitHub 镜像
local download_url=""
local download_success=false
echo "尝试下载${description} (直链)..."
# 优先尝试直链下载
echo "尝试直接下载: $original_url (超时 10 秒, 无重试)"
if curl -f -L -o "$download_path" "$original_url" --connect-timeout 10 --retry 0; then
download_success=true
download_url="$original_url"
echo "${description}下载成功!"
return 0 # 直链下载成功,立即返回成功
else
echo "直链下载失败!"
return 1 # 直链下载失败,立即返回失败
fi
}
# 测试镜像响应速度并选择最快的镜像
select_fastest_mirror() {
local mirrors=("$@")
local fastest=""
local fastest_time=999
echo "测试镜像速度..."
for mirror in "${mirrors[@]}"; do
# 使用curl的静默模式测试响应时间
curl -s --connect-timeout 3 -o /dev/null -w "%{time_total}" "$mirror" > /tmp/mirror_speed 2>/dev/null
if [ $? -eq 0 ]; then
local time_total=$(cat /tmp/mirror_speed)
# 转换为毫秒以便于比较
local time_ms=$(echo "$time_total * 1000" | bc 2>/dev/null || echo "999")
echo "镜像 $mirror 响应时间: ${time_ms}ms"
# 更新最快镜像
if (( $(echo "$time_ms < $fastest_time" | bc -l) )); then
fastest_time=$time_ms
fastest=$mirror
fi
else
echo "镜像 $mirror 无响应"
fi
done
# 如果所有镜像都无响应,返回第一个
if [ -z "$fastest" ]; then
fastest="${mirrors[0]}"
echo "所有镜像测试失败,使用默认镜像: $fastest"
else
echo "选择最快的镜像: $fastest (${fastest_time}ms)"
fi
# 确保mirror字符串有效
fastest=$(echo "$fastest" | tr -d ' \n\r\t')
# 如果还是空,使用第一个镜像
if [ -z "$fastest" ]; then
fastest="${mirrors[0]}"
echo "镜像选择失败,使用第一个镜像: $fastest"
fi
echo "$fastest"
}
# GitHub镜像代理
GITHUB_MIRRORS=(
"https://github.tbedu.top"
"https://ghproxy.com"
"https://gh.api.99988866.xyz"
"https://gh.llkk.cc"
"https://g.ioiox.com"
)
# Docker镜像代理
DOCKER_MIRRORS=(
"docker.1ms.run"
"docker.registry.cyou"
"docker-cf.registry.cyou"
"docker.tbedu.top"
"dockerproxy.cn"
"docker.1panel.live"
"hub.rat.dev"
"docker.anyhub.us.kg"
"docker.chenby.cn"
"dockerhub.icu"
"docker.awsl9527.cn"
"dhub.kubesre.xyz"
"docker.hlyun.org"
"docker.m.daocloud.io"
)
# 获取当前IP地址
get_current_ip() {
# 尝试多种方法获取公网IP
local ip=""
# 优先尝试本地网卡获取IP(可能是内网IP)
ip=$(hostname -I | awk '{print $1}')
# 如果为空或以127开头,尝试获取公网IP
if [[ -z "$ip" || "$ip" == 127.* ]]; then
# 尝试通过公共API获取IP
ip=$(curl -s ifconfig.me || curl -s ipinfo.io/ip || curl -s icanhazip.com || curl -s ip.sb)
fi
# 如果所有方法都失败,使用localhost
if [ -z "$ip" ]; then
ip="127.0.0.1"
echo "警告: 无法获取服务器IP地址,将使用localhost" >&2
fi
echo "$ip"
}
# 显示欢迎信息
show_welcome() {
clear
echo "=================================================================="
echo -e "${RED} 感谢您使用AUTMAN一键脚本 ${NC}"
echo "=================================================================="
echo
echo -e "${RED}▶ 如果脚本有bug请加入QQ群:${NC}${GREEN}475866384${NC}"
echo -e "${RED}▶ autman官方QQ群:${NC}${GREEN}735467280${NC}"
echo -e "${RED}▶ 如果懒得手动或者不会可以联系:${NC}${BLUE}偷豆豆的大舅哥${NC}"
echo -e "${RED}▶ QQ:${NC}${GREEN}2182043734${NC}"
echo -e "${RED}▶ 本地服务器用户作者不推荐您关闭防火墙,为了您的安全放行对应端口即可${NC}"
echo -e "${RED}▶ 云服务器用户在安装完成后请手动去服务器提供商放行对应的端口${NC}"
echo "=================================================================="
}
# 检测系统架构和版本
check_system() {
echo "正在检测系统信息..."
# 检测系统架构
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCH_TYPE="amd64"
;;
aarch64)
ARCH_TYPE="arm64"
;;
*)
echo "不支持的系统架构: $ARCH"
exit 1
;;
esac
# 检测操作系统类型和版本
if [ -f /etc/os-release ]; then
source /etc/os-release
OS=$ID
VERSION_ID=$VERSION_ID
case $OS in
ubuntu)
OS_TYPE="Ubuntu"
;;
centos)
OS_TYPE="CentOS"
;;
debian)
OS_TYPE="Debian"
;;
*)
echo "不支持的操作系统: $OS"
exit 1
;;
esac
else
echo "无法确定操作系统类型"
exit 1
fi
echo "=================================================================="
echo "系统信息检测完成:"
echo "操作系统: $OS_TYPE $VERSION_ID"
echo "系统架构: $ARCH ($ARCH_TYPE)"
echo "=================================================================="
}
# 配置镜像源
configure_mirrors() {
echo "正在配置镜像源..."
case $OS in
ubuntu|debian)
# 备份原始源
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 替换为阿里云镜像源
if [ "$OS" = "ubuntu" ]; then
sed -i 's/http:\/\/\(archive\|security\).ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list
else
sed -i 's/http:\/\/\(deb\|security\).debian.org/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list
fi
# 更新软件包列表
apt update
;;
centos)
# 备份原始源
mkdir -p /etc/yum.repos.d/backup
cp /etc/yum.repos.d/CentOS-*.repo /etc/yum.repos.d/backup/
# 下载阿里云镜像源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 替换$releasever为具体版本号
sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
# 清理并重建缓存
yum clean all
yum makecache
;;
esac
echo "镜像源配置完成"
}
# 检测已安装的软件和环境
check_installed_dependencies() {
echo "检测系统已安装的软件和环境..."
local missing_packages=()
# 检测基础软件包
for pkg in git curl wget vim gcc make jq python3 pip3; do
if ! command -v $pkg &> /dev/null; then
missing_packages+=("$pkg")
echo "未安装: $pkg"
else
echo "已安装: $pkg ($(command -v $pkg))"
fi
done
# 检测Node.js版本
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v)
echo "已安装: Node.js $NODE_VERSION"
# 检查是否为所需版本 16.13.1
if [[ "$NODE_VERSION" != "v16.13.1" ]]; then
echo "Node.js版本不匹配 (需要: v16.13.1, 当前: $NODE_VERSION)"
NODEJS_NEEDS_INSTALL=true
else
NODEJS_NEEDS_INSTALL=false
fi
else
echo "未安装: Node.js"
NODEJS_NEEDS_INSTALL=true
fi
# 检测Go版本
if command -v go &> /dev/null; then
GO_VERSION=$(go version | cut -d' ' -f3 | sed 's/go//')
echo "已安装: Go $GO_VERSION"
# 检查是否为所需版本 1.22.0
if [[ "$GO_VERSION" != "1.22.0" ]]; then
echo "Go版本不匹配 (需要: 1.22.0, 当前: $GO_VERSION)"
GO_NEEDS_INSTALL=true
else
GO_NEEDS_INSTALL=false
fi
else
echo "未安装: Go"
GO_NEEDS_INSTALL=true
fi
# 检测Docker
if command -v docker &> /dev/null; then
DOCKER_VERSION=$(docker --version | cut -d' ' -f3 | sed 's/,//')
echo "已安装: Docker $DOCKER_VERSION"
DOCKER_NEEDS_INSTALL=false
else
echo "未安装: Docker"
DOCKER_NEEDS_INSTALL=true
fi
# 根据OS类型确定缺少的包名
case $OS in
ubuntu|debian)
MISSING_BASE_PACKAGES=()
for pkg in "${missing_packages[@]}"; do
case $pkg in
git|curl|wget|vim|jq)
MISSING_BASE_PACKAGES+=("$pkg")
;;
gcc)
MISSING_BASE_PACKAGES+=("gcc" "g++")
;;
make)
MISSING_BASE_PACKAGES+=("make")
;;
python3)
MISSING_BASE_PACKAGES+=("python3")
;;
pip3)
MISSING_BASE_PACKAGES+=("python3-pip")
;;
esac
done
;;
centos)
MISSING_BASE_PACKAGES=()
for pkg in "${missing_packages[@]}"; do
case $pkg in
git|curl|wget|vim|jq|make)
MISSING_BASE_PACKAGES+=("$pkg")
;;
gcc)
MISSING_BASE_PACKAGES+=("gcc" "gcc-c++")
;;
python3)
MISSING_BASE_PACKAGES+=("python3")
;;
pip3)
MISSING_BASE_PACKAGES+=("python3-pip")
;;
esac
done
if [ ${#MISSING_BASE_PACKAGES[@]} -gt 0 ]; then
MISSING_BASE_PACKAGES+=("epel-release")
fi
;;
esac
echo "检测完成!"
echo "=================================================================="
}
# 重新添加被删除的ask_install_path函数
ask_install_path() {
local default_path="/root/autman"
local install_path
read -p "是否安装到默认路径 ($default_path)?[Y/n]: " custom_path
if [[ "$custom_path" == "n" || "$custom_path" == "N" ]]; then
read -p "请输入安装路径: " install_path
install_path=${install_path:-$default_path}
else
install_path=$default_path
fi
# 确保目录存在
mkdir -p "$install_path"
# 设置全局变量
INSTALL_PATH="$install_path"
return 0
}
# 修改install_base_packages函数以确保安装pip
install_base_packages() {
echo "=================================================================="
echo "安装基础软件包..."
# 根据包管理器安装基础软件包
if [ -x "$(command -v apt-get)" ]; then
apt-get update -y
apt-get install -y \
curl wget git vim gcc g++ jq \
python3 python3-pip \
python3-dev \
libssl-dev \
libffi-dev \
python3-setuptools \
python3-wheel \
python3-cryptography \
python-pip-wheel \
python3-cffi \
python3-pyOpenSSL
# 创建pip的软链接
if [ ! -e /usr/bin/pip ]; then
ln -s /usr/bin/pip3 /usr/bin/pip
fi
elif [ -x "$(command -v yum)" ]; then
yum update -y
yum install -y \
epel-release \
curl wget git vim gcc gcc-c++ make jq \
python3 python3-pip \
python3-devel \
openssl-devel \
libffi-devel \
python3-setuptools \
python3-wheel \
python3-cryptography \
python-pip-wheel \
python3-cffi \
python3-pyOpenSSL
# 重新安装 Python 的 SSL 支持
yum reinstall -y python3-libs
# 创建pip的软链接
if [ ! -e /usr/bin/pip ]; then
ln -s /usr/bin/pip3 /usr/bin/pip
fi
# 修复 SSL 问题
if ! python3 -c "import ssl" 2>/dev/null; then
echo "尝试修复 Python SSL 问题..."
# 使用 easy_install 安装 pip(不依赖 SSL)
yum install -y python3-setuptools
if command -v easy_install-3 >/dev/null 2>&1; then
easy_install-3 pip
else
python3 -m easy_install pip
fi
# 安装 pyOpenSSL
pip3 install --index-url=http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com pyOpenSSL
fi
else
echo "不支持的系统,无法安装基础软件包"
return 1
fi
# 升级 pip 到最新版本
python3 -m pip install --index-url=http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com pip --upgrade
echo "基础软件包安装完成"
echo "=================================================================="
}
# 完全修复Node.js安装问题
install_nodejs() {
echo "=================================================================="
echo "开始安装Node.js v16.13.1..."
# 检测是否已安装 Node.js,如果已安装则跳过
if [ "$NODEJS_NEEDS_INSTALL" = false ]; then
echo "检测到已安装 Node.js,跳过安装"
echo "Node.js 安装路径: /usr/local/$NODE_VERSION_FULL" # 显示安装路径
echo "=================================================================="
return 0
fi
NODE_VERSION_FULL="node-v16.13.1-linux-x64"
NODE_VERSION="v16.13.1"
cd /tmp
# 下载 Node.js
echo "下载 Node.js v$NODE_VERSION..."
if ! download_with_mirror "https://nodejs.org/dist/$NODE_VERSION/$NODE_VERSION_FULL.tar.gz" "/tmp/$NODE_VERSION_FULL.tar.gz" "Node.js压缩包"; then
echo "Node.js 下载失败"
echo "下载的压缩包文件位于: /tmp/$NODE_VERSION_FULL.tar.gz" # 显示下载路径 (即使失败也显示)
return 1
fi
# 解压 Node.js
echo "解压 Node.js..."
tar -xzf "$NODE_VERSION_FULL.tar.gz"
# 移动到 /usr/local
echo "移动 Node.js 到 /usr/local..."
if [ -d "/usr/local/$NODE_VERSION_FULL" ]; then
rm -rf "/usr/local/$NODE_VERSION_FULL"
fi
mv "$NODE_VERSION_FULL" /usr/local/
echo "Node.js 安装路径: /usr/local/$NODE_VERSION_FULL" # 显示安装路径
# 配置环境变量
echo "配置 Node.js 环境变量..."
NODE_HOME="/usr/local/$NODE_VERSION_FULL"
# 检查 .profile 文件是否存在,如果不存在则创建
if [ ! -f ~/.profile ]; then
touch ~/.profile
fi
# 使用 sed 检查是否已存在 NODE_HOME 环境变量设置
if ! grep -q "export NODE_HOME=" ~/.profile; then
echo "export NODE_HOME=$NODE_HOME" >> ~/.profile
fi
# 使用 sed 检查是否已存在 NODE_PATH 环境变量设置
if ! grep -q "export NODE_PATH=" ~/.profile; then
echo "export NODE_PATH=$NODE_HOME/lib/node_modules" >> ~/.profile
fi
# 使用 sed 检查是否已存在 NODE 可执行文件路径添加到 PATH
if ! grep -q "export PATH=.*\$NODE_HOME/bin" ~/.profile; then
echo "export PATH=\$PATH:\$NODE_HOME/bin" >> ~/.profile
fi
# 使环境变量生效
source ~/.profile
# 检查 Node.js 和 npm 是否安装成功
if node -v && npm -v; then
echo -e "${GREEN}Node.js v$NODE_VERSION 安装成功!${NC}"
else
echo -e "${RED}Node.js v$NODE_VERSION 安装失败,请检查错误信息${NC}"
return 1
fi
# 删除压缩包文件
echo "删除 Node.js 压缩包文件..."
rm -f "/tmp/$NODE_VERSION_FULL.tar.gz"
echo "已删除压缩包文件: /tmp/$NODE_VERSION_FULL.tar.gz" # 提示已删除
echo "=================================================================="
}
# 设置Node.js环境变量并验证 - 增加Ubuntu/Debian兼容性
setup_nodejs_environment() {
echo "配置Node.js环境变量..."
# 注意:使用与install_nodejs中相同的架构名称
local arch_name="x64"
if [ "$ARCH_TYPE" = "arm64" ]; then
arch_name="arm64"
fi
# 根据系统类型选择不同的环境变量配置方式
case $OS in
ubuntu|debian)
# Ubuntu/Debian方式
# 检查是否已配置
if ! grep -q "NODE_HOME=/usr/local/node-v16.13.1-linux-${arch_name}" /etc/environment; then
# 修改/etc/environment文件
echo "NODE_HOME=/usr/local/node-v16.13.1-linux-${arch_name}" >> /etc/environment
echo "PATH=\$PATH:\$NODE_HOME/bin" >> /etc/environment
echo "NODE_PATH=\$NODE_HOME/lib/node_modules" >> /etc/environment
fi
# 创建profile.d脚本
cat > /etc/profile.d/nodejs.sh << EOF
export NODE_HOME=/usr/local/node-v16.13.1-linux-${arch_name}
export PATH=\$PATH:\$NODE_HOME/bin
export NODE_PATH=\$NODE_HOME/lib/node_modules
EOF
chmod +x /etc/profile.d/nodejs.sh
;;
centos|rhel)
# CentOS/RHEL方式
if ! grep -q "NODE_HOME=/usr/local/node-v16.13.1-linux-${arch_name}" /etc/profile; then
echo "" >> /etc/profile
echo "# Node.js环境变量" >> /etc/profile
echo "export NODE_HOME=/usr/local/node-v16.13.1-linux-${arch_name}" >> /etc/profile
echo "export PATH=\$PATH:\$NODE_HOME/bin" >> /etc/profile
echo "export NODE_PATH=\$NODE_HOME/lib/node_modules" >> /etc/profile
fi
;;
esac
# 设置当前会话的环境变量(通用方式)
export NODE_HOME=/usr/local/node-v16.13.1-linux-${arch_name}
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
# 刷新环境变量 - 兼容不同系统
echo "刷新系统环境变量..."
case $OS in
ubuntu|debian)
if [ -f /etc/profile.d/nodejs.sh ]; then
source /etc/profile.d/nodejs.sh
fi
;;
centos|rhel)
source /etc/profile
;;
esac
# 验证Node.js环境变量是否正确设置
echo "验证Node.js环境变量..."
# 尝试多次确认node命令可用
local max_attempts=3
local attempt=1
while [ $attempt -le $max_attempts ]; do
if command -v node &>/dev/null; then
echo "Node.js命令可用,环境变量已生效"
break
else
echo "尝试 $attempt/$max_attempts: Node.js命令尚未可用,等待环境变量生效..."
# 再次导出环境变量并刷新
export PATH=$PATH:$NODE_HOME/bin
sleep 2
fi
attempt=$((attempt+1))
done
# 详细输出环境信息
echo "Node.js版本: $(node -v 2>/dev/null || echo '未找到Node.js命令')"
echo "NPM版本: $(npm -v 2>/dev/null || echo '未找到NPM命令')"
# 返回结果
if command -v node &>/dev/null; then
echo "Node.js环境变量配置成功"
return 0
else
echo "警告: Node.js环境变量可能未正确配置,可能影响后续步骤"
echo "建议: 安装完成后,请手动运行 'source /etc/profile' 并重新开始安装"
sleep 3
return 1
fi
}
# 设置Go环境变量并验证 - 增加Ubuntu/Debian兼容性
setup_go_environment() {
echo "配置Go环境变量..."
# 创建GOPATH目录
mkdir -p /usr/local/go/path
# 根据系统类型选择不同的环境变量配置方式
case $OS in
ubuntu|debian)
# Ubuntu/Debian方式
# 检查是否已配置
if ! grep -q "GOROOT=/usr/local/go" /etc/environment; then
# 修改/etc/environment文件
echo "GO111MODULE=on" >> /etc/environment
echo "GOPROXY=https://goproxy.cn" >> /etc/environment
echo "GOROOT=/usr/local/go" >> /etc/environment
echo "GOPATH=/usr/local/go/path" >> /etc/environment
echo "PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin" >> /etc/environment
fi
# 创建profile.d脚本
cat > /etc/profile.d/golang.sh << EOF
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
export GOROOT=/usr/local/go
export GOPATH=/usr/local/go/path
export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
EOF
chmod +x /etc/profile.d/golang.sh
;;
centos|rhel)
# CentOS/RHEL方式 - 保持原有实现
if ! grep -q "GOROOT=/usr/local/go" /etc/profile; then
echo "" >> /etc/profile
echo "# Go环境变量" >> /etc/profile
echo "export GO111MODULE=on" >> /etc/profile
echo "export GOPROXY=https://goproxy.cn" >> /etc/profile
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export GOPATH=/usr/local/go/path" >> /etc/profile
echo "export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin" >> /etc/profile
fi
;;
esac
# 设置当前会话的环境变量(通用方式)
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
export GOROOT=/usr/local/go
export GOPATH=/usr/local/go/path
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
# 刷新环境变量 - 兼容不同系统
echo "刷新系统环境变量..."
case $OS in
ubuntu|debian)
if [ -f /etc/profile.d/golang.sh ]; then
source /etc/profile.d/golang.sh
fi
;;
centos|rhel)
source /etc/profile
;;
esac
# 加入多次环境检查,确保变量已经生效
echo "验证Go环境变量是否正确设置..."
# 尝试多次确认Go命令可用
local max_attempts=3
local attempt=1
while [ $attempt -le $max_attempts ]; do
if command -v go &>/dev/null; then
echo "Go命令可用,环境变量已生效"
break
else
echo "尝试 $attempt/$max_attempts: Go命令尚未可用,等待环境变量生效..."
# 再次导出环境变量并刷新
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
sleep 2
fi
attempt=$((attempt+1))
done
# 详细输出环境信息
echo "Go版本: $(go version 2>/dev/null || echo '未找到Go命令')"
echo "Go环境: $(go env GOROOT 2>/dev/null || echo 'GOROOT未设置')"
echo "Go路径: $(go env GOPATH 2>/dev/null || echo 'GOPATH未设置')"
# 返回结果
if command -v go &>/dev/null; then
echo "Go环境变量配置成功"
return 0
else
echo "警告: Go环境变量可能未正确配置,可能影响后续步骤"
echo "建议: 安装完成后,请手动运行 'source /etc/profile' 并重新开始安装"
sleep 3 # 给用户时间阅读警告
return 1
fi
}
# 安装Go
install_golang() {
echo "=================================================================="
echo "开始安装Go 1.22.0..."
# 下载Go
GO_URL="https://dl.google.com/go/go1.22.0.linux-${ARCH_TYPE}.tar.gz"
GO_TARBALL="/tmp/go1.22.0.linux-${ARCH_TYPE}.tar.gz"
echo "下载Go安装包..."
curl -L -o "$GO_TARBALL" "$GO_URL"
if [ $? -ne 0 ]; then
echo "Go下载失败,尝试使用镜像..."
for mirror in "${GITHUB_MIRRORS[@]}"; do
echo "尝试从 $mirror 下载Go..."
if curl -L -o "$GO_TARBALL" "$mirror/https://dl.google.com/go/go1.22.0.linux-${ARCH_TYPE}.tar.gz"; then
echo "Go下载成功"
break
fi
done
fi
# 安装Go
echo "安装Go..."
rm -rf /usr/local/go
tar -C /usr/local -xzf "$GO_TARBALL"
# 设置环境变量
setup_go_environment
# 验证安装
if go version | grep -q "go1.22.0"; then
echo "Go 1.22.0 安装成功!"
return 0
else
echo "Go 安装失败,请手动安装"
return 1
fi
}
# 恢复 download_autman 函数,包含下载方式选择菜单
download_autman() {
local install_path=$1
echo "=================================================================="
echo "开始下载autman..."
# 确保安装目录存在
mkdir -p "$install_path"
# 设置默认版本号
local DEFAULT_VERSION="3.5.1"
local VERSION="$DEFAULT_VERSION"
# 询问用户是否使用默认版本
read -p "是否使用默认版本 ($DEFAULT_VERSION)?[Y/n]: " use_default_version
if [[ "$use_default_version" == "n" || "$use_default_version" == "N" ]]; then
read -p "请输入要安装的版本号: " custom_version
if [ -n "$custom_version" ]; then
VERSION="$custom_version"
fi
fi
echo "将安装 autman 版本: $VERSION"
# 设置文件名和下载路径
local FILENAME="autMan_${ARCH_TYPE}.tar.gz"
local DOWNLOAD_PATH="${install_path}/${FILENAME}"
echo "安装目录: $install_path"
echo "下载文件: $DOWNLOAD_PATH"
# 直接使用GitHub URL
local GITHUB_URL="https://github.com/hdbjlizhe/fanli/releases/download/${VERSION}/${FILENAME}"
# 显示下载选项菜单
echo "请选择下载方式:"
echo "1. 直连下载"
echo "2. 通过内置代理下载"
echo "3. 手动输入代理链接下载"
echo "4. 手动上传autman压缩包文件"
echo "=================================================================="
read -p "请选择 [1/2/3/4] 或 'q' 退出: " download_option
while true; do
local download_success=false
case "$download_option" in
"1")
echo "选择直连下载..."
if download_with_mirror "$GITHUB_URL" "$DOWNLOAD_PATH" "autman程序 (直连)"; then
echo "autman程序下载成功 (直连)"
download_success=true
else
echo "直连下载失败,请重新选择下载方式或手动上传/退出"
fi
;;
"2")
echo "选择通过内置代理下载..."
local download_success_mirror=false
# 循环尝试镜像下载
for mirror in "${GITHUB_MIRRORS[@]}"; do
local mirror_url=$(echo "$GITHUB_URL" | sed "s#^https://github.com#$mirror#")
echo "尝试从镜像下载: $mirror_url (镜像源: $mirror)"
if download_with_mirror "$mirror_url" "$DOWNLOAD_PATH" "autman程序 (镜像)"; then
echo "autman程序下载成功 (镜像源: $mirror)"
download_success_mirror=true
download_success=true
break # 镜像下载成功,跳出循环
else
echo "镜像源 $mirror 下载失败,尝试下一个镜像源..."
fi
done
if [ "$download_success_mirror" = false ]; then
echo "所有镜像源下载尝试失败,请检查网络或手动下载"
echo "请重新选择下载方式或选择手动上传/退出"
fi
;;
"3")
echo "选择手动输入代理链接下载..."
read -p "请输入GitHub镜像代理链接: " manual_proxy_url
if [ -n "$manual_proxy_url" ]; then
echo "尝试从手动代理链接下载: $manual_proxy_url"
# 确保代理链接以 / 结尾
if [[ ! "$manual_proxy_url" =~ /$ ]]; then
manual_proxy_url="${manual_proxy_url}/"
fi
# 直接将代理链接添加到原始 GitHub URL 前面
local manual_mirror_url="${manual_proxy_url}${GITHUB_URL}"
if download_with_mirror "$manual_mirror_url" "$DOWNLOAD_PATH" "autman程序 (手动代理)"; then
echo "autman程序下载成功 (手动代理链接)"
download_success=true
else
echo "从手动链接下载失败,请检查链接或手动上传文件"
echo "请重新选择下载方式或选择手动上传/退出"
fi
else
echo "您没有输入任何代理链接。"
echo "将返回下载选项菜单,请选择其他下载方式或手动上传文件。"
echo "请重新选择下载方式或选择手动上传/退出"
fi
;;
"4")
echo "选择手动上传autman压缩包文件..."
install_autman_from_archive "$install_path"
return $? # 返回手动上传的结果
download_success=true # 手动上传也视为下载成功
;;
"q")
echo "用户取消安装"
return 1 # 用户选择退出,函数返回
;;
*)
echo "无效的选择,请重新运行脚本"
echo "请重新选择下载方式或选择手动上传/退出"
;;
esac
if [ "$download_success" = true ]; then
# 解压autman (如果下载成功)
echo "解压autman..."
cd "$install_path"
# 先清理可能存在的旧文件
rm -rf autman autMan AutoMan AUTMAN 2>/dev/null
# 解压文件
tar -xzf "$FILENAME"
if [ $? -ne 0 ]; then
echo "autman解压失败! 请检查下载的文件是否完整或磁盘空间"
return 1
fi
# 检查是否存在 autMan 程序
if [ ! -f "autMan" ]; then
echo "错误:解压后未找到 autMan 程序文件"
return 1
fi
echo "autman下载和解压完成!"
return 0 # 下载和解压成功,函数返回
fi
read -p "请选择下载方式 [1/2/3/4] 或 'q' 退出 (或按 Enter 重新显示选项): " download_option_loop
if [ -z "$download_option_loop" ]; then download_option="$download_option"; continue; fi
download_option="$download_option_loop"
done
}
# 修改download_ip2region函数,确保直接下载到安装目录
download_ip2region() {
local install_path=$1
echo "下载IP2Region数据库文件..."
# 设置下载URL
local IP2REGION_URL="https://github.com/lionsoul2014/ip2region/raw/master/data/ip2region.xdb"
local IP2REGION_PATH="${install_path}/ip2region.xdb"
# 尝试下载
for mirror in "${GITHUB_MIRRORS[@]}"; do
echo "尝试从 $mirror 下载ip2region.xdb..."
if curl -L -o "$IP2REGION_PATH" "${mirror}/${IP2REGION_URL}"; then
echo "ip2region.xdb下载成功"
return 0
fi
done
echo "ip2region.xdb下载失败,请手动下载并放置到 $IP2REGION_PATH"
return 1
}
# 修复Go依赖安装函数,确保显示正确的GOPATH
install_go_dependencies() {
local install_path=$1
echo "=================================================================="
echo "开始安装Go依赖..."
# 尝试查找plugin/scripts目录,不限制深度
local scripts_dir=$(find "$install_path" -type d -name "scripts" | grep "plugin/scripts" | head -1)
if [ -n "$scripts_dir" ]; then
echo "找到插件目录: $scripts_dir"
cd "$scripts_dir"
# 初始化Go模块
echo "初始化Go模块..."
if [ ! -f "go.mod" ]; then
go mod init autman/plugins
fi
# 安装Go依赖
echo "安装hdbjlizhe/middleware..."
go get -u github.com/hdbjlizhe/middleware
# 返回原目录
cd - >/dev/null
echo "Go依赖安装完成"
# 获取正确的GOPATH
local actual_gopath=$(go env GOPATH)
if [ -n "$actual_gopath" ]; then
echo "依赖已保存到: ${actual_gopath}/pkg/mod"
else
echo "无法确定Go依赖保存位置,请检查go env GOPATH的输出"
fi
return 0
else
echo "错误: 找不到plugin/scripts目录"
echo "请确认autman安装是否完整,目录结构如下:"
find "$install_path" -type d | sort
return 1
fi
}
# 修改主安装函数,确保正确安装顺序
install_autman() {
echo "=================================================================="
echo "开始安装autman..."
# 询问安装路径
ask_install_path
# 下载并解压autman
if ! download_autman "$INSTALL_PATH"; then
echo "autman下载或解压失败!"
return 1
fi
echo "autman基础安装完成"
echo "=================================================================="
return 0
}
# 安装Python依赖
install_python_deps() {
echo "安装Python依赖..."
# 使用 HTTP 而不是 HTTPS,并信任主机
pip3 install --index-url=http://mirrors.aliyun.com/pypi/simple/ \
--trusted-host=mirrors.aliyun.com \
requests \
user_agent \
PyExecJS \
aiohttp \
pyOpenSSL
echo "Python依赖安装完成"
}
# 安装Node.js依赖
install_nodejs_deps() {
echo "安装Node.js依赖..."
# 设置npm使用淘宝镜像
npm config set registry https://registry.npmmirror.com
# 安装依赖
npm install --timeout=60000 --retry=3 axios request require crypto-js
if [ $? -ne 0 ]; then
echo "Node.js依赖安装失败"
return 1
fi
echo "Node.js依赖安装完成"
}
# 安装Go依赖
install_golang_deps() {
local install_path=$1
echo "安装Go依赖..."
# 进入plugin/scripts目录
if [ -d "${install_path}/autman/plugin/scripts" ]; then
cd "${install_path}/autman/plugin/scripts"
# 安装Go依赖
echo "安装hdbjlizhe/middleware..."
go get -u github.com/hdbjlizhe/middleware
cd - >/dev/null
echo "Go依赖安装完成"
else
echo "警告: 找不到plugin/scripts目录,跳过Go依赖安装"
fi
}
# 修复依赖安装顺序问题 - 将Go依赖安装从install_dependencies中分离出来
install_dependencies() {
local install_path=$1
echo "=================================================================="
echo "开始安装依赖..."
# 安装Python依赖
echo "安装Python依赖..."
pip install -U requests user_agent PyExecJS aiohttp
# 安装Node.js依赖
echo "安装Node.js依赖..."
npm install -g axios request require crypto-js
echo "基础依赖安装完成"
echo "=================================================================="
}
# 检测GLIBC版本
check_glibc_version() {
echo "检测系统GLIBC版本..."
# 获取GLIBC版本
GLIBC_VERSION=$(ldd --version | head -n 1 | grep -oE '[0-9]+\.[0-9]+$')
GLIBC_VERSION_MAJOR=$(echo $GLIBC_VERSION | cut -d. -f1)
GLIBC_VERSION_MINOR=$(echo $GLIBC_VERSION | cut -d. -f2)
echo "系统GLIBC版本: $GLIBC_VERSION"
# 检查GLIBC版本是否满足要求
if [ "$GLIBC_VERSION_MAJOR" -lt 2 ] || [ "$GLIBC_VERSION_MAJOR" -eq 2 -a "$GLIBC_VERSION_MINOR" -lt 17 ]; then
echo "警告: 系统GLIBC版本过低,autman可能无法正常运行"
echo "建议通过Docker安装autman"
return 1
fi
return 0
}
# 配置autman
configure_autman() {
local install_path=$1
echo "配置autman在 $install_path..."
# 创建配置文件
local config_file="${install_path}/sets.conf"
echo "创建配置文件..."
touch "$config_file"
# 询问用户是否设置管理员账号
read -p "是否需要设置管理员账号?[Y/n]: " set_admin
if [[ "$set_admin" != "n" && "$set_admin" != "N" ]]; then
read -p "请输入管理员账号 (默认: admin): " admin_username
admin_username=${admin_username:-"admin"}
echo "set autMan adminUsername $admin_username" >> "$config_file"
echo "管理员账号设置为: $admin_username"
fi
# 询问用户是否设置管理员密码
read -p "是否需要设置管理员密码?[Y/n]: " set_password
if [[ "$set_password" != "n" && "$set_password" != "N" ]]; then
read -p "请输入管理员密码 (默认: 123456): " admin_password
admin_password=${admin_password:-"123456"}
echo "set autMan adminPassword $admin_password" >> "$config_file"
echo "管理员密码设置为: $admin_password"
fi
# 询问用户设置端口
read -p "是否需要设置端口?[Y/n]: " set_port
if [[ "$set_port" != "n" && "$set_port" != "N" ]]; then
read -p "请输入端口号 (默认: 9090): " port
port=${port:-9090}
echo "set autMan port $port" >> "$config_file"
echo "端口设置为: $port"
# 保存端口到变量以便后续使用
configured_port=$port
else
configured_port=9090
fi
# 询问用户是否注册云账号
read -p "是否需要注册云账号?[Y/n]: " set_cloud
if [[ "$set_cloud" != "n" && "$set_cloud" != "N" ]]; then
read -p "请输入云账号: " cloud_username
if [ -n "$cloud_username" ]; then
echo "set cloud username $cloud_username" >> "$config_file"
echo "云密码已设置"
read -p "请输入云密码: " cloud_password
if [ -n "$cloud_password" ]; then
echo "set cloud password $cloud_password" >> "$config_file"
echo "云密码已设置"
fi
fi
fi
echo "配置完成"
return 0
}
# 检查Docker是否安装
check_docker() {
if [ "$DOCKER_NEEDS_INSTALL" = false ]; then
echo "Docker已安装"
return 0
else
echo "Docker未安装,开始安装..."
return 1
fi
}
# 安装Docker
install_docker() {
echo "开始安装Docker..."
case $OS in
ubuntu|debian)
# 安装依赖
apt update
apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
# 添加Docker官方GPG密钥
curl -fsSL https://download.docker.com/linux/$OS/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 添加Docker源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/$OS $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
# 安装Docker
apt update
apt install -y docker-ce docker-ce-cli containerd.io
;;
centos)
# 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加Docker源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 安装Docker
yum install -y docker-ce docker-ce-cli containerd.io
;;
esac
# 启动Docker
systemctl start docker
systemctl enable docker
echo "Docker安装完成"
return 0
}
# 尝试使用Docker镜像代理拉取镜像
try_docker_pull_with_mirrors() {
local image_name=$1
local mirrors=("${DOCKER_MIRRORS[@]}") # 使用 Docker 镜像代理列表
local pull_success=false
local last_error=""
echo "尝试使用Docker镜像代理拉取镜像: $image_name"
# 直接尝试拉取
echo "尝试直接拉取镜像 $image_name..."
if docker pull "$image_name"; then
echo "镜像拉取成功!"
return 0
else
echo "直接拉取失败,将尝试使用代理..."
fi
# 使用预设的Docker镜像代理
for mirror in "${mirrors[@]}"; do
echo "=================================================================="
echo "尝试使用代理 $mirror 拉取镜像..."
local proxy_image="${mirror}/${image_name}"
# 显示Docker原生输出
if docker pull "$proxy_image"; then
echo "镜像拉取成功!"
echo "重新标记镜像..."
docker tag "$proxy_image" "$image_name"
docker rmi "$proxy_image"
return 0
fi
echo "当前代理拉取失败,尝试下一个代理..."
done
return 1
}
# 手动镜像拉取函数
try_manual_mirror() {
echo "所有预设镜像代理均失败"
echo "可用的Docker镜像代理有:"
for i in "${!DOCKER_MIRRORS[@]}"; do
echo "$((i+1)). ${DOCKER_MIRRORS[$i]}"
done
read -p "请选择一个镜像代理编号,或输入'c'自定义代理,或输入'q'退出: " choice
if [[ "$choice" == "q" ]]; then
echo "用户取消安装"
return 1
elif [[ "$choice" == "c" ]]; then
read -p "请输入自定义Docker镜像代理地址 (如 docker.io): " custom_mirror
echo "尝试使用代理 $custom_mirror 拉取镜像..."
if docker pull "${custom_mirror}/hdbjlizhe/autman:latest"; then
echo "镜像拉取成功!"
docker tag "${custom_mirror}/hdbjlizhe/autman:latest" "hdbjlizhe/autman:latest"
docker rmi "${custom_mirror}/hdbjlizhe/autman:latest"
return 0
else
echo "自定义代理拉取失败"
return 1
fi
elif [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#DOCKER_MIRRORS[@]} ]; then
local mirror_index=$((choice-1))
local mirror="${DOCKER_MIRRORS[$mirror_index]}"
echo "尝试使用代理 $mirror 拉取镜像..."
if docker pull "${mirror}/hdbjlizhe/autman:latest"; then
echo "镜像拉取成功!"
docker tag "${mirror}/hdbjlizhe/autman:latest" "hdbjlizhe/autman:latest"
docker rmi "${mirror}/hdbjlizhe/autman:latest"
return 0
else
echo "选择的代理拉取失败"
return 1
fi
else
echo "无效的选择"
return 1
fi
}
# 重启Docker容器的函数
restart_docker_container() {
local container_name="$1"
echo "重启 $container_name 容器..."
# 重启容器
docker restart "$container_name"
if [ $? -eq 0 ]; then
echo "$container_name 容器重启成功"
return 0
else
echo "警告: $container_name 容器重启失败"
return 1
fi
}
# 修改 `install_autman_docker` 函数,在宿主机安装 Go 依赖
install_autman_docker() {
echo "=================================================================="
echo "开始使用Docker安装autman..."
echo "请选择Docker镜像拉取方式:"
echo "1. 直接拉取 (默认 - 适合网络环境较好)"
echo "2. 使用Docker镜像代理拉取 (推荐 - 解决网络问题)"
echo "3. 手动上传Docker镜像压缩包 (离线安装或网络极差)"
echo "=================================================================="
read -p "请选择 [1/2/3]: " docker_pull_method
local docker_pull_option=$docker_pull_method
# 确认用户是否想指定数据目录路径
read -p "是否使用默认数据目录 (/root/autman)?[Y/n]: " use_default_path
local docker_data_path="/root/autman"
if [[ "$use_default_path" == "n" || "$use_default_path" == "N" ]]; then
read -p "请输入数据目录路径: " custom_path
if [ -n "$custom_path" ]; then
docker_data_path="$custom_path"
fi
fi
# 确保目录存在
mkdir -p "$docker_data_path"
INSTALL_PATH="$docker_data_path" # 设置全局变量以便其他函数使用
echo "将使用目录 $docker_data_path 存储autman数据"
# 拉取Docker镜像
echo "拉取autman Docker镜像..."
# 定义 Docker 镜像名称
local DOCKER_IMAGE="hdbjlizhe/autman:latest"
local pull_success=false
case $docker_pull_option in
"2")
echo "使用Docker镜像代理拉取..."
# 遍历所有 Docker 镜像代理
for mirror in "${DOCKER_MIRRORS[@]}"; do
echo "尝试使用代理: $mirror"
if docker pull ${mirror}/hdbjlizhe/autman:latest; then
# 代理拉取成功后,重新标记镜像
docker tag ${mirror}/hdbjlizhe/autman:latest hdbjlizhe/autman:latest
docker rmi ${mirror}/hdbjlizhe/autman:latest
pull_success=true
break
else
echo "使用 $mirror 拉取失败,尝试下一个代理..."
fi
done
if [ "$pull_success" = false ]; then
echo "所有代理拉取都失败,请检查网络或尝试其他安装方式"
return 1
fi
;;
"3")
echo "请将Docker镜像压缩包上传到服务器,并输入文件路径"
read -p "输入文件路径: " image_path
if [ -f "$image_path" ]; then
docker load -i "$image_path"
else
echo "文件不存在: $image_path"
return 1
fi
;;
*)
echo "直接拉取Docker镜像..."
docker pull hdbjlizhe/autman:latest
;;
esac
if [ $? -ne 0 ]; then
echo "Docker 镜像拉取失败,安装终止"
return 1
fi
echo "容器下载完成"
# 停止可能存在的旧容器
docker stop autman 2>/dev/null
docker rm autman 2>/dev/null
echo "容器已停止,开始配置autman"
# 清空数据目录中的旧文件
echo "清理数据目录中的旧文件..."
rm -rf "${docker_data_path:?}"/* 2>/dev/null
# 下载autman压缩文件
echo "下载autman压缩文件..."
download_autman "$docker_data_path"
# 配置autman
echo "配置autman..."
configure_autman "$docker_data_path"
# 启动Docker容器
echo "启动autman容器..."
docker run -d --name autman --restart always --network=host -e autPort=${configured_port:-9090} -v "$docker_data_path:/autMan" hdbjlizhe/autman:latest
# 检查容器是否启动成功
if [ $? -ne 0 ]; then
echo "autman Docker容器启动失败,请检查日志"
docker logs autman
return 1
fi
echo "autman容器已启动"
# 在容器内安装Go依赖 - 【错误,应该在宿主机安装】
# 等待容器初始化
echo "等待容器初始化..."
sleep 5
# 重启容器以确保配置生效
echo "重启autman容器以应用配置..."
restart_docker_container "autman"
if [ $? -eq 0 ]; then
echo "=================================================================="
echo "autman Docker容器启动成功!"
# 获取当前IP地址
current_ip=$(get_current_ip)
echo "您可以通过访问 http://${current_ip}:${configured_port:-9090} 使用autman"
echo "=================================================================="
# 在显示完安装结果后,添加网络修复步骤
echo "=================================================================="
echo "注意:部分用户可能会出现容器无法正常访问的情况,脚本将进行简单修复..."
echo "正在重新配置容器网络模式..."
docker stop autman
docker rm autman
docker run -d --name autman --restart always --network=host -e autPort=${configured_port:-9090} -v "$docker_data_path:/autMan" hdbjlizhe/autman:latest
echo "=================================================================="
echo "如果您觉得当前的容器网络结构对您来说并不安全,您可执行以下命令来替换掉当前的容器模式:"
echo
echo "docker stop autman"
echo "docker rm autman"
echo "docker run -d --name autman --restart always -p 9090:8080 -v /root/autman:/autMan --log-opt max-size=10m --log-opt max-file=3 hdbjlizhe/autman:latest"
echo "=================================================================="
return 0
else
echo "autman Docker容器启动失败,请检查日志"
docker logs autman
return 1
fi
}
# 手动安装Docker镜像
install_docker_from_archive() {
echo "=================================================================="
echo "开始手动安装Docker镜像..."
read -p "请输入Docker镜像压缩包文件路径: " archive_path
if [ ! -f "$archive_path" ]; then
echo "错误: 文件 '$archive_path' 不存在"
return 1
fi
echo "加载Docker镜像..."
docker load -i "$archive_path"
if [ $? -ne 0 ]; then
echo "Docker 镜像加载失败,请检查文件是否有效或Docker环境"
return 1
fi
echo "Docker 镜像加载完成"
echo "=================================================================="
return 0
}
# 修复GLIBC版本检测后的Docker切换逻辑,但保留用户选择
setup_and_start_autman() {
local install_path=$1
echo "=================================================================="
echo "准备启动autman服务..."
# 搜索可执行文件,优先查找autman,然后是autMan
echo "查找autman可执行文件..."
local autman_exec=""
for exec_name in "autman" "autMan" "AutoMan" "AUTMAN"; do
local found_exec=$(find "$install_path" -type f -name "$exec_name" 2>/dev/null | head -1)
if [ -n "$found_exec" ]; then
autman_exec="$found_exec"
echo "找到可执行文件: $autman_exec"
break
fi
done
# 如果仍找不到,尝试查找其他可能的可执行文件
if [ -z "$autman_exec" ]; then
autman_exec=$(find "$install_path" -type f -executable -not -path "*/\.*" -not -name "*.sh" 2>/dev/null | head -1)
if [ -n "$autman_exec" ]; then
echo "未找到明确的autman可执行文件,尝试使用: $autman_exec"
else
echo "错误: 找不到可执行文件,安装可能不完整"
echo "建议切换到Docker安装方式"
read -p "是否切换到Docker安装? [Y/n]: " switch_docker
if [[ "$switch_docker" != "n" && "$switch_docker" != "N" ]]; then
USE_DOCKER=true
install_autman_docker
show_installation_result
exit 0
else
echo "用户选择不切换到Docker,退出安装"
return 1
fi
fi
fi
# 确保有执行权限
chmod +x "$autman_exec"
# 检查GLIBC兼容性,使用超时避免卡死
echo "检查系统兼容性..."
local error_output=$(timeout 5 "$autman_exec" --version 2>&1 || echo "执行超时或错误")
# 检查输出是否包含GLIBC错误
if [[ "$error_output" == *"GLIBC"* ]]; then
echo "=================================================================="
echo "错误: 检测到GLIBC版本不兼容"
echo "错误信息: $error_output"
echo "=================================================================="
echo "您的系统GLIBC版本过低,无法直接运行autman"
echo "建议使用Docker安装方式"
echo "=================================================================="
read -p "是否切换到Docker安装? [Y/n]: " switch_to_docker
if [[ "$switch_to_docker" != "n" && "$switch_to_docker" != "N" ]]; then
echo "正在切换到Docker安装..."
USE_DOCKER=true
install_autman_docker
show_installation_result
exit 0 # 在Docker安装完成后直接退出
fi
echo "警告: 继续使用本地安装可能导致服务无法正常运行"
fi
# 配置autman
configure_autman "$install_path"
# 创建启动脚本
local start_script="${install_path}/start_autman.sh"
echo "#!/bin/bash" > "$start_script"
echo "cd \"$(dirname "$autman_exec")\"" >> "$start_script"
echo "nohup \"$autman_exec\" > \"${install_path}/autman.log\" 2>&1 &" >> "$start_script"
chmod +x "$start_script"
# 启动服务
echo "启动autman服务..."
bash "$start_script"
# 检查进程是否启动
sleep 3
local pid=$(pgrep -f "$(basename "$autman_exec")")
if [ -n "$pid" ]; then
echo "服务进程已启动,进程ID: $pid"
echo "服务日志保存在: ${install_path}/autman.log"
# 获取当前IP地址
local ip=$(hostname -I | awk '{print $1}')
echo "=================================================================="
echo "autman已启动,请访问 http://${ip}:${configured_port:-9090}"
echo "=================================================================="
return 0
else
echo "警告: 服务可能未正常启动,检查日志..."
if [ -f "${install_path}/autman.log" ]; then
echo "---------------日志内容---------------"
tail -n 10 "${install_path}/autman.log"
echo "-------------------------------------"
# 再次检查日志中是否有GLIBC错误
if grep -q "GLIBC" "${install_path}/autman.log"; then
echo "=================================================================="
echo "检测到GLIBC版本问题,强烈建议使用Docker安装"
echo "=================================================================="
read -p "是否现在切换到Docker安装? [Y/n]: " switch_now
if [[ "$switch_now" != "n" && "$switch_now" != "N" ]]; then
USE_DOCKER=true
install_autman_docker
return $?
fi
fi
fi
echo "您可以手动启动: cd ${install_path} && ./$(basename "$autman_exec")"
return 1
fi
}
# 显示安装结果
show_installation_result() {
local ip=$(get_current_ip)
local port=${configured_port:-9090}
echo "=================================================================="
echo -e "${GREEN}安装完成!${NC}"
echo -e "${GREEN}感谢您使用AUTMAN一键脚本${NC}"
echo -e "${RED}如果脚本有bug请加入QQ群:${NC}${GREEN}475866384${NC}"
echo -e "${RED}autman官方QQ群:${NC}${GREEN}735467280${NC}"
echo -e "${RED}如果懒得手动或者不会可以联系:${NC}${BLUE}偷豆豆的大舅哥${NC}"
echo -e "${RED}QQ:${NC}${GREEN}2182043734${NC}"
echo -e "${RED}▶ 本地服务器用户作者不推荐您关闭防火墙,为了您的安全放行对应端口即可${NC}"
echo -e "${RED}▶ 云服务器用户在安装完成后请手动去服务器提供商放行对应的端口${NC}"
echo "=================================================================="
}
# 询问安装方式
ask_installation_method() {
echo "=================================================================="
echo "请选择安装方式:"
echo "1. 本地安装 (直接安装在系统中)"
echo "2. Docker安装 (使用Docker容器运行-大舅哥推荐)"
echo "=================================================================="
read -p "请输入选择 [1/2]: " install_method
case $install_method in
2)
USE_DOCKER=true
echo "已选择Docker安装方式"
;;
*)
USE_DOCKER=false
echo "已选择本地安装方式"
;;
esac
}
# 执行函数
show_welcome
check_system
ask_installation_method
configure_mirrors
check_installed_dependencies
if [ "$USE_DOCKER" = true ]; then
# Docker安装流程
if ! check_docker; then
install_docker
fi
install_autman_docker
else
# 本地安装流程
install_base_packages
install_nodejs
# 安装Go
if [ "$GO_NEEDS_INSTALL" = true ]; then
install_golang
else
echo "Go已安装,跳过"
fi
# 安装基础依赖(Python和Node.js)
install_dependencies
# 安装autman
install_autman
# 安装Go依赖(在autman安装完成后)
install_go_dependencies "$INSTALL_PATH"
# 配置和启动
setup_and_start_autman "$INSTALL_PATH"
fi
show_installation_result