Son aktivite 20 hours ago

Revizyon 8a76e9d5e1cc92f85aa54b318b2894c2bc34e53d

metube.sh Ham
1#!/usr/bin/env bash
2
3# MeTube installation script with offline Deno installation
4# Place this script and deno-x86_64-unknown-linux-gnu.zip in the same directory
5
6set -e
7
8APP="MeTube"
9APP_DIR="/opt/metube"
10DENO_INSTALL_DIR="/usr/local"
11DENO_ZIP="deno-x86_64-unknown-linux-gnu.zip"
12GITHUB_REPO="alexta69/metube"
13SERVICE_USER="root"
14
15# Colors for output
16RED='\033[0;31m'
17GREEN='\033[0;32m'
18YELLOW='\033[1;33m'
19BLUE='\033[0;34m'
20NC='\033[0m'
21
22info() { echo -e "${GREEN}[INFO]${NC} $1"; }
23warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
24error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
25step() { echo -e "${BLUE}[STEP]${NC} $1"; }
26
27# Check if running as root
28if [[ $EUID -ne 0 ]]; then
29 error "This script must be run as root"
30fi
31
32# Check for local Deno archive
33SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34DENO_ARCHIVE_PATH="${SCRIPT_DIR}/${DENO_ZIP}"
35
36if [[ ! -f "$DENO_ARCHIVE_PATH" ]]; then
37 error "Deno archive not found at $DENO_ARCHIVE_PATH"
38fi
39
40info "Found Deno archive: $DENO_ARCHIVE_PATH"
41
42# Install dependencies
43step "Installing system dependencies"
44apt-get update
45apt-get install -y curl wget unzip git build-essential python3 python3-pip python3-venv
46
47step "Installing NODEJS"
48curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
49apt install -y nodejs
50npm install -g pm2
51
52# Install Deno from local archive
53step "Installing Deno from local archive"
54if [[ -d "${DENO_INSTALL_DIR}/deno" ]]; then
55 rm -rf "${DENO_INSTALL_DIR}/deno"
56fi
57
58unzip -o "$DENO_ARCHIVE_PATH" -d /tmp/deno_extract
59chmod +x /tmp/deno_extract/deno
60mv /tmp/deno_extract/deno "${DENO_INSTALL_DIR}/bin/deno"
61rm -rf /tmp/deno_extract
62
63if command -v deno >/dev/null 2>&1; then
64 info "Deno installed successfully: $(deno --version)"
65else
66 error "Deno installation failed"
67fi
68
69# Install pnpm
70step "Installing pnpm"
71curl -fsSL https://get.pnpm.io/install.sh | sh -
72
73# Download and setup MeTube
74step "Downloading MeTube from GitHub"
75LATEST_URL=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep "tarball_url" | cut -d '"' -f 4)
76
77if [[ -z "$LATEST_URL" ]]; then
78 error "Failed to get latest release URL"
79fi
80
81if [[ -d "$APP_DIR" ]]; then
82 warn "Existing installation found, backing up..."
83 mv "$APP_DIR" "${APP_DIR}_bak_$(date +%Y%m%d_%H%M%S)"
84fi
85
86mkdir -p "$APP_DIR"
87cd "$APP_DIR"
88
89curl -L "$LATEST_URL" -o metube.tar.gz
90tar -xzf metube.tar.gz --strip-components=1
91rm metube.tar.gz
92
93# Build frontend
94step "Building frontend"
95if [[ -d "$APP_DIR/ui" ]]; then
96 cd "$APP_DIR/ui"
97 pnpm install --frozen-lockfile
98 pnpm run build
99else
100 error "UI directory not found"
101fi
102
103# Setup Python backend
104step "Setting up Python backend"
105cd "$APP_DIR"
106python3 -m venv .venv
107source .venv/bin/activate
108pip install --upgrade pip
109pip install yt-dlp aiohttp python-dotenv
110
111# Check for requirements.txt
112if [[ -f "$APP_DIR/requirements.txt" ]]; then
113 pip install -r requirements.txt
114fi
115
116# Create .env file
117step "Creating configuration"
118if [[ ! -f "$APP_DIR/.env" ]]; then
119 cat > "$APP_DIR/.env" <<EOF
120# MeTube Configuration
121DOWNLOAD_DIR=/downloads
122STATE_DIR=/opt/metube/state
123URL_PREFIX=
124HTTP_USERNAME=
125HTTP_PASSWORD=
126YTDL_OPTIONS=
127EOF
128fi
129
130# Create download and state directories
131mkdir -p /downloads
132mkdir -p "$APP_DIR/state"
133
134# Create systemd service
135step "Creating systemd service"
136cat > /etc/systemd/system/metube.service <<EOF
137[Unit]
138Description=MeTube - YouTube Downloader
139After=network.target
140
141[Service]
142Type=simple
143WorkingDirectory=${APP_DIR}
144EnvironmentFile=${APP_DIR}/.env
145ExecStart=${APP_DIR}/.venv/bin/python3 ${APP_DIR}/app/main.py
146Restart=always
147User=root
148StandardOutput=journal
149StandardError=journal
150
151[Install]
152WantedBy=multi-user.target
153EOF
154
155# Reload systemd and start service
156step "Starting MeTube service"
157systemctl daemon-reload
158systemctl enable metube
159systemctl start metube
160
161# Check if service is running
162sleep 3
163if systemctl is-active --quiet metube; then
164 info "MeTube service started successfully"
165else
166 error "MeTube service failed to start. Check logs with: journalctl -u metube"
167fi
168
169# Get IP address
170IP_ADDRESS=$(hostname -I | awk '{print $1}')
171
172echo ""
173echo -e "${GREEN}========================================${NC}"
174echo -e "${GREEN}MeTube installation completed!${NC}"
175echo -e "${GREEN}========================================${NC}"
176echo -e "Access MeTube at: ${YELLOW}http://${IP_ADDRESS}:8081${NC}"
177echo ""
178echo -e "Commands:"
179echo -e " Start: ${BLUE}systemctl start metube${NC}"
180echo -e " Stop: ${BLUE}systemctl stop metube${NC}"
181echo -e " Status: ${BLUE}systemctl status metube${NC}"
182echo -e " Logs: ${BLUE}journalctl -u metube -f${NC}"
183echo ""
184echo -e "Download directory: ${YELLOW}/downloads${NC}"
185echo -e "Config file: ${YELLOW}${APP_DIR}/.env${NC}"