#!/bin/bash set -eu DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=diachron/versions source "$DIR/diachron/versions" # shellcheck source=diachron/platform source "$DIR/diachron/platform" # Get platform-specific variables nodejs_binary_var="nodejs_binary_${platform}" nodejs_checksum_var="nodejs_checksum_${platform}" nodejs_dirname_var="nodejs_dirname_${platform}" nodejs_binary="${!nodejs_binary_var}" nodejs_checksum="${!nodejs_checksum_var}" nodejs_dirname="${!nodejs_dirname_var}" pnpm_binary_var="pnpm_binary_${platform}" pnpm_checksum_var="pnpm_checksum_${platform}" pnpm_binary_url="${!pnpm_binary_var}" pnpm_checksum="${!pnpm_checksum_var}" cache_dir="$HOME/.cache/diachron/v1/binaries" local_dir="$DIR/diachron/binaries" mkdir -p "$cache_dir" "$local_dir" # 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 } # 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="$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..." rm -rf "${cache_dir:?}/$nodejs_dirname" tar -xf "$node_archive" -C "$cache_dir" rm "$node_archive" echo "$nodejs_checksum" >"$cache_dir/.node.checksum" fi # 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 # 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 "$cache_dir/pnpm" echo "Verifying checksum..." echo "$pnpm_checksum $cache_dir/pnpm" | sha256_check chmod +x "$cache_dir/pnpm" 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 cd "$DIR/master" go build cd "$DIR/logger" go build # Update framework code cd "$DIR/backend" ../cmd pnpm install