Skip to content

Commit

Permalink
pulled from 00341-deterministic-image
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Oct 11, 2024
1 parent 68ef0de commit a3d6dcf
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions resources/extract-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# This script fetch the build.zip file and checksum file from builds.hedera.com and then extract it into HapiApp2 directory
# Usage extract-platform <release-version>
# e.g. extract-platform v0.42.5
set -o pipefail

readonly tag="${1}"
if [ -z "${tag}" ]; then
if [[ -z "${tag}" ]]; then
echo "Release tag is required (e.g. v0.42.5)";
exit 1
fi
Expand All @@ -17,23 +18,31 @@ readonly BUILD_ZIP_FILE="${HEDERA_USER_HOME_DIR}/build-${tag}.zip"
readonly BUILD_ZIP_URL="${HEDERA_BUILDS_URL}/node/software/${RELEASE_DIR}/build-${tag}.zip"
readonly CHECKSUM_FILE="${HEDERA_USER_HOME_DIR}/build-${tag}.sha384"
readonly CHECKSUM_URL="${HEDERA_BUILDS_URL}/node/software/${RELEASE_DIR}/build-${tag}.sha384"
readonly LOG_FILE="${HAPI_DIR}/output/extract-platform.log"
echo "extract-platform.sh: begin................................" | tee -a ${LOG_FILE}

# download
echo "Downloading ${BUILD_ZIP_URL}"
[ -f "${BUILD_ZIP_FILE}" ] || curl -sSf "${BUILD_ZIP_URL}" -o "${BUILD_ZIP_FILE}"
[ $? == 0 ] || exit 1
echo "Downloading ${CHECKSUM_URL}"
[ -f "${CHECKSUM_FILE}" ] || curl -sSf "${CHECKSUM_URL}" -o "${CHECKSUM_FILE}"
[ $? == 0 ] || exit 1
readonly sum="$(openssl dgst -sha384 "${BUILD_ZIP_FILE}" | awk '{print $2}')"
readonly expected_sum="$(awk '{print $1}' < "${CHECKSUM_FILE}")"
if [ "${sum}" != "${expected_sum}" ]; then
echo "SHA sum of ${BUILD_ZIP_FILE} does not match. Aborting."
echo "Downloading ${BUILD_ZIP_URL}" | tee -a ${LOG_FILE}
[[ -f "${BUILD_ZIP_FILE}" ]] || curl -sSf "${BUILD_ZIP_URL}" -o "${BUILD_ZIP_FILE}" | tee -a ${LOG_FILE}
[[ $? -ne 0 ]] && exit 1
echo "Downloading ${CHECKSUM_URL}" | tee -a ${LOG_FILE}
[[ -f "${CHECKSUM_FILE}" ]] || curl -sSf "${CHECKSUM_URL}" -o "${CHECKSUM_FILE}" | tee -a ${LOG_FILE}
[[ $? -ne 0 ]] && exit 1
cd ${HEDERA_USER_HOME_DIR}
sha384sum -c ${CHECKSUM_FILE} | tee -a ${LOG_FILE}

Check warning on line 32 in resources/extract-platform.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

resources/extract-platform.sh#L32

Double quote to prevent globbing and word splitting.
if [[ $? -ne 0 ]]; then
echo "SHA sum of ${BUILD_ZIP_FILE} does not match. Aborting." | tee -a ${LOG_FILE}
exit 1
fi

# extract
echo "Extracting ${BUILD_ZIP_FILE}"
[[ -d "${HAPI_DIR}" ]] || mkdir -p "${HAPI_DIR}"
cd "${HAPI_DIR}" && jar xvf "${BUILD_ZIP_FILE}"
[ $? == 0 ] || exit 1
echo "Extracting ${BUILD_ZIP_FILE}" | tee -a ${LOG_FILE}
[[ -d "${HAPI_DIR}" ]] || mkdir -p "${HAPI_DIR}" | tee -a ${LOG_FILE}
echo "HAPI_DIR=${HAPI_DIR}" | tee -a ${LOG_FILE}
cd ${HAPI_DIR}
pwd | tee -a ${LOG_FILE}
ls -al | tee -a ${LOG_FILE}
jar xvf "${BUILD_ZIP_FILE}" | tee -a ${LOG_FILE}
[[ $? -ne 0 ]] && echo "Failure occurred during decompress" && exit 1
echo "................................end: extract-platform.sh" | tee -a ${LOG_FILE}
exit 0

0 comments on commit a3d6dcf

Please sign in to comment.