setup.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env bash
  2. # HyperFrames setup for Hermes.
  3. #
  4. # Verifies Node >= 22 and FFmpeg, installs the `hyperframes` CLI globally,
  5. # pre-caches `chrome-headless-shell`, and runs `hyperframes doctor`.
  6. #
  7. # Pins `hyperframes@>=0.4.2` so the OpenClaw/Chromium-147 fix from
  8. # https://github.com/heygen-com/hyperframes/issues/294 (commit 4c72ba4)
  9. # is always present — the engine auto-detects `HeadlessExperimental.beginFrame`
  10. # support and falls back to screenshot capture otherwise.
  11. #
  12. # Idempotent: safe to re-run.
  13. set -euo pipefail
  14. MIN_NODE_MAJOR=22
  15. MIN_HYPERFRAMES_VERSION="0.4.2"
  16. red() { printf '\033[31m%s\033[0m\n' "$*"; }
  17. green() { printf '\033[32m%s\033[0m\n' "$*"; }
  18. yellow() { printf '\033[33m%s\033[0m\n' "$*"; }
  19. bold() { printf '\033[1m%s\033[0m\n' "$*"; }
  20. bold "==> HyperFrames setup"
  21. # --- 1. Node.js --------------------------------------------------------------
  22. if ! command -v node >/dev/null 2>&1; then
  23. red "✗ Node.js is not installed."
  24. echo " Install Node.js >= ${MIN_NODE_MAJOR} (nvm, Homebrew, or your package manager) and re-run."
  25. exit 1
  26. fi
  27. node_version="$(node --version | sed 's/^v//')"
  28. node_major="$(echo "$node_version" | cut -d. -f1)"
  29. if [ "$node_major" -lt "$MIN_NODE_MAJOR" ]; then
  30. red "✗ Node.js ${node_version} is too old. HyperFrames requires Node.js >= ${MIN_NODE_MAJOR}."
  31. echo " Upgrade with 'nvm install ${MIN_NODE_MAJOR} && nvm use ${MIN_NODE_MAJOR}' or your package manager."
  32. exit 1
  33. fi
  34. green "✓ Node.js ${node_version}"
  35. # --- 2. FFmpeg ---------------------------------------------------------------
  36. if ! command -v ffmpeg >/dev/null 2>&1; then
  37. red "✗ FFmpeg is not installed."
  38. case "$(uname -s)" in
  39. Linux*) echo " sudo apt-get install -y ffmpeg # Debian/Ubuntu"
  40. echo " sudo dnf install -y ffmpeg # Fedora/RHEL";;
  41. Darwin*) echo " brew install ffmpeg";;
  42. MINGW*|MSYS*|CYGWIN*) echo " winget install Gyan.FFmpeg";;
  43. *) echo " See https://ffmpeg.org/download.html";;
  44. esac
  45. exit 1
  46. fi
  47. green "✓ FFmpeg $(ffmpeg -version 2>&1 | head -1 | awk '{print $3}')"
  48. # --- 3. npm ------------------------------------------------------------------
  49. if ! command -v npm >/dev/null 2>&1; then
  50. red "✗ npm is not installed (should ship with Node.js)."
  51. exit 1
  52. fi
  53. # --- 4. Install / upgrade hyperframes CLI -----------------------------------
  54. bold "==> Installing hyperframes CLI (>= ${MIN_HYPERFRAMES_VERSION})"
  55. current_hyperframes=""
  56. if command -v hyperframes >/dev/null 2>&1; then
  57. current_hyperframes="$(hyperframes --version 2>/dev/null | tail -1 | sed 's/^v//')"
  58. fi
  59. if [ -n "$current_hyperframes" ]; then
  60. yellow " Found hyperframes ${current_hyperframes}"
  61. fi
  62. # Always install/upgrade to >= MIN version.
  63. # Using 'latest' so we pick up any newer auto-detect/capture fixes.
  64. if ! npm install -g "hyperframes@latest" >/dev/null 2>&1; then
  65. red "✗ npm install -g hyperframes@latest failed."
  66. echo " Try: sudo npm install -g hyperframes@latest"
  67. echo " Or use a user-scoped npm prefix: npm config set prefix ~/.npm-global && export PATH=\"\$HOME/.npm-global/bin:\$PATH\""
  68. exit 1
  69. fi
  70. installed_version="$(hyperframes --version 2>/dev/null | tail -1 | sed 's/^v//')"
  71. green "✓ hyperframes ${installed_version} installed globally"
  72. # Sanity-check minimum version.
  73. version_ge() {
  74. # version_ge A B → true if A >= B
  75. [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -1)" = "$2" ]
  76. }
  77. if ! version_ge "$installed_version" "$MIN_HYPERFRAMES_VERSION"; then
  78. red "✗ hyperframes ${installed_version} is below required minimum ${MIN_HYPERFRAMES_VERSION}."
  79. echo " Try 'npm install -g hyperframes@latest' or 'sudo npm install -g hyperframes@latest'."
  80. exit 1
  81. fi
  82. # --- 5. Pre-cache chrome-headless-shell --------------------------------------
  83. #
  84. # Chromium 147+ removed HeadlessExperimental.beginFrame. System Chrome (e.g.
  85. # /usr/bin/google-chrome) can't render with the fast path, so the engine
  86. # auto-detects and falls back to screenshot mode — but BeginFrame mode is
  87. # faster and produces higher-quality output. Install chrome-headless-shell
  88. # up front so the engine picks it over system Chrome.
  89. bold "==> Pre-caching chrome-headless-shell (for best render quality)"
  90. if ! npx --yes puppeteer browsers install chrome-headless-shell >/dev/null 2>&1; then
  91. yellow "⚠ Could not pre-install chrome-headless-shell."
  92. yellow " Rendering will still work via screenshot-mode fallback (slower)."
  93. yellow " If you hit HeadlessExperimental.beginFrame errors:"
  94. yellow " export PRODUCER_FORCE_SCREENSHOT=true"
  95. yellow " See references/troubleshooting.md."
  96. else
  97. green "✓ chrome-headless-shell installed"
  98. fi
  99. # --- 6. Doctor ---------------------------------------------------------------
  100. bold "==> Running hyperframes doctor"
  101. if hyperframes doctor; then
  102. green "✓ HyperFrames is ready"
  103. echo
  104. echo " Scaffold a project: npx hyperframes init my-video"
  105. echo " Preview: npx hyperframes preview"
  106. echo " Render: npx hyperframes render"
  107. else
  108. yellow "⚠ hyperframes doctor reported issues."
  109. yellow " See references/troubleshooting.md or re-run 'hyperframes doctor'."
  110. exit 1
  111. fi