|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ========================================== |
| 4 | +# TranscodeGroup One-Click Installer |
| 5 | +# Downloads repo, installs deps, runs setup |
| 6 | +# Usage: |
| 7 | +# curl -fsSL https://raw.githubusercontent.com/.../download-and-install.sh | bash |
| 8 | +# curl -fsSL https://raw.githubusercontent.com/TranscodeGroup/docker/perf/deploy/nxr/download-and-install.sh | sudo BRANCH=perf/deploy/nxr bash |
| 9 | +# ========================================== |
| 10 | + |
| 11 | +set -e |
| 12 | + |
| 13 | +# Colors |
| 14 | +GREEN='\033[0;32m' |
| 15 | +BLUE='\033[0;34m' |
| 16 | +RED='\033[0;31m' |
| 17 | +NC='\033[0m' |
| 18 | + |
| 19 | +REPO_URL="https://github.com/TranscodeGroup/docker.git" |
| 20 | +INSTALL_DIR="/home/docker" |
| 21 | +# Allow overriding branch via env var, default to 'master' |
| 22 | +BRANCH=${BRANCH:-"master"} |
| 23 | + |
| 24 | +echo -e "${BLUE}>>> Starting TranscodeGroup Installer...${NC}" |
| 25 | + |
| 26 | +# 1. Root Check |
| 27 | +if [ "$EUID" -ne 0 ]; then |
| 28 | + echo -e "${RED}Please run as root (sudo su).${NC}" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +# 2. System Dependencies (Git) |
| 33 | +if ! command -v git &> /dev/null; then |
| 34 | + echo -e "${BLUE}Installing Git...${NC}" |
| 35 | + if [ -f /etc/redhat-release ]; then |
| 36 | + yum install -y git |
| 37 | + elif [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then |
| 38 | + apt-get update && apt-get install -y git |
| 39 | + else |
| 40 | + echo -e "${RED}Unsupported OS for auto-install. Please install git manually.${NC}" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +else |
| 44 | + echo -e "${GREEN}Git detected.${NC}" |
| 45 | +fi |
| 46 | + |
| 47 | +# 3. Clone Repository or Update |
| 48 | +if [ -d "$INSTALL_DIR" ]; then |
| 49 | + if [ -d "$INSTALL_DIR/.git" ]; then |
| 50 | + echo -e "${BLUE}Updating existing repository at $INSTALL_DIR...${NC}" |
| 51 | + cd "$INSTALL_DIR" |
| 52 | + |
| 53 | + # Auto-detect branch if user didn't specify one |
| 54 | + if [ "$BRANCH" == "master" ]; then |
| 55 | + DETECTED_LOCAL_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "master") |
| 56 | + if [ "$DETECTED_LOCAL_BRANCH" != "HEAD" ]; then |
| 57 | + BRANCH=$DETECTED_LOCAL_BRANCH |
| 58 | + echo -e "${BLUE}Auto-detected current branch: $BRANCH${NC}" |
| 59 | + fi |
| 60 | + fi |
| 61 | + |
| 62 | + git fetch origin |
| 63 | + git reset --hard "origin/$BRANCH" |
| 64 | + git clean -fd |
| 65 | + echo -e "${GREEN}Successfully reset to origin/$BRANCH and cleaned worktree.${NC}" |
| 66 | + else |
| 67 | + # Directory exists but is NOT a git repo (e.g. manual mkdir or unzip) |
| 68 | + if [ "$(ls -A $INSTALL_DIR)" ]; then |
| 69 | + BACKUP_DIR="${INSTALL_DIR}_backup_$(date +%s)" |
| 70 | + echo -e "${YELLOW}Directory $INSTALL_DIR exists but is not a git repo.${NC}" |
| 71 | + echo -e "${YELLOW}Renaming to $BACKUP_DIR to allow fresh install...${NC}" |
| 72 | + mv "$INSTALL_DIR" "$BACKUP_DIR" |
| 73 | + |
| 74 | + echo -e "${BLUE}Cloning repository to $INSTALL_DIR...${NC}" |
| 75 | + git clone -b "$BRANCH" "$REPO_URL" "$INSTALL_DIR" |
| 76 | + else |
| 77 | + # Directory exists but is empty |
| 78 | + echo -e "${BLUE}Cloning repository to existing empty directory $INSTALL_DIR...${NC}" |
| 79 | + git clone -b "$BRANCH" "$REPO_URL" "$INSTALL_DIR" |
| 80 | + fi |
| 81 | + fi |
| 82 | +else |
| 83 | + echo -e "${BLUE}Cloning repository to $INSTALL_DIR...${NC}" |
| 84 | + mkdir -p "$(dirname "$INSTALL_DIR")" |
| 85 | + git clone -b "$BRANCH" "$REPO_URL" "$INSTALL_DIR" |
| 86 | +fi |
| 87 | + |
| 88 | +# 4. Docker Check & Install |
| 89 | +if ! command -v docker &> /dev/null; then |
| 90 | + echo -e "${BLUE}Docker not found. Installing via official script...${NC}" |
| 91 | + curl -fsSL https://get.docker.com | bash |
| 92 | + systemctl enable docker |
| 93 | + systemctl start docker |
| 94 | + echo -e "${GREEN}Docker installed.${NC}" |
| 95 | +else |
| 96 | + echo -e "${GREEN}Docker detected.${NC}" |
| 97 | +fi |
| 98 | + |
| 99 | +# 5. Handover to setup-services.sh |
| 100 | +DEPLOY_SCRIPT="$INSTALL_DIR/setup-services.sh" |
| 101 | + |
| 102 | +if [ -f "$DEPLOY_SCRIPT" ]; then |
| 103 | + chmod +x "$DEPLOY_SCRIPT" |
| 104 | + echo -e "${BLUE}>>> Handing over to setup-services.sh...${NC}" |
| 105 | + echo "" |
| 106 | + # Switch to directory before execution to ensure relative paths work |
| 107 | + cd "$INSTALL_DIR" |
| 108 | + exec ./setup-services.sh |
| 109 | +else |
| 110 | + echo -e "${RED}Critical Error: setup-services.sh not found in downloaded repository!${NC}" |
| 111 | + exit 1 |
| 112 | +fi |
0 commit comments