Files
dock/ghproxy
2025-10-20 13:14:27 +08:00

48 lines
1.8 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
# 创建数据目录和脚本目录(添加容错判断,避免重复创建的冗余输出)
sudo mkdir -p /data || { echo "创建/data目录失败"; exit 1; }
sudo mkdir -p /boot/脚本 || { echo "创建/boot/脚本目录失败"; exit 1; }
# 定义文件路径并赋予变量更清晰的名称
yaml_file="/boot/脚本/ghproxy.yaml"
# 写入配置文件使用sudo确保权限添加备份机制
if [ -f "$yaml_file" ]; then
# 若文件已存在,先备份避免覆盖
sudo cp "$yaml_file" "${yaml_file}.bak-$(date +%Y%m%d%H%M%S)" || { echo "备份现有文件失败"; exit 1; }
fi
# 写入配置内容(缩进更规范,添加服务说明)
sudo tee "$yaml_file" > /dev/null <<EOF
# GHProxy 配置文件GitHub 代理服务)
# 版本v3.9
version: '3.9'
services:
ghproxy:
image: 'wjqserver/ghproxy:latest' # 代理服务镜像
restart: always # 容器退出后自动重启
volumes:
- './ghproxy/log:/data/ghproxy/log' # 日志目录挂载
- './ghproxy/config:/data/ghproxy/config' # 配置目录挂载
ports:
- '7210:8080' # 宿主机7210端口映射到容器8080端口
EOF
# 检查配置文件是否生成成功
if [ ! -f "$yaml_file" ]; then
echo -e "\033[31m 配置文件创建失败,请检查权限 \033[0m"
exit 1
fi
# 启动服务(添加启动状态检查)
echo "正在启动 ghproxy 服务..."
sudo docker compose -f "$yaml_file" up -d || {
echo -e "\033[31m 服务启动失败,请检查配置文件 \033[0m"
exit 1
}
# 输出成功信息(增加服务状态提示)
echo -e "\033[32m 服务启动成功GHProxy 监听端口7210 \033[0m"
echo -e "\033[34m 可通过 docker compose -f $yaml_file logs -f 查看实时日志 \033[0m"