From 034b035a91e33d8878fa223bef2ac030286c9c3c Mon Sep 17 00:00:00 2001 From: Michael Wolf Date: Sat, 7 Feb 2026 09:12:21 -0500 Subject: [PATCH] Cache downloaded binaries in ~/.cache/diachron/v1/binaries Downloads Node.js and pnpm to a shared cache directory, then copies into the project tree. Repeated project bootstraps skip the network entirely if the cache is warm. Co-Authored-By: Claude Opus 4.6 --- sync.sh | 66 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/sync.sh b/sync.sh index 8719815..a7e6dfe 100755 --- a/sync.sh +++ b/sync.sh @@ -1,7 +1,5 @@ #!/bin/bash -# Note: This is kind of AI slop and needs to be more carefully reviewed. - set -eu DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -25,50 +23,66 @@ pnpm_checksum_var="pnpm_checksum_${platform}" pnpm_binary_url="${!pnpm_binary_var}" pnpm_checksum="${!pnpm_checksum_var}" -# Set up paths for shims to use -nodejs_dist_dir="diachron/binaries/$nodejs_dirname" -nodejs_bin_dir="$nodejs_dist_dir/bin" +cache_dir="$HOME/.cache/diachron/v1/binaries" +local_dir="$DIR/diachron/binaries" +mkdir -p "$cache_dir" "$local_dir" -# Ensure correct node version is installed -node_installed_checksum_file="$DIR/diachron/binaries/.node.checksum" -node_installed_checksum="" -if [ -f "$node_installed_checksum_file" ]; then - node_installed_checksum=$(cat "$node_installed_checksum_file") -fi +# read_checksum_file +# Prints the contents of a checksum file, or empty string +# if the file does not exist. +read_checksum_file() { + if [ -f "$1" ]; then + cat "$1" + fi +} -if [ "$node_installed_checksum" != "$nodejs_checksum" ]; then +# Ensure Node.js is in the cache +cached_node_checksum=$(read_checksum_file "$cache_dir/.node.checksum") +if [ "$cached_node_checksum" != "$nodejs_checksum" ]; then echo "Downloading Node.js for $platform..." - node_archive="$DIR/diachron/downloads/node.tar.xz" + node_archive="$cache_dir/node.tar.xz" curl -fsSL "$nodejs_binary" -o "$node_archive" echo "Verifying checksum..." echo "$nodejs_checksum $node_archive" | sha256_check echo "Extracting Node.js..." - tar -xf "$node_archive" -C "$DIR/diachron/binaries" + rm -rf "${cache_dir:?}/$nodejs_dirname" + tar -xf "$node_archive" -C "$cache_dir" rm "$node_archive" - echo "$nodejs_checksum" >"$node_installed_checksum_file" + echo "$nodejs_checksum" >"$cache_dir/.node.checksum" fi -# Ensure correct pnpm version is installed -pnpm_binary="$DIR/diachron/binaries/pnpm" -pnpm_installed_checksum_file="$DIR/diachron/binaries/.pnpm.checksum" -pnpm_installed_checksum="" -if [ -f "$pnpm_installed_checksum_file" ]; then - pnpm_installed_checksum=$(cat "$pnpm_installed_checksum_file") +# Copy Node.js into the working directory if needed +local_node_checksum=$(read_checksum_file "$local_dir/.node.checksum") +if [ "$local_node_checksum" != "$nodejs_checksum" ]; then + echo "Installing Node.js into project..." + rm -rf "${local_dir:?}/$nodejs_dirname" + cp -R "$cache_dir/$nodejs_dirname" "$local_dir/$nodejs_dirname" + echo "$nodejs_checksum" >"$local_dir/.node.checksum" fi -if [ "$pnpm_installed_checksum" != "$pnpm_checksum" ]; then +# Ensure pnpm is in the cache +cached_pnpm_checksum=$(read_checksum_file "$cache_dir/.pnpm.checksum") +if [ "$cached_pnpm_checksum" != "$pnpm_checksum" ]; then echo "Downloading pnpm for $platform..." - curl -fsSL "$pnpm_binary_url" -o "$pnpm_binary" + curl -fsSL "$pnpm_binary_url" -o "$cache_dir/pnpm" echo "Verifying checksum..." - echo "$pnpm_checksum $pnpm_binary" | sha256_check + echo "$pnpm_checksum $cache_dir/pnpm" | sha256_check - chmod +x "$pnpm_binary" + chmod +x "$cache_dir/pnpm" - echo "$pnpm_checksum" >"$pnpm_installed_checksum_file" + echo "$pnpm_checksum" >"$cache_dir/.pnpm.checksum" +fi + +# Copy pnpm into the working directory if needed +local_pnpm_checksum=$(read_checksum_file "$local_dir/.pnpm.checksum") +if [ "$local_pnpm_checksum" != "$pnpm_checksum" ]; then + echo "Installing pnpm into project..." + cp "$cache_dir/pnpm" "$local_dir/pnpm" + echo "$pnpm_checksum" >"$local_dir/.pnpm.checksum" fi # Get golang binaries in place