-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetch-engine.sh
More file actions
executable file
·128 lines (113 loc) · 4.3 KB
/
Copy pathfetch-engine.sh
File metadata and controls
executable file
·128 lines (113 loc) · 4.3 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
#!/bin/sh
# fetch-engine.sh — download + cache the prebuilt pure-Aether engine
# (libselenium_core) from the project's GitHub releases, so a dev building a
# LINK-TIME binding (rust/go/c/cpp/nim/zig/…) needs no Aether toolchain.
#
# scripts/fetch-engine.sh # this platform, the pinned tag
# TAG=v0.8.0 scripts/fetch-engine.sh # pin an engine release
# FORCE=1 scripts/fetch-engine.sh # re-download
# scripts/fetch-engine.sh --path # just print the cache path, don't fetch
#
# It writes to the SAME per-user cache the runtime bindings (ruby/python/dart/
# php/lua/julia) use — $XDG_CACHE_HOME/selaenium/<tag>/libselenium_core.<ext>
# (~/.cache on Linux, ~/Library/Caches on macOS, %LOCALAPPDATA% on Windows) — so
# every binding shares one downloaded engine. The link-time build scripts add
# that dir to their library search path, so after running this once you just
# build normally.
#
# Portable POSIX sh; needs curl or wget, and sha256sum or shasum. Verifies the
# published .sha256 sidecar. Idempotent: a present, checksum-matching copy is a
# no-op.
set -eu
# The libselenium_core gh-release tag. Single source of truth: the repo-root
# SELENIUM_CORE_VERSION file (read here, overridable via TAG=). Every binding
# reads that same file so the tag lives in ONE place.
_here="$(cd "$(dirname "$0")/.." && pwd)" # repo root (scripts/ is one down)
TAG="${TAG:-$(cat "$_here/SELENIUM_CORE_VERSION")}"
REPO="aether-lang-dev/selaenium"
BASE="https://github.com/${REPO}/releases/download"
path_only=0
[ "${1:-}" = "--path" ] && path_only=1
# ---- platform -> release asset name (matches release/build.sh) ----
uname_s="$(uname -s 2>/dev/null || echo unknown)"
uname_m="$(uname -m 2>/dev/null || echo unknown)"
case "$uname_s" in
Linux) os=linux; ext=so ;;
Darwin) os=macos; ext=dylib ;;
FreeBSD) os=freebsd; ext=so ;;
MINGW*|MSYS*|CYGWIN*|Windows*) os=windows; ext=dll ;;
*) echo "fetch-engine: unsupported OS: $uname_s" >&2; exit 1 ;;
esac
case "$uname_m" in
x86_64|amd64) arch=x86_64 ;;
arm64|aarch64) arch=arm64 ;;
*) echo "fetch-engine: unsupported CPU: $uname_m" >&2; exit 1 ;;
esac
asset="libselenium_core-${TAG}-${os}-${arch}.${ext}"
# ---- cache dir (identical convention to the runtime bindings) ----
if [ -n "${XDG_CACHE_HOME:-}" ]; then
base_cache="$XDG_CACHE_HOME"
elif [ "$os" = macos ]; then
base_cache="$HOME/Library/Caches"
elif [ "$os" = windows ]; then
base_cache="${LOCALAPPDATA:-$HOME/AppData/Local}"
else
base_cache="$HOME/.cache"
fi
cache_dir="$base_cache/selaenium/$TAG"
# The bare filename the binding loaders/linkers look for.
case "$os" in
windows) libname="selenium_core.dll" ;;
macos) libname="libselenium_core.dylib" ;;
*) libname="libselenium_core.so" ;;
esac
dest="$cache_dir/$libname"
if [ "$path_only" = 1 ]; then
echo "$dest"
exit 0
fi
# ---- helpers ----
have() { command -v "$1" >/dev/null 2>&1; }
fetch_to() { # url dest
if have curl; then curl -fsSL -o "$2" "$1"
elif have wget; then wget -q -O "$2" "$1"
else echo "fetch-engine: need curl or wget" >&2; exit 1
fi
}
sha256_of() { # path -> hex on stdout (empty if no tool)
if have sha256sum; then sha256sum "$1" | awk '{print $1}'
elif have shasum; then shasum -a 256 "$1" | awk '{print $1}'
else echo ""
fi
}
# published sidecar hex ("" if unavailable)
want=""
sidecar_tmp="$(mktemp)"
if fetch_to "${BASE}/${TAG}/${asset}.sha256" "$sidecar_tmp" 2>/dev/null; then
want="$(awk '{print $1; exit}' "$sidecar_tmp")"
fi
rm -f "$sidecar_tmp"
# idempotent: present + checksum-matching copy is a no-op
if [ "${FORCE:-0}" != 1 ] && [ -f "$dest" ]; then
if [ -z "$want" ] || [ "$(sha256_of "$dest")" = "$want" ]; then
echo "fetch-engine: already cached: $dest" >&2
echo "$dest"
exit 0
fi
fi
mkdir -p "$cache_dir"
echo "fetch-engine: downloading $asset ($TAG) ..." >&2
tmp="$dest.$$.part"
fetch_to "${BASE}/${TAG}/${asset}" "$tmp"
if [ -n "$want" ]; then
got="$(sha256_of "$tmp")"
if [ -n "$got" ] && [ "$got" != "$want" ]; then
rm -f "$tmp"
echo "fetch-engine: checksum mismatch for $asset: expected $want, got $got" >&2
exit 1
fi
fi
mv -f "$tmp" "$dest" # atomic within the cache dir
echo "fetch-engine: engine ready at $dest" >&2
echo "fetch-engine: now build normally — the link-time build scripts search this cache." >&2
echo "$dest"