11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci# This function logs the archive checksum and, if provided, compares it with
41cb0ef41Sopenharmony_ci# the deposited checksum
51cb0ef41Sopenharmony_ci#
61cb0ef41Sopenharmony_ci# $1 is the package name e.g. 'acorn', 'ada', 'base64' etc. See the file
71cb0ef41Sopenharmony_ci# https://github.com/nodejs/node/blob/main/doc/contributing/maintaining/maintaining-dependencies.md
81cb0ef41Sopenharmony_ci# for a complete list of package name
91cb0ef41Sopenharmony_ci# $2 is the downloaded archive
101cb0ef41Sopenharmony_ci# $3 (optional) is the deposited sha256 cheksum. When provided, it is checked
111cb0ef41Sopenharmony_ci# against the checksum generated from the archive
121cb0ef41Sopenharmony_cilog_and_verify_sha256sum() {
131cb0ef41Sopenharmony_ci  package_name="$1"
141cb0ef41Sopenharmony_ci  archive="$2"
151cb0ef41Sopenharmony_ci  checksum="$3"
161cb0ef41Sopenharmony_ci  bsd_formatted_checksum=$(shasum -a 256 --tag "$archive")
171cb0ef41Sopenharmony_ci  if [ -z "$3" ]; then
181cb0ef41Sopenharmony_ci    echo "$bsd_formatted_checksum"
191cb0ef41Sopenharmony_ci  else
201cb0ef41Sopenharmony_ci    archive_checksum=$(shasum -a 256 "$archive")
211cb0ef41Sopenharmony_ci    if [ "$checksum" = "$archive_checksum" ]; then
221cb0ef41Sopenharmony_ci      echo "Valid $package_name checksum"
231cb0ef41Sopenharmony_ci      echo "$bsd_formatted_checksum"
241cb0ef41Sopenharmony_ci    else
251cb0ef41Sopenharmony_ci      echo "ERROR - Invalid $package_name checksum:"
261cb0ef41Sopenharmony_ci      echo "deposited: $checksum"
271cb0ef41Sopenharmony_ci      echo "generated: $archive_checksum"
281cb0ef41Sopenharmony_ci      exit 1
291cb0ef41Sopenharmony_ci    fi
301cb0ef41Sopenharmony_ci  fi
311cb0ef41Sopenharmony_ci}
32