#!/usr/bin/env bash # MyPanel installer — https://mypanel.vn # Cách dùng: curl -fsSL https://get.mypanel.vn | bash # Tùy chọn: MYPANEL_VERSION=v0.1.0 MYPANEL_PORT=8888 curl -fsSL https://get.mypanel.vn | bash set -euo pipefail BASE_URL="${MYPANEL_BASE_URL:-https://get.mypanel.vn}" INSTALL_DIR="/usr/local/bin" DATA_DIR="/var/lib/mypanel" PORT="${MYPANEL_PORT:-8888}" err() { echo "LỖI: $*" >&2; exit 1; } [ "$(id -u)" -eq 0 ] || err "cần chạy với quyền root: curl -fsSL https://get.mypanel.vn | sudo bash" [ "$(uname -s)" = "Linux" ] || err "MyPanel chỉ hỗ trợ Linux (Ubuntu 22.04+/Debian 12+)" command -v curl >/dev/null 2>&1 || err "cần cài curl trước (apt install -y curl)" command -v sha256sum >/dev/null 2>&1 || err "thiếu lệnh sha256sum" command -v systemctl >/dev/null 2>&1 || err "hệ thống cần systemd" case "$(uname -m)" in x86_64|amd64) ARCH=amd64 ;; aarch64|arm64) ARCH=arm64 ;; *) err "kiến trúc CPU không hỗ trợ: $(uname -m)" ;; esac VERSION="${MYPANEL_VERSION:-$(curl -fsSL "$BASE_URL/latest.txt" | tr -d '[:space:]')}" [ -n "$VERSION" ] || err "không đọc được phiên bản mới nhất từ $BASE_URL/latest.txt" echo "==> Cài MyPanel $VERSION (linux/$ARCH)" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT BIN="mypanel-linux-$ARCH" echo "==> Tải $BASE_URL/releases/$VERSION/$BIN" curl -fSL --progress-bar "$BASE_URL/releases/$VERSION/$BIN" -o "$TMP/$BIN" curl -fsSL "$BASE_URL/releases/$VERSION/SHA256SUMS" -o "$TMP/SHA256SUMS" echo "==> Kiểm tra checksum SHA256" ( cd "$TMP" && grep " $BIN\$" SHA256SUMS | sha256sum -c - ) \ || err "checksum KHÔNG khớp — file tải về có thể đã bị can thiệp, dừng cài đặt" if systemctl is-active --quiet mypanel 2>/dev/null; then echo "==> Phát hiện MyPanel đang chạy — sẽ nâng cấp binary và khởi động lại" systemctl stop mypanel fi install -m 0755 "$TMP/$BIN" "$INSTALL_DIR/mypanel" mkdir -p "$DATA_DIR" cat > /etc/systemd/system/mypanel.service <}:$PORT" echo " (chứng chỉ tự ký — trình duyệt sẽ cảnh báo, chọn Advanced > Proceed)" echo " Tài khoản: admin" if [ -f "$DATA_DIR/admin-password.txt" ]; then echo " Mật khẩu: $(cat "$DATA_DIR/admin-password.txt")" fi echo "" echo " Lưu ý: mở port $PORT trên firewall / security group." echo " Quản lý service: systemctl status|restart|stop mypanel" echo "================================================="