From f3206d58e4ce175ce0b2dc056eff011bee2ccc6a Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 10 Jul 2025 14:23:57 +0200 Subject: [PATCH] maint(common): add support for inline file exclusions to `add_zip_files` This change adds support for the `-xr!wildcard` parameter to the `add_zip_files` function, e.g. `-xr!build.sh` will exclude all `build.sh` files from the archive. This is an alternative to adding a file list. --- resources/build/zip.inc.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/build/zip.inc.sh b/resources/build/zip.inc.sh index 1f80a71edb..a84d8e940e 100644 --- a/resources/build/zip.inc.sh +++ b/resources/build/zip.inc.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellscript shell=bash # # This script contains zip and unzip (TODO) utilities to function for all environments. # unzip is available in all environments @@ -27,6 +27,7 @@ function add_zip_files() { local ZIP_FLAGS=() local SEVENZ_FLAGS=('a') # 7z requires a command local INCLUDE=() + local EXCLUDE_FILE while [[ $# -gt 0 ]] ; do case "$1" in -r) @@ -41,6 +42,14 @@ function add_zip_files() { SEVENZ_FLAGS+=($1) shift ;; + -xr!*) + # Recursively exclude the file after -xr! from the archive + EXCLUDE_FILE=$(mktemp) + find . -name ${1##-xr!} > "${EXCLUDE_FILE}" + ZIP_FLAGS+=("-x@${EXCLUDE_FILE}") + SEVENZ_FLAGS+=($1) + shift + ;; # Zip flags that have a corresponding 7z flag -q) @@ -51,14 +60,14 @@ function add_zip_files() { shift ;; -[0123456789]) - # Compression level where + # Compression level where # -0 indicates no compression # -1 indicates low compression (fastest) # -9 indicates ultra compression (slowest) ZIP_FLAGS+=($1) if [[ $1 =~ -([0-9]) ]]; then SEVENZ_FLAGS+=("-mx${BASH_REMATCH[1]}") - fi + fi shift; ;; @@ -102,4 +111,7 @@ function add_zip_files() { # builder_echo_debug "${COMPRESS_CMD} ${SEVENZ_FLAGS[@]} ${ZIP_FLAGS[@]} ${ZIP_FILE} ${INCLUDE[@]}" "${COMPRESS_CMD}" ${SEVENZ_FLAGS[@]} ${ZIP_FLAGS[@]} ${ZIP_FILE} ${INCLUDE[@]} + if [[ -n "${EXCLUDE_FILE:-}" ]]; then + rm "${EXCLUDE_FILE}" + fi }