From b46aad6df449445a9fc4aa7b32bd40005438e3f7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:18:05 +0200 Subject: Adding upstream version 2.9.5. Signed-off-by: Daniel Baumann --- scripts/make-releases-json | 103 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 scripts/make-releases-json (limited to 'scripts/make-releases-json') diff --git a/scripts/make-releases-json b/scripts/make-releases-json new file mode 100755 index 0000000..ba05665 --- /dev/null +++ b/scripts/make-releases-json @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# +# Scan a branch directory for source tarballs and rebuild the releases.json +# file for that branch. md5 and sha256 are added if present. The highest +# numbered version is referenced as the latest release. +# +# Usage: $0 [-b branch] [-o outfile] /path/to/download/branch +# + +USAGE="Usage: ${0##*/} [-b branch] [-o outfile] DIR" +OUTPUT= +BRANCH= +DIR= + +die() { + [ "$#" -eq 0 ] || echo "$*" >&2 + exit 1 +} + +err() { + echo "$*" >&2 +} + +quit() { + [ "$#" -eq 0 -o -n "$QUIET" ] || echo "$*" + exit 0 +} + +emit_json() { + printf '{\n "branch": "%s",\n' ${BRANCH} + latest="" + for file in $(find "$DIR/src" -name 'haproxy-[0-9]*.gz' -printf "%P\n" |grep -v '[0-9]-patches*' | sort -rV ); do + rel="${file##*haproxy-}" + rel="${rel%%.tar.*}" + if [ -z "$latest" ]; then + latest="$rel"; + printf ' "latest_release": "%s",\n' ${latest} + printf ' "releases": {\n' + else + printf ",\n" + fi + printf ' "%s": {\n' ${rel} + printf ' "file": "%s"' ${file} + if [ -s "$DIR/src/$file.md5" ]; then + printf ',\n "md5": "%s"' $(awk '{print $1}' "$DIR/src/$file.md5") + fi + if [ -s "$DIR/src/$file.sha256" ]; then + printf ',\n "sha256": "%s"' $(awk '{print $1}' "$DIR/src/$file.sha256") + fi + printf '\n }' + done + + if [ -n "$latest" ]; then + printf "\n }" ## "releases" + fi + + printf '\n}\n' +} + + +### main + +while [ -n "$1" -a -z "${1##-*}" ]; do + case "$1" in + -b) BRANCH="$2" ; shift 2 ;; + -o) OUTPUT="$2" ; shift 2 ;; + -h|--help) quit "$USAGE" ;; + *) die "$USAGE" ;; + esac +done + +if [ $# -ne 1 ]; then + die "$USAGE" +fi + +DIR="$1" ; shift +if [ -z "$DIR" ]; then + die "Missing download directory name." +fi + +if [ ! -d "$DIR/." ]; then + die "Download directory doesn't exist : $DIR" +fi + +if [ ! -d "$DIR/src" ]; then + die "Download directory must contain 'src' : $DIR" +fi + +if [ -z "$BRANCH" ]; then + BRANCH=${DIR##*/} + if [ -n "${BRANCH//[0-9.]}" ]; then + die "Couldn't determine branch number from dir name: $BRANCH" + fi +fi + +# echo "debug: DIR=$DIR BRANCH=$BRANCH" +if [ -n "$OUTPUT" ]; then + emit_json > "$OUTPUT.tmp" + mv -f "$OUTPUT.tmp" "$OUTPUT" + rm -f "$OUTPUT.tmp" +else + emit_json +fi -- cgit v1.2.3