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 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 09:12:21 -05:00
parent f352ae44e1
commit 034b035a91

66
sync.sh
View File

@@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
# Note: This is kind of AI slop and needs to be more carefully reviewed.
set -eu set -eu
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -25,50 +23,66 @@ pnpm_checksum_var="pnpm_checksum_${platform}"
pnpm_binary_url="${!pnpm_binary_var}" pnpm_binary_url="${!pnpm_binary_var}"
pnpm_checksum="${!pnpm_checksum_var}" pnpm_checksum="${!pnpm_checksum_var}"
# Set up paths for shims to use cache_dir="$HOME/.cache/diachron/v1/binaries"
nodejs_dist_dir="diachron/binaries/$nodejs_dirname" local_dir="$DIR/diachron/binaries"
nodejs_bin_dir="$nodejs_dist_dir/bin" mkdir -p "$cache_dir" "$local_dir"
# Ensure correct node version is installed # read_checksum_file <path>
node_installed_checksum_file="$DIR/diachron/binaries/.node.checksum" # Prints the contents of a checksum file, or empty string
node_installed_checksum="" # if the file does not exist.
if [ -f "$node_installed_checksum_file" ]; then read_checksum_file() {
node_installed_checksum=$(cat "$node_installed_checksum_file") if [ -f "$1" ]; then
fi 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..." 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" curl -fsSL "$nodejs_binary" -o "$node_archive"
echo "Verifying checksum..." echo "Verifying checksum..."
echo "$nodejs_checksum $node_archive" | sha256_check echo "$nodejs_checksum $node_archive" | sha256_check
echo "Extracting Node.js..." 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" rm "$node_archive"
echo "$nodejs_checksum" >"$node_installed_checksum_file" echo "$nodejs_checksum" >"$cache_dir/.node.checksum"
fi fi
# Ensure correct pnpm version is installed # Copy Node.js into the working directory if needed
pnpm_binary="$DIR/diachron/binaries/pnpm" local_node_checksum=$(read_checksum_file "$local_dir/.node.checksum")
pnpm_installed_checksum_file="$DIR/diachron/binaries/.pnpm.checksum" if [ "$local_node_checksum" != "$nodejs_checksum" ]; then
pnpm_installed_checksum="" echo "Installing Node.js into project..."
if [ -f "$pnpm_installed_checksum_file" ]; then rm -rf "${local_dir:?}/$nodejs_dirname"
pnpm_installed_checksum=$(cat "$pnpm_installed_checksum_file") cp -R "$cache_dir/$nodejs_dirname" "$local_dir/$nodejs_dirname"
echo "$nodejs_checksum" >"$local_dir/.node.checksum"
fi 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..." 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 "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 fi
# Get golang binaries in place # Get golang binaries in place