forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·50 lines (40 loc) · 1.36 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.36 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
#!/usr/bin/env bash
set -euo pipefail
root="$(cd "$(dirname "$0")" && pwd)"
cd "$root"
cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/opencode"
models_json="${MODELS_DEV_API_JSON:-$cache_dir/models.json}"
tmpdir="${TMPDIR:-/tmp}"
fetched="$tmpdir/opencode-models-api.json"
fetch_models() {
if [[ -n "${MODELS_DEV_API_JSON:-}" && -f "$MODELS_DEV_API_JSON" ]]; then
echo "==> using MODELS_DEV_API_JSON=$MODELS_DEV_API_JSON"
return 0
fi
echo "==> fetching models.dev/api.json"
if curl -fsSL --max-time 30 https://models.dev/api.json -o "$fetched" \
&& [[ -s "$fetched" ]]; then
mkdir -p "$cache_dir"
cp "$fetched" "$models_json"
export MODELS_DEV_API_JSON="$models_json"
echo "==> saved $models_json"
return 0
fi
if [[ -s "$models_json" ]]; then
echo "==> models.dev fetch failed; using cached $models_json"
export MODELS_DEV_API_JSON="$models_json"
return 0
fi
echo "error: could not fetch https://models.dev/api.json and no cache at $models_json" >&2
echo "hint: download api.json on a working network, then:" >&2
echo " MODELS_DEV_API_JSON=/path/to/api.json ./build.sh" >&2
return 1
}
echo "==> installing dependencies"
bun install
fetch_models
echo "==> building binaries${*:+ ($*)}"
./packages/opencode/script/build.ts "$@"
echo "==> done"
echo "binaries in: $root/packages/opencode/dist"
ls -1 packages/opencode/dist