|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +BASE_URL="https://binaries.soliditylang.org/bin" |
| 6 | +REPO_ROOT="$(dirname "$0")/.." |
| 7 | +LIST_FILE=$(mktemp -t solc-bin-list-XXXXXX.json) |
| 8 | + |
| 9 | +function fail() { |
| 10 | + echo -e "ERROR: $*" >&2 |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
| 14 | +function check_release_version() { |
| 15 | + local current_version="$1" |
| 16 | + |
| 17 | + curl --silent --fail "${BASE_URL}/list.json" -o "$LIST_FILE" |
| 18 | + [[ ! -f $LIST_FILE ]] && fail "Download of release list failed:\n [url]: ${BASE_URL}/list.json" |
| 19 | + |
| 20 | + # Retrieve the latest released version |
| 21 | + latest_version_short=$(jq --raw-output ".latestRelease" "$LIST_FILE") |
| 22 | + latest_version_long=$(jq --raw-output ".releases | .[\"${latest_version_short}\"]" "$LIST_FILE" | sed --regexp-extended --quiet 's/^soljson-v(.*).js$/\1/p') |
| 23 | + |
| 24 | + # Check if current version is the latest release |
| 25 | + if [[ $current_version != "$latest_version_long" ]]; then |
| 26 | + fail "Version is not the latest release:\n [current]: ${current_version}\n [latest]: ${latest_version_short}" |
| 27 | + fi |
| 28 | + |
| 29 | + current_sha=$(shasum --binary --algorithm 256 ./soljson.js | awk '{ print $1 }') |
| 30 | + release_sha=$(jq --raw-output ".builds[] | select(.longVersion == \"${latest_version_long}\") | .sha256" "$LIST_FILE" | sed 's/^0x//') |
| 31 | + |
| 32 | + # Check if sha matches |
| 33 | + if [[ $current_sha != "$release_sha" ]]; then |
| 34 | + fail "Checksum mismatch.\n [current]: ${current_sha}\n [release]: ${release_sha}" |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +( |
| 39 | + cd "$REPO_ROOT" |
| 40 | + |
| 41 | + current_version=$(node ./dist/solc.js --version | sed --regexp-extended --quiet 's/^(.*).Emscripten.*/\1/p') |
| 42 | + |
| 43 | + # Verify if current version matches the package version. |
| 44 | + # It already exits with an error if the version mismatch |
| 45 | + node ./dist/verifyVersion.js |
| 46 | + |
| 47 | + # Verify if current version is the latest release |
| 48 | + if check_release_version "$current_version"; then |
| 49 | + echo "The currently installed soljson.js binary (${current_version}) matches the latest release available in solc-bin." |
| 50 | + fi |
| 51 | + |
| 52 | + # Cleanup temp files |
| 53 | + rm -f "$LIST_FILE" |
| 54 | +) |
0 commit comments