diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /packaging/macos/jhb/usr/bin/run-parts | |
parent | Initial commit. (diff) | |
download | inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'packaging/macos/jhb/usr/bin/run-parts')
-rwxr-xr-x | packaging/macos/jhb/usr/bin/run-parts | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/packaging/macos/jhb/usr/bin/run-parts b/packaging/macos/jhb/usr/bin/run-parts new file mode 100755 index 0000000..ff0470c --- /dev/null +++ b/packaging/macos/jhb/usr/bin/run-parts @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +### description ################################################################ + +# A partial replacement for Debian's "run-parts" tool. Execute files in a +# directory in their lexical order with the specialty of being able to +# use symlinks to create an order without executing the files twice. + +### shellcheck ################################################################# + +# Nothing here. + +### dependencies ############################################################### + +# Nothing here. + +### variables ################################################################## + +# Nothing here. + +### functions ################################################################## + +function main +{ + local mode=$1 + local dir=$2 + + local file_pattern + + if [ -d "$dir" ]; then + # reconstruct to make it proper (e.g. remove superfluous slashes) + dir=$(dirname "$dir")/$(basename "$dir") + else + # split into directory and file + file_pattern=$(basename "$dir") + dir=$(dirname "$dir") + fi + + file_pattern=${file_pattern:-*} # default pattern is "*" + + local linked_files + linked_files=$(find "$dir" -type l -exec readlink {} +) + + for file in "$dir"/$file_pattern; do # requires 'shopt -s nullglob' + # Only process files that have no symlinks (in that same directory) pointing + # at them. + if [[ "$linked_files" != *$(basename "$file")* ]]; then + case "$mode" in + list) + echo "$file" + ;; + run) + $file + ;; + esac + fi + done +} + +### main ####################################################################### + +set -e + +shopt -s nullglob # in case no files are found + +case "$1" in + list) + main "list" "$2" + ;; + *) + main "run" "$1" + ;; +esac |