okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
be885026f
main
1#!/usr/bin/env bash 2# Fetch and verify the private Node runtime the desktop bundle ships. 3# 4# The App Host is an ordinary Node program, and the packaging requirement is that an end user 5# supplies no runtime of their own. The desktop bundle therefore carries a pinned standalone Node 6# beside the host. 7# 8# It is NOT committed. It is a ~117 MB platform binary: committing it would bloat every clone, it 9# cannot be reviewed in a diff, and it is not source. This script is the reproducible substitute — 10# it downloads the official build for the target and refuses to install anything whose SHA-256 does 11# not match the recorded digest. 12# 13# Usage: 14# apps/desktop/scripts/fetch-node.sh # host platform 15# apps/desktop/scripts/fetch-node.sh --target linux-x64 16# apps/desktop/scripts/fetch-node.sh --check # verify what is already installed 17# 18# The Node version must satisfy the App Host's own `engines.node` (>= 24.12.0). 19set -euo pipefail 20 21NODE_VERSION =" ${ STRATA_NODE_VERSION :-24.12.0} " 22HERE =" $( cd " $( dirname " ${ BASH_SOURCE [0]} " ) " && pwd ) " 23DEST =" $ HERE /../src-tauri/resources/node" 24 25# Published SHA-256 of each official nodejs.org archive, recorded so a tampered or truncated 26# download is refused rather than shipped. Add a row when bumping the version. 27# Taken from nodejs.org's own SHASUMS256.txt for v24.12.0, which is published over HTTPS beside 28# the archives. Recorded here so the fetch is verified against a value that does not come from the 29# same response as the payload. 30digest_for () { 31case " $ 1 " in 32 darwin-arm64)echo "319f221adc5e44ff0ed57e8a441b2284f02b8dc6fc87b8eb92a6a93643fd8080" ;; 33 linux-x64)echo "6159227e0af7d7c3c6bb2fa900452b04a6cb8841a702a79acc613209d70b04d0" ;; 34 linux-arm64)echo "9b2a2eeb98a8eb37361224e2a1d060300ad2dd143af58dfdb16de785df0f1228" ;; 35 win-x64)echo "9c125f61ae947b52e779095830f9cac267846a043ef7192183c84016aaad2812" ;; 36 *)echo "" ;; 37esac 38} 39 40target () { 41if [" ${ 1 :-} " ="--target" ];then echo " ${ 2 :?--target needs a value} " ;return ;fi 42case " $( uname -s ) - $( uname -m ) " in 43 Darwin-arm64)echo darwin-arm64 ;; 44 Linux-x86_64)echo linux-x64 ;; 45 Linux-aarch64)echo linux-arm64 ;; 46 MINGW*| MSYS*| CYGWIN*)echo win-x64 ;; 47 *)echo "unsupported host: $( uname -s ) - $( uname -m ) " >&2;exit 2 ;; 48esac 49} 50 51TARGET =" $( target " $ @" ) " 52EXE ="node" 53case " $ TARGET " in win-*)EXE ="node.exe" ;;esac 54INSTALLED =" $ DEST / $ EXE " 55 56if [" ${ 1 :-} " ="--check" ];then 57if [ ! -x" $ INSTALLED " ];then echo "fetch-node: not installed at $ INSTALLED " >&2;exit 1;fi 58got =" $( " $ INSTALLED " --version ) " 59echo "fetch-node: $ INSTALLED is $ got " 60case " $ got " in "v $ NODE_VERSION " )exit 0 ;; *)echo "fetch-node: expected v $ NODE_VERSION " >&2;exit 1 ;;esac 61fi 62 63# The official archive for this target. 64case " $ TARGET " in 65 darwin-arm64)ARCHIVE ="node-v $ NODE_VERSION -darwin-arm64.tar.gz" ;; 66 darwin-x64)ARCHIVE ="node-v $ NODE_VERSION -darwin-x64.tar.gz" ;; 67 linux-x64)ARCHIVE ="node-v $ NODE_VERSION -linux-x64.tar.gz" ;; 68 linux-arm64)ARCHIVE ="node-v $ NODE_VERSION -linux-arm64.tar.gz" ;; 69 win-x64)ARCHIVE ="node-v $ NODE_VERSION -win-x64.zip" ;; 70 *)echo "fetch-node: no archive known for $ TARGET " >&2;exit 2 ;; 71esac 72URL ="https://nodejs.org/dist/v $ NODE_VERSION / $ ARCHIVE " 73 74EXPECTED =" $( digest_for " $ TARGET " ) " 75WORK =" $( mktemp -d " ${ TMPDIR :-/tmp} /strata-node.XXXXXX" ) " # GNU mktemp needs the X template; BSD accepts it too 76trap 'rm -rf "$WORK"' EXIT 77 78echo "fetch-node: $ URL " 79curl -fsSL -o " $ WORK / $ ARCHIVE " " $ URL " 80 81ACTUAL =" $( shasum -a 256 " $ WORK / $ ARCHIVE " 2 > /dev/null | cut -d ' ' -f1 || sha256sum " $ WORK / $ ARCHIVE " | cut -d ' ' -f1 ) " 82if [ -n" $ EXPECTED " ];then 83if [" $ ACTUAL " !=" $ EXPECTED " ];then 84echo "fetch-node: REFUSING — $ ARCHIVE hashes $ ACTUAL , expected $ EXPECTED " >&2 85exit 1 86fi 87echo "fetch-node: sha256 verified against the recorded digest" 88else 89# Without a recorded digest the download cannot be authenticated. Say so loudly and keep the 90# computed value so it can be recorded, rather than implying a verification that did not happen. 91echo "fetch-node: WARNING — no recorded digest for $ TARGET ; this download is NOT authenticated." >&2 92echo "fetch-node: computed sha256 $ ACTUAL — record it in $( basename " ${ BASH_SOURCE [0]} " ) to enable verification." >&2 93fi 94 95mkdir -p " $ DEST " 96case " $ ARCHIVE " in 97 *.zip)unzip -q -j " $ WORK / $ ARCHIVE " "node-v $ NODE_VERSION -win-x64/node.exe" -d " $ DEST " ;; 98 *)tar xzf" $ WORK / $ ARCHIVE " -C " $ WORK " 99cp " $ WORK /node-v $ NODE_VERSION - $ TARGET /bin/node" " $ DEST /node" ;; 100esac 101chmod +x" $ DEST / $ EXE " 102 103echo "fetch-node: installed $( " $ DEST / $ EXE " --version ) at $ DEST / $ EXE "