#!/usr/bin/env bash # MeTube installation script with offline Deno installation # Place this script and deno-x86_64-unknown-linux-gnu.zip in the same directory set -e APP="MeTube" APP_DIR="/opt/metube" DENO_INSTALL_DIR="/usr/local" DENO_ZIP="deno-x86_64-unknown-linux-gnu.zip" GITHUB_REPO="alexta69/metube" SERVICE_USER="root" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' info() { echo -e "${GREEN}[INFO]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } step() { echo -e "${BLUE}[STEP]${NC} $1"; } # Check if running as root if [[ $EUID -ne 0 ]]; then error "This script must be run as root" fi # Check for local Deno archive SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DENO_ARCHIVE_PATH="${SCRIPT_DIR}/${DENO_ZIP}" if [[ ! -f "$DENO_ARCHIVE_PATH" ]]; then error "Deno archive not found at $DENO_ARCHIVE_PATH" fi info "Found Deno archive: $DENO_ARCHIVE_PATH" # Install dependencies step "Installing system dependencies" apt-get update apt-get install -y curl wget unzip git build-essential python3 python3-pip python3-venv step "Installing NODEJS" curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - apt install -y nodejs npm install -g pm2 # Install Deno from local archive step "Installing Deno from local archive" if [[ -d "${DENO_INSTALL_DIR}/deno" ]]; then rm -rf "${DENO_INSTALL_DIR}/deno" fi unzip -o "$DENO_ARCHIVE_PATH" -d /tmp/deno_extract chmod +x /tmp/deno_extract/deno mv /tmp/deno_extract/deno "${DENO_INSTALL_DIR}/bin/deno" rm -rf /tmp/deno_extract if command -v deno >/dev/null 2>&1; then info "Deno installed successfully: $(deno --version)" else error "Deno installation failed" fi # Install pnpm step "Installing pnpm" curl -fsSL https://get.pnpm.io/install.sh | sh - # Download and setup MeTube step "Downloading MeTube from GitHub" LATEST_URL=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep "tarball_url" | cut -d '"' -f 4) if [[ -z "$LATEST_URL" ]]; then error "Failed to get latest release URL" fi if [[ -d "$APP_DIR" ]]; then warn "Existing installation found, backing up..." mv "$APP_DIR" "${APP_DIR}_bak_$(date +%Y%m%d_%H%M%S)" fi mkdir -p "$APP_DIR" cd "$APP_DIR" curl -L "$LATEST_URL" -o metube.tar.gz tar -xzf metube.tar.gz --strip-components=1 rm metube.tar.gz # Build frontend step "Building frontend" if [[ -d "$APP_DIR/ui" ]]; then cd "$APP_DIR/ui" pnpm install --frozen-lockfile pnpm run build else error "UI directory not found" fi # Setup Python backend step "Setting up Python backend" cd "$APP_DIR" python3 -m venv .venv source .venv/bin/activate pip install --upgrade pip pip install yt-dlp aiohttp python-dotenv # Check for requirements.txt if [[ -f "$APP_DIR/requirements.txt" ]]; then pip install -r requirements.txt fi # Create .env file step "Creating configuration" if [[ ! -f "$APP_DIR/.env" ]]; then cat > "$APP_DIR/.env" < /etc/systemd/system/metube.service <