Files
hubproxy/install.sh
2026-01-24 23:33:43 +08:00

111 lines
2.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# HubProxy 一键安装脚本 (Gitea 私人仓库版)
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# 配置信息
VERSION="v1.2.1"
SERVICE_NAME="hubproxy"
# 按照你的习惯,安装在 /opt如果你想完全放在 /vol1 下也可以修改此处
INSTALL_DIR="/opt/hubproxy"
BINARY_NAME="hubproxy"
TEMP_DIR="/tmp/hubproxy-install"
echo -e "${BLUE}HubProxy 一键安装脚本 - 来自 Gitea 私人仓库${NC}"
echo "================================================="
# 1. 权限检查
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}此脚本需要 root 权限运行${NC}"
exit 1
fi
# 2. 检测系统架构并匹配你的 Gitea 链接
arch=$(uname -m)
case $arch in
x86_64)
ARCH="amd64"
DOWNLOAD_URL="https://git.vps3344521.xyz/3344/hubproxy/releases/download/v1.2.1/hubproxy-v1.2.1-linux-amd64.tar.gz"
;;
aarch64|arm64)
ARCH="arm64"
DOWNLOAD_URL="https://git.vps3344521.xyz/3344/hubproxy/releases/download/v1.2.1/hubproxy-v1.2.1-linux-arm64.tar.gz"
;;
*)
echo -e "${RED}不支持的架构: $arch${NC}"
exit 1
;;
esac
echo -e "${BLUE}检测到架构: ${ARCH}${NC}"
echo -e "${BLUE}准备从 Gitea 下载...${NC}"
# 3. 安装必要工具
for cmd in curl tar; do
if ! command -v $cmd &> /dev/null; then
echo -e "${YELLOW}正在安装依赖 $cmd...${NC}"
apt update && apt install -y $cmd
fi
done
# 4. 执行下载
rm -rf "${TEMP_DIR}" && mkdir -p "${TEMP_DIR}"
cd "${TEMP_DIR}"
echo -e "${YELLOW}正在下载: ${DOWNLOAD_URL}${NC}"
curl -L -o "hubproxy.tar.gz" "${DOWNLOAD_URL}"
# 5. 解压 (根据你提供的包结构,通常解压后是一个目录或直接是二进制文件)
tar -xzf "hubproxy.tar.gz"
# 进入解压出的目录(如果压缩包里有 hubproxy 文件夹的话)
[ -d "hubproxy" ] && cd hubproxy
# 6. 配置服务环境
echo -e "${BLUE}配置安装目录: ${INSTALL_DIR}${NC}"
mkdir -p "${INSTALL_DIR}"
cp "${BINARY_NAME}" "${INSTALL_DIR}/"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
# 如果有默认配置文件也一并复制
if [ -f "config.toml" ]; then
if [ ! -f "${INSTALL_DIR}/config.toml" ]; then
cp "config.toml" "${INSTALL_DIR}/"
fi
fi
# 7. 写入 Systemd 服务
echo -e "${BLUE}正在创建 Systemd 服务...${NC}"
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
[Unit]
Description=HubProxy Service
After=network.target
[Service]
Type=simple
WorkingDirectory=${INSTALL_DIR}
ExecStart=${INSTALL_DIR}/${BINARY_NAME}
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# 8. 启动服务
systemctl daemon-reload
systemctl enable ${SERVICE_NAME}
systemctl restart ${SERVICE_NAME}
# 9. 清理并完成
rm -rf "${TEMP_DIR}"
echo "-------------------------------------------------"
echo -e "${GREEN}HubProxy 安装成功!${NC}"
echo -e "安装路径: ${INSTALL_DIR}"
echo -e "服务状态: ${BLUE}systemctl status ${SERVICE_NAME}${NC}"