install.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. #
  3. # CodeGraph standalone installer.
  4. #
  5. # Downloads a self-contained bundle (a vendored Node runtime + the app) from
  6. # GitHub Releases. No Node.js, no build tools, no npm required — ideal for a
  7. # fresh Linux VPS over SSH.
  8. #
  9. # curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh
  10. #
  11. # Upgrade: re-run the same command.
  12. # Uninstall: curl -fsSL .../install.sh | sh -s -- --uninstall
  13. #
  14. # Environment:
  15. # CODEGRAPH_VERSION release tag to install (default: latest)
  16. # CODEGRAPH_INSTALL_DIR bundle location (default: ~/.codegraph)
  17. # CODEGRAPH_BIN_DIR symlink location (default: ~/.local/bin)
  18. set -eu
  19. REPO="colbymchenry/codegraph"
  20. INSTALL_DIR="${CODEGRAPH_INSTALL_DIR:-$HOME/.codegraph}"
  21. BIN_DIR="${CODEGRAPH_BIN_DIR:-$HOME/.local/bin}"
  22. if [ "${1:-}" = "--uninstall" ]; then
  23. rm -f "$BIN_DIR/codegraph"
  24. rm -rf "$INSTALL_DIR"
  25. echo "CodeGraph uninstalled (removed $INSTALL_DIR and $BIN_DIR/codegraph)."
  26. exit 0
  27. fi
  28. # 1. Detect platform → target triple matching the release archives.
  29. os="$(uname -s)"
  30. arch="$(uname -m)"
  31. case "$os" in
  32. Darwin) os="darwin" ;;
  33. Linux) os="linux" ;;
  34. *) echo "codegraph: unsupported OS '$os'." >&2; exit 1 ;;
  35. esac
  36. case "$arch" in
  37. arm64|aarch64) arch="arm64" ;;
  38. x86_64|amd64) arch="x64" ;;
  39. *) echo "codegraph: unsupported architecture '$arch'." >&2; exit 1 ;;
  40. esac
  41. target="${os}-${arch}"
  42. # 2. Resolve the version (latest release unless pinned).
  43. version="${CODEGRAPH_VERSION:-}"
  44. if [ -z "$version" ]; then
  45. version="$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
  46. | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -n1)"
  47. fi
  48. [ -n "$version" ] || { echo "codegraph: could not resolve latest version; set CODEGRAPH_VERSION." >&2; exit 1; }
  49. # 3. Download + extract the bundle.
  50. url="https://github.com/$REPO/releases/download/$version/codegraph-${target}.tar.gz"
  51. echo "Installing CodeGraph $version ($target)..."
  52. tmp="$(mktemp -d)"
  53. trap 'rm -rf "$tmp"' EXIT
  54. curl -fsSL "$url" -o "$tmp/cg.tar.gz" || { echo "codegraph: download failed: $url" >&2; exit 1; }
  55. dest="$INSTALL_DIR/versions/$version"
  56. rm -rf "$dest"
  57. mkdir -p "$dest"
  58. # Archives contain a top-level codegraph-<target>/ dir; strip it.
  59. tar -xzf "$tmp/cg.tar.gz" -C "$dest" --strip-components=1
  60. # 4. Symlink the launcher onto PATH and mark the current version.
  61. mkdir -p "$BIN_DIR"
  62. ln -sf "$dest/bin/codegraph" "$BIN_DIR/codegraph"
  63. ln -sfn "$dest" "$INSTALL_DIR/current"
  64. echo "Installed to $dest"
  65. echo "Linked $BIN_DIR/codegraph"
  66. case ":$PATH:" in
  67. *":$BIN_DIR:"*) ;;
  68. *)
  69. echo ""
  70. echo "$BIN_DIR is not on your PATH. Add it:"
  71. echo " export PATH=\"$BIN_DIR:\$PATH\""
  72. ;;
  73. esac
  74. echo ""
  75. echo "Done. Run: codegraph --help"