asterisk/third-party/apply_patches
Sean Bright 9ca24c9c2b apply_patches: Use globbing instead of file/sort.
This accomplishes the same thing as a `find ... | sort` but with the
added benefit of clarity and avoiding a call to a subshell.

Additionally drop the -s option from call to patch as it is not POSIX.
2023-07-07 10:02:18 -06:00

38 lines
884 B
Bash
Executable file

#!/bin/sh
if [ "$1" = "-q" ] ; then
quiet=1
shift
fi
PATCH=${PATCH:-patch}
patchdir=${1:?You must supply a patches directory}
sourcedir=${2?:You must supply a source directory}
if [ ! -d "$patchdir" ] ; then
echo "$patchdir is not a directory" >&2
exit 1
fi
if [ ! -d "$sourcedir" ] ; then
echo "$sourcedir is not a directory" >&2
exit 1
fi
# Patterns used in filename expansion (globs) are sorted according to the
# current locale, so there is no need to do it explicitly.
for patchfile in "$patchdir"/*.patch ; do
# A glob that doesn't match is not replaced, so we handle that here. We
# should only fail this test if there are no patch files.
[ -f "$patchfile" ] || {
echo "No patches in $patchdir" >&2
exit 0
}
[ -z "$quiet" ] && echo "Applying patch $(basename "$patchfile")"
${PATCH} -d "$sourcedir" -p1 -i "$patchfile" >/dev/null || exit 1
done
exit 0