Source mirror · commit 369512f · 2026-10-26 · MIT · canonical repo: gitlab.com/jiapunk/upgrade-airlock
git clone https://upgrade-airlock.pages.dev/source/upgrade-airlock.git
upgrade-airlock / cre / setup.sh
cre/setup.sh85 lines · 5259 bytes
1#!/usr/bin/env bash
2# Installs the CRE toolchain into ./.tools (gitignored) and the workflow's npm deps (veto/).
3# - CRE CLI v1.37.0, SHA-256-pinned per platform; every pin is also checked against the release's checksums.txt:
4# darwin-arm64, darwin-amd64, linux-amd64 and linux-arm64 (glibc >= 2.36, e.g. Ubuntu 24.04; the release's
5# "ldd2-35" build below 2.36). A release archive already in $CRE_ZIP_CACHE is reused if its hash matches.
6# On Linux, curl, unzip and tar must be installed first.
7# - bun 1.4.2: via npm on macOS; on Linux the SHA-256-pinned release zip from GitHub
8# (the "baseline" build on x86-64 CPUs without AVX2).
9# Afterwards: export PATH="$PWD/.tools/bin:$PWD/.tools/node_modules/.bin:$PATH"
10set -euo pipefail
11cd "$(dirname "$0")"
12V=v1.37.0
13REL="https://github.com/smartcontractkit/cre-cli/releases/download/$V"
14ZIP_CACHE="${CRE_ZIP_CACHE:-/nonexistent}" # optional: a folder that already holds the pinned release archive
15mkdir -p .tools/bin .tools/dl
16sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1"; else shasum -a 256 "$1"; fi | awk '{print $1}'; }
17glibc_old() { # true when glibc < 2.36 (the release then ships a separate "_ldd2-35" build)
18 local v; v=$(ldd --version 2>/dev/null | head -n1 | grep -oE '[0-9]+\.[0-9]+' | tail -n1) || return 1
19 [ -n "$v" ] && [ "$(printf '%s\n' "$v" 2.36 | sort -V | head -n1)" = "$v" ] && [ "$v" != 2.36 ]
20}
21
22# GitHub release asset digests of CRE CLI v1.37.0 (identical to the release's checksums.txt)
23case "$(uname -s)-$(uname -m)" in
24 Darwin-arm64) PLAT=darwin_arm64; ASSET=cre_darwin_arm64.zip; PIN=b72d94ca7b3a6a88dbb68205c6a00c2edfb107814fb3dab1c15264aebdb0a7a0 ;;
25 Darwin-x86_64) PLAT=darwin_amd64; ASSET=cre_darwin_amd64.zip; PIN=6f1aa58a375cb8286f253ce867a1fae5d2b9aa0070e0960de4405fdf899d2cfc ;;
26 Linux-x86_64)
27 PLAT=linux_amd64
28 if glibc_old; then ASSET=cre_linux_amd64_ldd2-35.tar.gz; PIN=3c8a73540ed78210ab3ed23d792d8a6bfb4e56deb49bc77d61dfbdd54a147155
29 else ASSET=cre_linux_amd64.tar.gz; PIN=1e660e955be607bca3ae683d5f264bb354252f6af657f0d86e56108438536503; fi ;;
30 Linux-aarch64|Linux-arm64)
31 PLAT=linux_arm64
32 if glibc_old; then ASSET=cre_linux_arm64_ldd2-35.tar.gz; PIN=49c48b60a737ada370fb10213bcb1c364bce71508b4e2557512956a3b4289280
33 else ASSET=cre_linux_arm64.tar.gz; PIN=8454d872386a1633e9f1792d593b13b3f1dd7f8101bc09cbb6f67069edcb5dfa; fi ;;
34 *) echo "no pinned CRE CLI $V for $(uname -s)-$(uname -m); install it by hand" >&2; exit 1 ;;
35esac
36MEMBER="cre_${V}_${PLAT}" # the one file inside every release archive
37
38if [ ! -x .tools/bin/cre ]; then
39 if [ -f "$ZIP_CACHE/$ASSET" ] && [ "$(sha256 "$ZIP_CACHE/$ASSET")" = "$PIN" ]; then
40 cp "$ZIP_CACHE/$ASSET" ".tools/dl/$ASSET"
41 else
42 ( cd .tools/dl
43 curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors -o "$ASSET" "$REL/$ASSET"
44 curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors -o checksums.txt "$REL/checksums.txt"
45 grep -F "$PIN" checksums.txt | grep -q "_${PLAT}" || { echo "release checksums.txt does not list the pinned digest for $ASSET" >&2; exit 1; } )
46 fi
47 got=$(sha256 ".tools/dl/$ASSET")
48 [ "$got" = "$PIN" ] || { echo "checksum mismatch for $ASSET: $got != $PIN" >&2; exit 1; }
49 rm -rf .tools/dl/x && mkdir -p .tools/dl/x
50 case "$ASSET" in
51 *.zip) [ "$(unzip -Z1 ".tools/dl/$ASSET")" = "$MEMBER" ] || { echo "unexpected archive members in $ASSET" >&2; exit 1; }
52 unzip -o -q ".tools/dl/$ASSET" "$MEMBER" -d .tools/dl/x ;;
53 *.tar.gz) [ "$(tar -tzf ".tools/dl/$ASSET")" = "$MEMBER" ] || { echo "unexpected archive members in $ASSET" >&2; exit 1; }
54 tar -xzf ".tools/dl/$ASSET" -C .tools/dl/x "$MEMBER" ;;
55 esac
56 mv ".tools/dl/x/$MEMBER" .tools/bin/cre && rmdir .tools/dl/x
57 chmod +x .tools/bin/cre
58 xattr -c .tools/bin/cre 2>/dev/null || true
59fi
60
61if [ "$(uname -s)" = Darwin ]; then
62 if [ ! -x .tools/node_modules/.bin/bun ]; then
63 ( cd .tools && echo '{"name":"cre-tools","private":true}' > package.json && npm i --no-audit --no-fund bun@1.4.2 >/dev/null )
64 fi
65elif [ ! -x .tools/bin/bun ]; then
66 # bun-v1.4.2 GitHub release asset digests
67 case "$PLAT" in
68 linux_amd64)
69 if grep -qw avx2 /proc/cpuinfo 2>/dev/null; then BZ=bun-linux-x64; BPIN=36368faef7527875d5ffa52e53cd48021741f2a83eb6208a8dd64068d422a913
70 else BZ=bun-linux-x64-baseline; BPIN=c678040f14fe0440eb839d37cbd0ce4c051a32da72806ac97de6a6aab6bf728f; fi ;;
71 linux_arm64) BZ=bun-linux-aarch64; BPIN=54328bbc2d9c8e0c9f892c544d66c57a83b84139e34909e5ee81758f1ac8fda7 ;;
72 esac
73 curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors -o ".tools/dl/$BZ.zip" "https://github.com/oven-sh/bun/releases/download/bun-v1.4.2/$BZ.zip"
74 got=$(sha256 ".tools/dl/$BZ.zip")
75 [ "$got" = "$BPIN" ] || { echo "checksum mismatch for $BZ.zip: $got != $BPIN" >&2; exit 1; }
76 rm -rf ".tools/dl/$BZ" && unzip -o -q ".tools/dl/$BZ.zip" "$BZ/bun" -d .tools/dl
77 mv ".tools/dl/$BZ/bun" .tools/bin/bun && rmdir ".tools/dl/$BZ"
78 chmod +x .tools/bin/bun && ln -sf bun .tools/bin/bunx
79fi
80
81export PATH="$PWD/.tools/bin:$PWD/.tools/node_modules/.bin:$PATH"
82cre version
83echo "bun $(bun --version)"
84( cd veto && bun install )
85echo "ok. Now run: export PATH=\"$PWD/.tools/bin:$PWD/.tools/node_modules/.bin:\$PATH\""