diff --git a/scripts/guko-install.sh b/scripts/guko-install.sh new file mode 100755 index 0000000..be8461e --- /dev/null +++ b/scripts/guko-install.sh @@ -0,0 +1,133 @@ +#!/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 <&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