Files
guko/scripts/guko-install.sh
2026-06-23 00:54:00 +00:00

134 lines
3.1 KiB
Bash
Executable File
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.

#!/usr/bin/env bash
set -euo pipefail
BASE_URL="${GUKO_BASE_URL:-https://mjjtop.com/admin/guko/raw/branch/main}"
INSTALL_DIR="${GUKO_INSTALL_DIR:-/opt/guko}"
COMPOSE_FILE="${INSTALL_DIR}/docker-compose.yml"
ENV_FILE="${INSTALL_DIR}/.env"
SERVERS_FILE="${INSTALL_DIR}/servers.json"
need_root() {
if [ "$(id -u)" -ne 0 ]; then
echo "请用 root 运行sudo bash <(curl -fsSL https://mjjtop.com/guko)" >&2
exit 1
fi
}
install_docker() {
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
return
fi
echo "==> 安装 Docker / Compose"
curl -fsSL https://get.docker.com | sh
systemctl enable --now docker >/dev/null 2>&1 || true
}
fetch() {
local url="$1" out="$2"
curl -fL --retry 3 --connect-timeout 10 "$url" -o "$out"
}
init_files() {
echo "==> 初始化 ${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}" "${INSTALL_DIR}/keys" "${INSTALL_DIR}/media" "${INSTALL_DIR}/results" "${INSTALL_DIR}/tmp"
chmod 700 "${INSTALL_DIR}/keys"
fetch "${BASE_URL}/docker-compose.example.yml" "${COMPOSE_FILE}"
if [ ! -f "${ENV_FILE}" ]; then
fetch "${BASE_URL}/.env.example" "${ENV_FILE}"
sed -i \
-e 's/^BOT_TOKEN=.*/BOT_TOKEN=replace-me/' \
-e 's/^ALLOWED_USERS=.*/ALLOWED_USERS=123456789/' \
-e 's/^ADMIN_USERS=.*/ADMIN_USERS=123456789/' \
"${ENV_FILE}"
fi
if [ ! -f "${SERVERS_FILE}" ]; then
fetch "${BASE_URL}/servers.example.json" "${SERVERS_FILE}"
fi
}
usage() {
cat <<USAGE
GUKO 一键部署脚本
用法:
bash <(curl -fsSL https://mjjtop.com/guko) install 安装/初始化
bash <(curl -fsSL https://mjjtop.com/guko) up 启动
bash <(curl -fsSL https://mjjtop.com/guko) down 停止
bash <(curl -fsSL https://mjjtop.com/guko) restart 重启
bash <(curl -fsSL https://mjjtop.com/guko) logs 看日志
bash <(curl -fsSL https://mjjtop.com/guko) status 状态
bash <(curl -fsSL https://mjjtop.com/guko) update 更新镜像并重启
安装目录:${INSTALL_DIR}
首次安装后必须编辑:${ENV_FILE}
BOT_TOKEN=你的 Telegram Bot Token
ALLOWED_USERS=你的 Telegram 数字 ID
ADMIN_USERS=你的 Telegram 数字 ID
USAGE
}
compose() {
cd "${INSTALL_DIR}"
docker compose -f "${COMPOSE_FILE}" "$@"
}
cmd="${1:-install}"
case "$cmd" in
install|init)
need_root
install_docker
init_files
cat <<MSG
✅ GUKO 已初始化到:${INSTALL_DIR}
下一步:
1. 编辑配置nano ${ENV_FILE}
2. 填好 BOT_TOKEN / ALLOWED_USERS / ADMIN_USERS
3. 启动bash <(curl -fsSL https://mjjtop.com/guko) up
4. Telegram 私聊 Bot 发送 /start再用 /addserver 添加服务器
MSG
;;
up|start)
need_root
[ -f "${COMPOSE_FILE}" ] || { echo "未安装,先执行 install" >&2; exit 1; }
compose pull
compose up -d
compose ps
;;
down|stop)
need_root
compose down
;;
restart)
need_root
compose restart
compose ps
;;
update)
need_root
compose pull
compose up -d
compose ps
;;
logs)
need_root
compose logs -f --tail=200
;;
status|ps)
need_root
compose ps
;;
help|-h|--help)
usage
;;
*)
usage
exit 2
;;
esac