• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# This function logs the archive checksum and, if provided, compares it with
4# the deposited checksum
5#
6# $1 is the package name e.g. 'acorn', 'ada', 'base64' etc. See the file
7# https://github.com/nodejs/node/blob/main/doc/contributing/maintaining/maintaining-dependencies.md
8# for a complete list of package name
9# $2 is the downloaded archive
10# $3 (optional) is the deposited sha256 cheksum. When provided, it is checked
11# against the checksum generated from the archive
12log_and_verify_sha256sum() {
13  package_name="$1"
14  archive="$2"
15  checksum="$3"
16  bsd_formatted_checksum=$(shasum -a 256 --tag "$archive")
17  if [ -z "$3" ]; then
18    echo "$bsd_formatted_checksum"
19  else
20    archive_checksum=$(shasum -a 256 "$archive")
21    if [ "$checksum" = "$archive_checksum" ]; then
22      echo "Valid $package_name checksum"
23      echo "$bsd_formatted_checksum"
24    else
25      echo "ERROR - Invalid $package_name checksum:"
26      echo "deposited: $checksum"
27      echo "generated: $archive_checksum"
28      exit 1
29    fi
30  fi
31}
32