| 1 | #!/usr/bin/env bash |
| 2 | # One-click installer for Video-Claw. |
| 3 | |
| 4 | set -euo pipefail |
| 5 | |
| 6 | ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 7 | BACKEND_DIR="$ROOT_DIR/backend" |
| 8 | FRONTEND_DIR="$ROOT_DIR/frontend" |
| 9 | |
| 10 | info() { |
| 11 | printf "\033[1;34m[install]\033[0m %s\n" "$1" |
| 12 | } |
| 13 | |
| 14 | warn() { |
| 15 | printf "\033[1;33m[install]\033[0m %s\n" "$1" |
| 16 | } |
| 17 | |
| 18 | fail() { |
| 19 | printf "\033[1;31m[install]\033[0m %s\n" "$1" >&2 |
| 20 | exit 1 |
| 21 | } |
| 22 | |
| 23 | check_command() { |
| 24 | command -v "$1" >/dev/null 2>&1 || fail "$2" |
| 25 | } |
| 26 | |
| 27 | check_python() { |
| 28 | check_command python3 "Python 3.9+ is required. Please install Python first." |
| 29 | python3 - <<'PY' |
| 30 | import sys |
| 31 | if sys.version_info < (3, 9): |
| 32 | raise SystemExit("Python 3.9+ is required.") |
| 33 | print(f"Python {sys.version.split()[0]}") |
| 34 | PY |
| 35 | } |
| 36 | |
| 37 | check_ffmpeg() { |
| 38 | if ! command -v ffmpeg >/dev/null 2>&1; then |
| 39 | warn "ffmpeg was not found. Video concatenation and audio/video post-processing will be unavailable." |
| 40 | return 0 |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | ensure_uv() { |
| 45 | if command -v uv >/dev/null 2>&1; then |
| 46 | return 0 |
| 47 | fi |
| 48 | |
| 49 | warn "uv was not found. Installing uv with python3 -m pip..." |
| 50 | python3 -m pip install --user uv |
| 51 | |
| 52 | if ! command -v uv >/dev/null 2>&1; then |
| 53 | warn "uv is still not on PATH. Falling back to venv + pip for backend dependencies." |
| 54 | return 1 |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | install_backend() { |
| 59 | info "Installing backend dependencies..." |
| 60 | cd "$BACKEND_DIR" |
| 61 | |
| 62 | if [ ! -f "config.yaml" ] && [ -f "config.yaml.example" ]; then |
| 63 | cp config.yaml.example config.yaml |
| 64 | warn "Created backend config.yaml from config.yaml.example. Fill in API keys before generating videos." |
| 65 | fi |
| 66 | |
| 67 | if ensure_uv; then |
| 68 | uv sync |
| 69 | else |
| 70 | python3 -m venv venv |
| 71 | # shellcheck disable=SC1091 |
| 72 | source venv/bin/activate |
| 73 | python -m pip install --upgrade pip |
| 74 | python -m pip install -r requirements.txt |
| 75 | fi |
| 76 | } |
| 77 | |
| 78 | install_frontend() { |
| 79 | info "Installing frontend dependencies..." |
| 80 | cd "$FRONTEND_DIR" |
| 81 | |
| 82 | check_command node "Node.js 18+ is required. Please install Node.js first." |
| 83 | check_command npm "npm is required. Please install npm first." |
| 84 | |
| 85 | if [ -f "package-lock.json" ]; then |
| 86 | npm ci |
| 87 | else |
| 88 | npm install |
| 89 | fi |
| 90 | |
| 91 | if [ "${AIGC_DIRECTOR_SKIP_FRONTEND_BUILD:-0}" = "1" ]; then |
| 92 | warn "Skipping frontend build because AIGC_DIRECTOR_SKIP_FRONTEND_BUILD=1." |
| 93 | else |
| 94 | npm run build |
| 95 | fi |
| 96 | } |
| 97 | |
| 98 | main() { |
| 99 | info "Video-Claw one-click install" |
| 100 | check_python |
| 101 | check_ffmpeg |
| 102 | install_backend |
| 103 | install_frontend |
| 104 | |
| 105 | cat <<EOF |
| 106 | |
| 107 | Video-Claw installation complete. |
| 108 | |
| 109 | Next steps: |
| 110 | 1. Edit backend API keys: |
| 111 | $BACKEND_DIR/config.yaml |
| 112 | |
| 113 | 2. Start backend: |
| 114 | cd "$BACKEND_DIR" |
| 115 | uv run python api_server.py |
| 116 | # or, if uv was unavailable: |
| 117 | source venv/bin/activate && python api_server.py |
| 118 | |
| 119 | 3. Start frontend in a new terminal: |
| 120 | cd "$FRONTEND_DIR" |
| 121 | npm start |
| 122 | |
| 123 | URLs: |
| 124 | Backend: http://localhost:8000/api/health |
| 125 | Frontend: http://localhost:3000 |
| 126 | EOF |
| 127 | } |
| 128 | |
| 129 | main "$@" |
| 130 |