#!/bin/sh # Xtarwall XWatch installer for macOS and Linux. # curl -fsSL https://xtarwall.com/install.sh | sh # # What it does, and nothing more: # - checks for Node.js 22.6 or newer and npm; # - downloads Xtarwall XWatch v0.1.0 (a pinned GitHub tag) and checks its SHA-256; # - installs it into ${XTARWALL_HOME:-$HOME/.xtarwall}/watch, replacing an older copy only once the new one is ready; # - writes the launcher ${XTARWALL_HOME:-$HOME/.xtarwall}/bin/xtarwall-watch. # No sudo, no writes outside that folder (npm keeps its usual download cache), no changes to your shell profile. # Source: https://github.com/xtarwall/xwatch (AGPL-3.0-only) set -eu WATCH_VERSION="0.1.0" WATCH_URL="https://codeload.github.com/xtarwall/xwatch/tar.gz/refs/tags/v0.1.0" WATCH_SHA256="8209af62550a227c9016c6088c2de40cac75318c97b8977afd6f6d05eb41d7df" say() { printf '%s\n' "$*"; } die() { printf 'xtarwall-watch install: %s\n' "$*" >&2; exit 1; } # Quote a string for safe use inside a POSIX sh script: 'it'\''s' shq() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"; } need_node() { say "Xtarwall XWatch needs Node.js 22.6 or newer, with npm." say "Get it from https://nodejs.org (or your package manager), then run this installer again." exit 1 } sha256_of() { if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | awk '{print $1}' elif command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}' else die "need shasum or sha256sum to check the download" fi } download() { if command -v curl >/dev/null 2>&1; then curl -fsSL --proto '=https' --tlsv1.2 --retry 2 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" else die "need curl or wget to download Xtarwall XWatch" fi } main() { case "$(uname -s 2>/dev/null || echo unknown)" in Darwin|Linux) ;; *) die "this installer is for macOS and Linux. On Windows, use WSL." ;; esac command -v node >/dev/null 2>&1 || need_node command -v npm >/dev/null 2>&1 || need_node node -e 'const [a,b]=process.versions.node.split(".").map(Number);process.exit(a>22||(a===22&&b>=6)?0:1)' 2>/dev/null || { say "Found Node.js $(node --version 2>/dev/null || echo '(unknown version)'), which is too old." need_node } NODE_BIN=$(command -v node) case "$NODE_BIN" in /*) ;; *) NODE_BIN=node ;; esac [ -n "${HOME:-}" ] || die "HOME is not set" XH=${XTARWALL_HOME:-$HOME/.xtarwall} case "$XH" in /*) ;; *) die "XTARWALL_HOME must be an absolute path" ;; esac XH=${XH%/} [ -n "$XH" ] || die "XTARWALL_HOME must not be /" case "$XH" in *" "*) die "XTARWALL_HOME must not contain a newline" ;; esac umask 022 mkdir -p "$XH" "$XH/bin" # Everything below happens in a private work folder inside $XH, removed on exit. WORK=$(mktemp -d "$XH/.install.XXXXXX") || die "could not create a work folder in $XH" DEST="$XH/watch" # On any exit: if the old install was moved aside but the new one is not in place, put the old one back; then clean up. trap 'if [ -e "$WORK/old" ] && [ ! -e "$DEST" ] && [ ! -L "$DEST" ]; then mv "$WORK/old" "$DEST"; fi; rm -rf "$WORK"' EXIT trap 'exit 130' INT trap 'exit 143' TERM say "Downloading Xtarwall XWatch v$WATCH_VERSION ..." download "$WATCH_URL" "$WORK/watch.tar.gz" || die "download failed: $WATCH_URL" GOT=$(sha256_of "$WORK/watch.tar.gz") if [ "$GOT" != "$WATCH_SHA256" ]; then die "checksum mismatch, nothing was installed. expected $WATCH_SHA256 got $GOT" fi say "Checksum OK." mkdir "$WORK/new" tar -xzf "$WORK/watch.tar.gz" -C "$WORK/new" --strip-components=1 || die "could not unpack the download" [ -f "$WORK/new/bin/dh.ts" ] && [ -f "$WORK/new/package.json" ] || die "the download does not look like Xtarwall XWatch" say "Installing dependencies ..." [ -f "$WORK/new/package-lock.json" ] || die "the download has no package-lock.json, so its dependencies cannot be verified; nothing was installed" (cd "$WORK/new" && npm ci --omit=dev --ignore-scripts --no-audit --no-fund --loglevel=error --update-notifier=false) || die "npm could not install the dependencies; your previous install, if any, is untouched" LAUNCHER="$XH/bin/xtarwall-watch" { printf '#!/bin/sh\n' printf '# Xtarwall XWatch v%s launcher (written by https://xtarwall.com/install.sh)\n' "$WATCH_VERSION" printf 'NODE=%s\n' "$(shq "$NODE_BIN")" printf '[ -x "$NODE" ] || NODE=node\n' printf 'exec "$NODE" --experimental-strip-types %s "$@"\n' "$(shq "$DEST/bin/dh.ts")" } > "$WORK/launcher" chmod 755 "$WORK/launcher" # Swap in: move the old copy aside, move the new one in (same filesystem, so each step is a rename), then drop the old. if [ -e "$DEST" ] || [ -L "$DEST" ]; then mv "$DEST" "$WORK/old" || die "could not move the old install aside" fi if ! mv "$WORK/new" "$DEST"; then [ -e "$WORK/old" ] && mv "$WORK/old" "$DEST" die "could not move the new install into place; the old one was restored" fi mv -f "$WORK/launcher" "$LAUNCHER" || die "could not write the launcher $LAUNCHER" rm -rf "$WORK/old" BIN_DIR="$XH/bin" QL=$(shq "$LAUNCHER") # JSON string for the launcher path (escape \ and ") JL=$(printf '%s' "$LAUNCHER" | sed 's/\\/\\\\/g; s/"/\\"/g') JH=$(printf '%s' "$HOME" | sed 's/\\/\\\\/g; s/"/\\"/g') say "" say "Xtarwall XWatch v$WATCH_VERSION is installed in $DEST" say "Launcher: $LAUNCHER" say "" say "To run it from your shell, add this line to your shell profile:" say " export PATH=$(shq "$BIN_DIR"):\"\$PATH\"" say "" say "Connect it to your coding agent. Replace \$HOME/code with the folder that holds your repos." say "" say "Claude Code:" say " claude mcp add xtarwall-watch --scope user -e DH_MCP_ALLOWED_ROOTS=\"\$HOME/code\" -- $QL mcp" say "" say "Codex:" say " codex mcp add xtarwall-watch --env DH_MCP_ALLOWED_ROOTS=\"\$HOME/code\" -- $QL mcp" say "" say "Cursor (~/.cursor/mcp.json):" say " { \"mcpServers\": { \"xtarwall-watch\": {" say " \"command\": \"$JL\"," say " \"args\": [\"mcp\"]," say " \"env\": { \"DH_MCP_ALLOWED_ROOTS\": \"$JH/code\" } } } }" say "" say "XWatch uses your own AI key. Read more: https://xtarwall.com/watch/" } main "$@"