#!/bin/bash # gscript - File bootstrap cài đặt GScript sản xuất. # Tải gscript.tar.gz từ distribution URL, giải nén vào /opt/gscript, # chạy install.sh. # # Distribution URL có thể override qua env var: # GSCRIPT_URL=https://your-domain/install bash install # Default trỏ về Cloudflare Worker proxy GitLab repo. set -e GSCRIPT_URL="${GSCRIPT_URL:-https://gscript.glodival.com}" TARBALL_URL="${GSCRIPT_URL}/gscript.tar.gz" INSTALL_DIR="/opt/gscript" LOG_DIR="${INSTALL_DIR}/logs" LOG_FILE="${LOG_DIR}/install_bootstrap.log" mkdir -p "$LOG_DIR" exec > >(tee -a "$LOG_FILE") 2>&1 echo "=== GScript Bootstrap Installer ===" echo "Source: $TARBALL_URL" # Kiểm tra quyền root if [[ $EUID -ne 0 ]]; then echo "Vui lòng chạy script với quyền root." exit 1 fi # Cài curl/tar nếu thiếu (Ubuntu minimal đôi khi thiếu) if ! command -v curl >/dev/null 2>&1 || ! command -v tar >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1; then apt-get update -qq && apt-get install -y -qq curl tar ca-certificates elif command -v dnf >/dev/null 2>&1; then dnf install -y -q curl tar ca-certificates fi fi TMP_TAR=$(mktemp -t gscript.XXXXXX.tar.gz) trap "rm -f '$TMP_TAR'" EXIT echo "Đang tải gói GScript..." if ! curl -fsSL --max-time 120 -o "$TMP_TAR" "$TARBALL_URL"; then echo "Lỗi: Không tải được $TARBALL_URL." echo "Kiểm tra DNS, kết nối Internet, hoặc thử override:" echo " GSCRIPT_URL=https://alt.example.com bash install" exit 1 fi if [ ! -s "$TMP_TAR" ]; then echo "Lỗi: file tải về rỗng." exit 1 fi mkdir -p "$INSTALL_DIR" echo "Giải nén gói vào $INSTALL_DIR..." # GitLab archive endpoint trả về tarball với 1 folder bọc ngoài kiểu # `gscript-master-/...`. Dùng --strip-components=1 để bỏ folder đó. # Tarball tự build (không qua GitLab) thường extract trực tiếp → cần fallback. if ! tar -xzf "$TMP_TAR" -C "$INSTALL_DIR" --strip-components=1 2>/dev/null; then echo "Thử giải nén không strip-components (tarball tự build)..." tar -xzf "$TMP_TAR" -C "$INSTALL_DIR" || { echo "Lỗi: Giải nén thất bại." exit 1 } fi chmod +x "$INSTALL_DIR/install.sh" "$INSTALL_DIR/menu.sh" "$INSTALL_DIR"/modules/*.sh 2>/dev/null || true # Chạy file install.sh if [ -f "$INSTALL_DIR/install.sh" ]; then bash "$INSTALL_DIR/install.sh" else echo "Không tìm thấy $INSTALL_DIR/install.sh sau khi giải nén." exit 1 fi