-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·165 lines (149 loc) · 5.82 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·165 lines (149 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh
# clawpatrol installer. Downloads a prebuilt binary from GitHub Releases.
# Falls back to source build when CLAWPATROL_FROM_SOURCE=1 (requires Go).
#
# Usage:
# curl -fsSL https://clawpatrol.dev/install.sh | sh
#
# Options (env vars):
# CLAWPATROL_VERSION — release tag (default: latest)
# CLAWPATROL_PREFIX — install dir (default: $HOME/.local/bin)
# CLAWPATROL_FROM_SOURCE — 1 to build from source (Go required)
# CLAWPATROL_REF — git ref when building from source (default: main)
# CLAWPATROL_NO_TELEMETRY — 1 to skip the anonymous install-event ping
#
# POSIX sh.
set -eu
REPO="denoland/clawpatrol"
VERSION="${CLAWPATROL_VERSION:-latest}"
PREFIX="${CLAWPATROL_PREFIX:-$HOME/.local/bin}"
# Anonymous install telemetry. Pings clawpatrol.dev with os/arch/
# version and a generated per-run id so we can count installs and
# debug failures. Opt out with CLAWPATROL_NO_TELEMETRY=1.
TELEMETRY_URL="https://clawpatrol.dev/api/telemetry/v1/install"
INSTALL_ID=""
telemetry() {
[ "${CLAWPATROL_NO_TELEMETRY:-0}" = "1" ] && return 0
command -v curl >/dev/null 2>&1 || return 0
if [ -z "$INSTALL_ID" ]; then
INSTALL_ID=$(
od -An -N16 -tx1 /dev/urandom 2>/dev/null | tr -d ' \n' \
|| date +%s%N 2>/dev/null \
|| date +%s
)
fi
event="$1"
reason="${2:-}"
body=$(printf '{"install_id":"%s","event":"%s","os":"%s","arch":"%s","version":"%s","from_source":"%s","reason":"%s"}' \
"$INSTALL_ID" "$event" \
"${OS:-}" "${ARCH:-}" "$VERSION" \
"${CLAWPATROL_FROM_SOURCE:-0}" "$reason")
(curl -fsS --max-time 3 -X POST \
-H 'Content-Type: application/json' \
-d "$body" "$TELEMETRY_URL" >/dev/null 2>&1 || true) &
}
if [ "$VERSION" = "latest" ]; then
BASE="https://github.com/${REPO}/releases/latest/download"
else
BASE="https://github.com/${REPO}/releases/download/${VERSION}"
fi
say() { printf '\033[1;36m==>\033[0m %s\n' "$*"; }
fail() { telemetry failed "$*"; printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH=amd64 ;;
arm64|aarch64) ARCH=arm64 ;;
*) fail "unsupported arch: $ARCH" ;;
esac
case "$OS" in
linux|darwin) ;;
*) fail "unsupported OS: $OS" ;;
esac
command -v curl >/dev/null 2>&1 || fail "curl required"
mkdir -p "$PREFIX"
# source-build branch
if [ "${CLAWPATROL_FROM_SOURCE:-0}" = "1" ]; then
REF="${CLAWPATROL_REF:-main}"
command -v go >/dev/null 2>&1 || fail "go toolchain required for source build"
command -v git >/dev/null 2>&1 || fail "git required"
SRC=$(mktemp -d)
trap 'rm -rf "$SRC"' EXIT INT TERM
say "cloning ${REPO}@${REF}"
git clone --depth 1 --branch "$REF" "https://github.com/${REPO}.git" "$SRC" >/dev/null 2>&1 \
|| git clone --depth 1 "https://github.com/${REPO}.git" "$SRC" >/dev/null 2>&1 \
|| fail "git clone failed"
if command -v deno >/dev/null 2>&1 && [ -d "$SRC/dashboard" ]; then
say "building dashboard"
( cd "$SRC/dashboard" && deno install >/dev/null 2>&1 && deno task build >/dev/null 2>&1 ) \
|| say "dashboard build failed (skipping)"
fi
mkdir -p "$SRC/dashboard/dist"
if [ -z "$(ls -A "$SRC/dashboard/dist" 2>/dev/null)" ]; then
printf '<!doctype html><html><body><pre>dashboard not built</pre></body></html>' > "$SRC/dashboard/dist/index.html"
fi
say "building clawpatrol"
( cd "$SRC" && go build -ldflags "-s -w" -trimpath -o clawpatrol ./cmd/clawpatrol ) || fail "go build failed"
mv "$SRC/clawpatrol" "$PREFIX/clawpatrol"
chmod +x "$PREFIX/clawpatrol"
say "installed: $PREFIX/clawpatrol"
telemetry completed
exit 0
fi
# binary download (default)
URL="${BASE}/clawpatrol-${OS}-${ARCH}"
TMP=$(mktemp)
trap 'rm -f "$TMP"' EXIT INT TERM
say "downloading ${URL}"
curl -fsSL -o "$TMP" "$URL" || fail "download failed (no release for ${OS}-${ARCH} at ${VERSION}?)"
# optional sha256 verify
SUMS=$(curl -fsSL "${BASE}/SHA256SUMS" 2>/dev/null || true)
if [ -n "$SUMS" ]; then
EXPECTED=$(printf '%s\n' "$SUMS" | awk -v f="clawpatrol-${OS}-${ARCH}" '$2==f{print $1}')
if [ -n "$EXPECTED" ]; then
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "$TMP" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "$TMP" | awk '{print $1}')
else
ACTUAL=""
fi
if [ -n "$ACTUAL" ]; then
[ "$EXPECTED" = "$ACTUAL" ] || fail "sha256 mismatch (expected $EXPECTED, got $ACTUAL)"
say "sha256 ok"
fi
fi
fi
mv "$TMP" "$PREFIX/clawpatrol"
chmod +x "$PREFIX/clawpatrol"
say "installed: $PREFIX/clawpatrol"
case ":$PATH:" in
*":$PREFIX:"*) ;;
*) printf '\n add to PATH: export PATH="%s:$PATH"\n\n' "$PREFIX" ;;
esac
"$PREFIX/clawpatrol" version 2>/dev/null || true
echo
# macOS: install Clawpatrol.app for `clawpatrol run`
# The .app holds the system extension that intercepts per-process
# flows. Without it `clawpatrol run` errors. Pulled from the same
# release as the Go binary, expanded to /Applications. Skip silently
# if the artifact isn't present (older releases or unsigned dev runs).
if [ "$OS" = "darwin" ]; then
APP_URL="${BASE}/Clawpatrol.app.tar.gz"
APP_TMP=$(mktemp -d)
if curl -fsSL -o "$APP_TMP/app.tgz" "$APP_URL" 2>/dev/null; then
say "installing Clawpatrol.app to /Applications"
rm -rf /Applications/Clawpatrol.app 2>/dev/null \
|| sudo rm -rf /Applications/Clawpatrol.app 2>/dev/null \
|| fail "couldn't remove old /Applications/Clawpatrol.app (need sudo?)"
if ! tar -xzf "$APP_TMP/app.tgz" -C /Applications 2>/dev/null; then
sudo tar -xzf "$APP_TMP/app.tgz" -C /Applications \
|| fail "extract Clawpatrol.app failed"
fi
else
say "Clawpatrol.app not in this release; skipping (run \`clawpatrol run\` won't work on macOS until you install the .app)"
fi
rm -rf "$APP_TMP"
fi
telemetry completed
echo "next: clawpatrol join <gateway-url>"