#!/bin/bash
set -euo pipefail
# Download first, inspect this script, then run: bash install.sh
# Requires macOS + Node.js 22+. No sudo; this never performs cleanup or recovery automatically.
[[ "$(uname -s)" == "Darwin" ]] || { echo 'This tool supports macOS only.' >&2; exit 1; }
command -v node >/dev/null && command -v npm >/dev/null || { echo 'Install Node.js 22+ first.' >&2; exit 1; }
node -e 'if(Number(process.versions.node.split(".")[0])<22)process.exit(1)' || { echo 'Node.js 22+ required.' >&2; exit 1; }
[[ "$(id -u)" != "0" ]] || { echo 'Run without sudo.' >&2; exit 1; }
DEST="$PWD/claude-account-reset-0.3.0"
mkdir "$DEST" || { echo 'Destination exists; nothing overwritten.' >&2; exit 1; }
ARCHIVE="$DEST/tool.tar.gz"
curl --fail --show-error --silent --location --proto '=https' --tlsv1.2 'https://claude-account-reset.pages.dev/downloads/claude-account-reset-0.3.0.tar.gz' --output "$ARCHIVE"
printf '%s  %s\n' '8569c1674c1c29c8cef5ecb56fdb485b323a6f567332e62488b550f0fd06e6d5' "$ARCHIVE" | shasum -a 256 -c -
tar -xzf "$ARCHIVE" -C "$DEST"
rm "$ARCHIVE"
cd "$DEST"
npm ci --omit=dev --ignore-scripts --no-audit --no-fund
printf '\nInstalled %s. Quit Claude, then run the inspection:\n' "$DEST"
printf 'cd "%s"\nnode bin/reset.mjs --traces\nnode bin/recover.mjs\nnode bin/handoff.mjs\n' "$DEST"
printf '\nNo Claude data has been inspected or changed by this installer.\n'
