Skip to content

Commit

Permalink
feat: validate cached node version (gjaldon#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigatim committed Aug 26, 2023
1 parent be5e4bd commit d994540
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export_config_vars
export_mix_env

cached_node=$cache_dir/node-v$node_version-linux-x64.tar.gz
cached_sha=$cache_dir/SHA256SUM-node-v$node_version

head "Installing binaries"
cleanup_cache
Expand Down
16 changes: 13 additions & 3 deletions lib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ resolve_node() {
node_sha=$(curl --silent --get --retry 5 --retry-max-time 15 $sha_url | grep -E "node-v${number}-linux-x64.tar.gz" | awk '{print $1}')
}

# fails if node tar is missing, sha file is missing, or sha doesn't match
validate_cached_node() {
if sha256sum -c $cached_sha; then
download_complete=true
fi
}

download_node() {
local download_complete=false
local code=""

if [ -f ${cached_node} ]; then
validate_cached_node
if $download_complete; then
info "Using cached node ${node_version}..."
download_complete=true
else

# three attempts to download the file successfully
Expand All @@ -74,7 +81,10 @@ download_node() {
# validate download if we have a SHA256 checksum for the version
if [ ! -z "$node_sha" ]; then
echo "Validating node $number (${node_sha})..."
if echo "$node_sha ${cached_node}" | sha256sum -c -; then
echo "$node_sha ${cached_node}" > $cached_sha

validate_cached_node
if $download_complete; then
echo "Download complete"
download_complete=true
break
Expand Down

0 comments on commit d994540

Please sign in to comment.