diff options
author | Jan Doskočil <jan.doskocil@nic.cz> | 2024-11-20 16:53:43 +0100 |
---|---|---|
committer | Jan Doskočil <jan.doskocil@nic.cz> | 2024-11-20 19:15:51 +0100 |
commit | 7c0f4390c757a4a2a1514ee1db76f6701791bb68 (patch) | |
tree | 8a1e8189d3fe1e17e7970b9c7722fcf7e69fb7b5 | |
parent | knot-exporter: fix zone-status parsing (diff) | |
download | knot-7c0f4390c757a4a2a1514ee1db76f6701791bb68.tar.xz knot-7c0f4390c757a4a2a1514ee1db76f6701791bb68.zip |
scripts: update_ngtcp2.sh for semi-automatic embedded libngtcp2 updates
-rwxr-xr-x | scripts/update_ngtcp2.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/update_ngtcp2.sh b/scripts/update_ngtcp2.sh new file mode 100755 index 000000000..ee2324cd8 --- /dev/null +++ b/scripts/update_ngtcp2.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -ueo pipefail + +ROOT_PATH="$(dirname "$(realpath "$0")")/../src/contrib/libngtcp2/ngtcp2" +NGTCP2_GIT="https://github.com/ngtcp2/ngtcp2" + +if [ $# != 1 ]; then + printf 'expected single arg - git tag name to which to upgrade\n' + exit 1 +fi + +clonedir="$(mktemp -d)" +trap 'rm -rf "$clonedir"; printf "error encountered - aborting\n"' ERR + +cur_version=v"$(sed -En 's/^.*NGTCP2_VERSION[^"]*"([0-9.]+)"/\1/p' "${ROOT_PATH}/version.h")" + +git clone --branch="$1" "$NGTCP2_GIT" "${clonedir}/ngtcp2" 2>/dev/null + +cd "${clonedir}/ngtcp2" +git diff --name-only --diff-filter=A "$cur_version" "$1" | xargs -r realpath >../added +git diff --name-only --diff-filter=D "$cur_version" "$1" | xargs -r realpath >../deleted +git diff --name-only --diff-filter=ad "$cur_version" "$1" | xargs -r realpath >../changed + +# generate new version.h +autoreconf -if >/dev/null 2>&1 +./configure --enable-lib-only --with-gnutls >/dev/null 2>&1 +cp ./lib/includes/ngtcp2/version.h "${ROOT_PATH}" + +cd "$ROOT_PATH" + +# delete files deleted in new version +while IFS=$'\n' read -r line; do + find . -type f -name "$(basename "$line")" | xargs -r rm +done <"${clonedir}/deleted" + +# update changed files +find . -type f | while IFS=$'\n' read -r line; do + base="$(basename "$line")" + match="$(grep -m1 "$base" "${clonedir}/changed" || true)" + if [ -n "$match" ]; then + cp "$match" "$line" + fi +done + +# ngtcp2_crypto.h is the only non-unique filename, so we deal with it separately +# ugly - I'm aware ;p +cp "${clonedir}/ngtcp2/lib/ngtcp2_crypto.h" ./lib/ngtcp2_crypto.h +cp "${clonedir}/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h" ./ngtcp2_crypto.h + +newfiles="$(wc -l "${clonedir}/added" | cut -d' ' -f1)" +if [ "$newfiles" -gt 0 ]; then + printf "%s new file(s) were added between %s and %s; add these manually if desired:\n" \ + "$newfiles" "$cur_version" "$1" + cut -d'/' -f'5-' "${clonedir}/added" | xargs -r printf "\t%s\n" +fi + +rm -rf "$clonedir" |