-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·346 lines (299 loc) · 10.5 KB
/
install.sh
File metadata and controls
executable file
·346 lines (299 loc) · 10.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/sh
# Dune CLI installer
# Usage: curl -sSfL https://github.com/duneanalytics/cli/raw/main/install.sh | bash
#
# Environment variables:
# INSTALL_DIR — override installation directory (default: auto-detected)
# VERSION — specific version to install (default: latest)
# GITHUB_TOKEN — GitHub token for private repo access
set -e
REPO="duneanalytics/cli"
BINARY="dune"
PROJECT="dune-cli"
main() {
need_cmd uname
need_cmd mktemp
need_cmd chmod
need_cmd rm
os=$(detect_os)
arch=$(detect_arch)
version=$(resolve_version)
if [ -z "$version" ]; then
err "could not determine latest version"
fi
# Strip leading 'v' for archive name
version_num="${version#v}"
if [ -n "$INSTALL_DIR" ]; then
install_dir="$INSTALL_DIR"
else
install_dir=$(detect_install_dir)
fi
case "$os" in
windows) ext="zip" ;;
*) ext="tar.gz" ;;
esac
archive="${PROJECT}_${version_num}_${os}_${arch}.${ext}"
url="https://github.com/${REPO}/releases/download/${version}/${archive}"
checksum_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
log "Downloading ${BINARY} ${version} for ${os}/${arch}..."
download "$url" "$tmp/$archive"
download "$checksum_url" "$tmp/checksums.txt"
log "Verifying checksum..."
verify_checksum "$tmp/$archive" "$tmp/checksums.txt" "$archive"
log "Extracting..."
case "$ext" in
tar.gz) tar -xzf "$tmp/$archive" -C "$tmp" ;;
zip) need_cmd unzip; unzip -q "$tmp/$archive" -d "$tmp" ;;
esac
binary_name="$BINARY"
if [ "$os" = "windows" ]; then
binary_name="${BINARY}.exe"
fi
if [ ! -f "$tmp/$binary_name" ]; then
err "binary '$binary_name' not found in archive"
fi
chmod +x "$tmp/$binary_name"
mkdir -p "$install_dir" 2>/dev/null || true
if [ -w "$install_dir" ]; then
mv "$tmp/$binary_name" "$install_dir/$binary_name"
else
log "Installing to ${install_dir} (requires sudo)..."
sudo mkdir -p "$install_dir"
sudo mv "$tmp/$binary_name" "$install_dir/$binary_name"
fi
# Post-install interactive setup only when we have a usable terminal.
if has_tty; then
post_install "${install_dir}/${binary_name}" "$version"
else
echo "" >&2
log "Dune CLI ${version} installed successfully!"
echo "" >&2
log "Tip: Run 'npx skills add duneanalytics/skills' to install Dune AI skills."
log "Tip: Run 'dune auth' to authenticate with your Dune account."
log "Tip: Run 'dune sim auth' to access real-time blockchain data (balances, tokens, NFTs)."
fi
}
post_install() {
dune_bin="$1"
dune_version="$2"
echo "" >&2
# --- Skill install ---
if has npx; then
log "Dune skills let AI agents (Cursor, Claude Code, etc.) query"
log "blockchain data and access real-time wallet/token info on your behalf."
printf " Install Dune skills for your AI coding agent? [Y/n] " >&2
read -r answer < /dev/tty || answer=""
case "$answer" in
[nN]*)
log "Skipped. You can install them later with: npx skills add duneanalytics/skills"
;;
*)
log "Installing Dune skills..."
npx skills add duneanalytics/skills --skill '*' < /dev/tty || log "Skill installation failed. You can retry with: npx skills add duneanalytics/skills"
;;
esac
else
log "Tip: Run 'npx skills add duneanalytics/skills' to install Dune AI skills."
log "(requires Node.js / npx)"
fi
echo "" >&2
# --- Authentication ---
if "$dune_bin" usage > /dev/null 2>&1; then
log "Already authenticated with Dune."
else
log "Authenticate to start running queries and accessing your Dune account."
printf " Authenticate with Dune now? [Y/n] " >&2
read -r answer < /dev/tty || answer=""
case "$answer" in
[nN]*)
log "Skipped. You can authenticate later with: dune auth"
;;
*)
echo "" >&2
log "You'll need a Dune API key. To create one:"
log " 1. Go to https://dune.com and login or create an account"
log " 2. Navigate to 'APIs & Connectors'"
log " 3. Click 'API Keys' and create a new key"
echo "" >&2
"$dune_bin" auth < /dev/tty || log "Authentication failed. You can retry with: dune auth"
;;
esac
fi
echo "" >&2
# --- Sim API Authentication ---
if "$dune_bin" sim evm token-info native --chain-ids 1 > /dev/null 2>&1; then
log "Already authenticated with Sim API."
else
log "Authenticate with the Sim API to access real-time blockchain data"
log "(wallet balances, token prices, NFTs, DeFi positions, etc.)."
printf " Authenticate with Sim API now? [Y/n] " >&2
read -r answer < /dev/tty || answer=""
case "$answer" in
[nN]*)
log "Skipped. You can authenticate later with: dune sim auth"
;;
*)
echo "" >&2
log "You'll need a Sim API key. To create one:"
log " 1. Go to https://sim.dune.com/ and login or create an account"
log " 2. Click 'Keys'"
log " 3. Click 'New' to create a new API key"
echo "" >&2
"$dune_bin" sim auth < /dev/tty || log "Authentication failed. You can retry with: dune sim auth"
;;
esac
fi
echo "" >&2
log "Dune CLI ${dune_version} installed successfully!"
}
has_tty() {
[ -t 0 ] || [ -t 1 ] || [ -t 2 ]
}
# Pick the best install directory by checking user-writable directories
# already on PATH, falling back to /usr/local/bin (always on PATH).
detect_install_dir() {
for candidate in \
"$HOME/.local/bin" \
"$HOME/bin" \
"$HOME/go/bin" \
"$HOME/.cargo/bin"; do
case ":$PATH:" in
*":${candidate}:"*)
if [ -d "$candidate" ] && [ -w "$candidate" ]; then
echo "$candidate"
return
fi
;;
esac
done
echo "/usr/local/bin"
}
detect_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux*) echo "linux" ;;
darwin*) echo "darwin" ;;
mingw*|msys*|cygwin*) echo "windows" ;;
*) err "unsupported OS: $os" ;;
esac
}
detect_arch() {
arch=$(uname -m)
case "$arch" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) err "unsupported architecture: $arch" ;;
esac
}
resolve_version() {
if [ -n "$VERSION" ]; then
case "$VERSION" in
v*) echo "$VERSION" ;;
*) echo "v$VERSION" ;;
esac
return
fi
auth_header=""
if [ -n "$GITHUB_TOKEN" ]; then
auth_header="Authorization: token $GITHUB_TOKEN"
fi
if has curl; then
curl -sSfL -H "Accept: application/json" ${auth_header:+-H "$auth_header"} \
"https://api.github.com/repos/${REPO}/releases/latest" \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p'
elif has wget; then
wget -qO- --header="Accept: application/json" ${auth_header:+--header="$auth_header"} \
"https://api.github.com/repos/${REPO}/releases/latest" \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p'
else
err "need curl or wget to determine latest version"
fi
}
download() {
url="$1"
dest="$2"
if [ -n "$GITHUB_TOKEN" ]; then
# Private repos require downloading via the API asset endpoint.
# The direct github.com/.../releases/download/... URL returns 404.
asset_name=$(basename "$url")
release_url="https://api.github.com/repos/${REPO}/releases/tags/${version}"
if has curl; then
asset_api_url=$(curl -sSfL \
-H "Authorization: token $GITHUB_TOKEN" \
"$release_url" \
| grep -B3 "\"name\": \"${asset_name}\"" \
| sed -n 's/.*"url": "\(https:\/\/api\.github\.com\/repos\/.*\/releases\/assets\/[0-9]*\)".*/\1/p')
if [ -n "$asset_api_url" ]; then
curl -sSfL \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/octet-stream" \
-o "$dest" \
"$asset_api_url"
else
curl -sSfL -o "$dest" "$url"
fi
elif has wget; then
asset_api_url=$(wget -qO- \
--header="Authorization: token $GITHUB_TOKEN" \
"$release_url" \
| grep -B3 "\"name\": \"${asset_name}\"" \
| sed -n 's/.*"url": "\(https:\/\/api\.github\.com\/repos\/.*\/releases\/assets\/[0-9]*\)".*/\1/p')
if [ -n "$asset_api_url" ]; then
wget -qO "$dest" \
--header="Authorization: token $GITHUB_TOKEN" \
--header="Accept: application/octet-stream" \
"$asset_api_url"
else
wget -qO "$dest" "$url"
fi
else
err "need curl or wget to download files"
fi
else
if has curl; then
curl -sSfL -o "$dest" "$url"
elif has wget; then
wget -qO "$dest" "$url"
else
err "need curl or wget to download files"
fi
fi
}
verify_checksum() {
file="$1"
checksum_file="$2"
archive_name="$3"
expected=$(awk -v name="$archive_name" '$2 == name || $2 == "*"name { print $1; exit }' "$checksum_file")
if [ -z "$expected" ]; then
err "checksum not found for $archive_name"
fi
if has sha256sum; then
actual=$(sha256sum "$file" | awk '{print $1}')
elif has shasum; then
actual=$(shasum -a 256 "$file" | awk '{print $1}')
else
log "WARNING: could not verify checksum (no sha256sum or shasum found)"
return 0
fi
if [ "$expected" != "$actual" ]; then
err "checksum mismatch: expected $expected, got $actual"
fi
}
has() {
command -v "$1" > /dev/null 2>&1
}
need_cmd() {
if ! has "$1"; then
err "required command not found: $1"
fi
}
log() {
echo " $*" >&2
}
err() {
log "error: $*"
exit 1
}
main "$@"