1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#!/bin/bash
# Copyright 2017 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Script for updating Node binaries.
# 1) Update NODE_VERSION variable below to the desired version.
# 2) Run this script without any flags first to download all the binaries
# locally.
# 3) Authenticate using your @google account by running `gsutil.py config`
# (prerequisite for step #4 below).
# 4) To upload the binaries to the Google Storage bucket, use the
# `--upload` or `-u` flag. This will upload the binaries to
# the Google Storage bucket and update the DEPS file.
# 5) Land a CL with the changes generated by this script.
set -eu
cd "$(dirname "$0")"
BASE_URL="https://nodejs.org/dist"
NODE_VERSION="v22.11.0"
upload=false # Default value
# The script can take a command line flag and check if it is valid.
# If the flag `--upload` | `-u` is passed in, then the script
# uploads the binaries and update the DEPS.
while [[ $# -gt 0 ]]; do
case $1 in
-u|--upload)
upload=true
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
upload_unix(){
local SUFFIX="$1"
local FOLDER="$2"
local UPLOAD_FILE="${FOLDER}/node-${SUFFIX}.tar.gz"
if [[ -e "${UPLOAD_FILE}" ]]; then
if [[ "$SUFFIX" == "darwin-x64" ]]; then
local PATHNAME="src/third_party/node/mac"
fi
if [[ "$SUFFIX" == "darwin-arm64" ]]; then
local PATHNAME="src/third_party/node/mac_arm64"
fi
if [[ "$SUFFIX" == "linux-x64" ]]; then
local PATHNAME="src/third_party/node/linux"
fi
./upload_to_gcs_and_update_deps "${UPLOAD_FILE}" "${PATHNAME}"
echo "DONE uploading ${SUFFIX} binaries and updating DEPS file.."
else
echo "Error: File '${UPLOAD_FILE}' does not exist."
echo "Please run ./update_node_binaries to download binaries locally first."
fi
}
upload_win(){
local FILENAME="node.exe"
local FOLDER="win"
local UPLOAD_FILE="${FOLDER}/${FILENAME}"
if [[ -e "${UPLOAD_FILE}" ]]; then
./upload_to_gcs_and_update_deps "${UPLOAD_FILE}" src/third_party/node/win
echo "DONE uploading Windows binaries and updating DEPS file.."
else
echo "Error: File '$UPLOAD_FILE' does not exist."
echo "Please run ./update_node_binaries to download binaries locally first."
fi
}
download_unix() {
local SUFFIX="$1"
local FOLDER="$2"
local FILENAME="node-${NODE_VERSION}-${SUFFIX}.tar.gz"
local URL="${BASE_URL}/${NODE_VERSION}/${FILENAME}"
rm -f "${FOLDER}/${FILENAME}"
wget -P "${FOLDER}/" "${URL}"
# Check SHASUMS256 of downloaded binary.
local sha256_expected
sha256_expected="$(grep "$FILENAME" SHASUMS256.txt | cut -d ' ' -f1)"
local sha256_actual
sha256_actual="$(sha256sum "${FOLDER}/${FILENAME}" | cut -d ' ' -f1)"
if [ "${sha256_expected}" != "${sha256_actual}" ]; then
echo "SHA256 mismatch. Exiting..."
exit 1
fi
# Unpack temporarily, delete npm, npx, corepack and re-pack.
tar xfz "${FOLDER}/${FILENAME}" -C "${FOLDER}/"
rm "${FOLDER}/${FILENAME}"
rm "${FOLDER}/node-${NODE_VERSION}-${SUFFIX}/bin/corepack"
rm -rf "${FOLDER}/node-${NODE_VERSION}-${SUFFIX}/lib/node_modules/corepack"
rm "${FOLDER}/node-${NODE_VERSION}-${SUFFIX}/bin/npm"
rm -rf "${FOLDER}/node-${NODE_VERSION}-${SUFFIX}/lib/node_modules/npm"
rm "${FOLDER}/node-${NODE_VERSION}-${SUFFIX}/bin/npx"
# Drop the version info from the name, since it is redundant and would make
# rolling new versions more involved.
rm -rf "${FOLDER}/node-${SUFFIX}/"
mv "${FOLDER}/node-${NODE_VERSION}-${SUFFIX}/" "${FOLDER}/node-${SUFFIX}/"
tar cfz "${FOLDER}/node-${SUFFIX}.tar.gz" -C "${FOLDER}" "node-${SUFFIX}/"
}
download_win() {
local FILENAME="node.exe"
local FOLDER="win"
local WINDOWS_URL="${BASE_URL}/${NODE_VERSION}/win-x64/${FILENAME}"
rm -f "${FOLDER}/${FILENAME}"
wget -P "${FOLDER}/" "${WINDOWS_URL}"
# Check SHASUMS256 of downloaded binary.
local sha256_expected
sha256_expected="$(grep "win-x64/$FILENAME" SHASUMS256.txt | cut -d ' ' -f1)"
local sha256_actual
sha256_actual="$(sha256sum "${FOLDER}/${FILENAME}" | cut -d ' ' -f1)"
if [ "${sha256_expected}" != "${sha256_actual}" ]; then
echo "SHA256 mismatch. Exiting..."
exit 1
fi
}
if [[ $upload != true ]]; then
# First download checksum file.
rm -f "SHASUMS256.txt"
wget "https://nodejs.org/dist/${NODE_VERSION}/SHASUMS256.txt"
download_unix "darwin-x64" "mac"
download_unix "darwin-arm64" "mac"
download_unix "linux-x64" "linux"
download_win
echo "To upload the binaries, please run ./update_node_binaries --upload"
else
echo "Uploading to GCS and updating DEPS files..."
upload_unix "darwin-x64" "mac"
upload_unix "darwin-arm64" "mac"
upload_unix "linux-x64" "linux"
upload_win
fi
|