|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (C) 2026 The Falco Authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 7 | +# in compliance with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software distributed under the License |
| 12 | +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | +# or implied. See the License for the specific language governing permissions and limitations under |
| 14 | +# the License. |
| 15 | +# |
| 16 | +# Update the version and recompute the SHA256 checksum in the cmake module for falcosecurity/libs or the driver. |
| 17 | +# |
| 18 | +# Usage: |
| 19 | +# ./update-deps-version driver <version> |
| 20 | +# ./update-deps-version libs <version> |
| 21 | +# |
| 22 | +# <version> can be a commit hash, tag, or branch name. |
| 23 | + |
| 24 | +set -euo pipefail |
| 25 | + |
| 26 | +REPO_ROOT="$(git rev-parse --show-toplevel)" |
| 27 | + |
| 28 | +usage() { |
| 29 | + echo "Usage: $(basename "$0") {driver|libs} <version>" >&2 |
| 30 | + exit 1 |
| 31 | +} |
| 32 | + |
| 33 | +# Stream a URL directly into sha256sum and print the hash. |
| 34 | +sha256_of_url() { |
| 35 | + local url="$1" |
| 36 | + echo "Computing SHA256 for ${url} ..." >&2 |
| 37 | + if command -v curl &>/dev/null; then |
| 38 | + curl -fsSL --retry 3 "${url}" | sha256sum | awk '{print $1}' |
| 39 | + elif command -v wget &>/dev/null; then |
| 40 | + wget -q --tries=3 -O - "${url}" | sha256sum | awk '{print $1}' |
| 41 | + else |
| 42 | + echo "Error: neither curl nor wget found" >&2 |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +[[ $# -ne 2 ]] && usage |
| 48 | +SUBCMD="$1" |
| 49 | +VERSION="$2" |
| 50 | + |
| 51 | +case "${SUBCMD}" in |
| 52 | +driver) |
| 53 | + CMAKE_FILE="${REPO_ROOT}/cmake/modules/driver.cmake" |
| 54 | + REPO="$(grep -oP 'set\(DRIVER_REPO\s+"\K[^"]+' "${CMAKE_FILE}")" |
| 55 | + VERSION_VAR="DRIVER_VERSION" |
| 56 | + CHECKSUM_VAR="DRIVER_CHECKSUM" |
| 57 | + ;; |
| 58 | +libs) |
| 59 | + CMAKE_FILE="${REPO_ROOT}/cmake/modules/falcosecurity-libs.cmake" |
| 60 | + REPO="$(grep -oP 'set\(FALCOSECURITY_LIBS_REPO\s+"\K[^"]+' "${CMAKE_FILE}")" |
| 61 | + VERSION_VAR="FALCOSECURITY_LIBS_VERSION" |
| 62 | + CHECKSUM_VAR="FALCOSECURITY_LIBS_CHECKSUM" |
| 63 | + ;; |
| 64 | +*) |
| 65 | + usage |
| 66 | + ;; |
| 67 | +esac |
| 68 | + |
| 69 | +echo "Repo: ${REPO}, Version: ${VERSION}" |
| 70 | + |
| 71 | +SHA256="$(sha256_of_url "https://github.com/${REPO}/archive/${VERSION}.tar.gz")" |
| 72 | +echo " SHA256: ${SHA256}" |
| 73 | + |
| 74 | +# note: in the following `sed` expressions, `-z` is required in order for `[[:space:]]+` to span across newlines. |
| 75 | + |
| 76 | +# Update the version string in the cmake file, skipping the "0.0.0-local" one by temporarily swapping it with a |
| 77 | +# placeholder and restoring it at the end (note: this is required because `sed` has no negative lookahead`). |
| 78 | +sed -z -i -E \ |
| 79 | + -e 's/"0\.0\.0-local"/PLACEHOLDER/g' \ |
| 80 | + -e "s/(set\(${VERSION_VAR}[[:space:]]+\")[^\"]+(\")/\\1${VERSION}\\2/" \ |
| 81 | + -e 's/PLACEHOLDER/"0.0.0-local"/g' \ |
| 82 | + "${CMAKE_FILE}" |
| 83 | + |
| 84 | +# Update the SHA256 checksum string in the cmake file. |
| 85 | +sed -z -i -E "s/(set\(${CHECKSUM_VAR}[[:space:]]+\"SHA256=)[a-fA-F0-9]+(\")/\\1${SHA256}\\2/" "${CMAKE_FILE}" |
| 86 | + |
| 87 | +echo "Updated ${CMAKE_FILE}" |
0 commit comments