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.
This commit is contained in:
Eberhard Beilharz 2025-07-10 14:23:57 +02:00
parent bc7499a3e1
commit f3206d58e4
No known key found for this signature in database
GPG key ID: E9140597606020D3

View file

@ -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
}