Skip to content

Instantly share code, notes, and snippets.

@denvazh
Created June 25, 2017 11:43
Show Gist options
  • Save denvazh/aa67d75ea1b0595e16b824b3f317bdb4 to your computer and use it in GitHub Desktop.
Save denvazh/aa67d75ea1b0595e16b824b3f317bdb4 to your computer and use it in GitHub Desktop.
Bash wrapper to conditionally apply patch
#!/usr/bin/env bash
# first argument is a patch file
if [ $# -eq 0 ]; then
echo "No arguments supplied. Aborting."
exit 0
fi
PATCH_FILE=$1
# try to apply patch and see if it was already applied
STAT=$(patch -p0 -N --dry-run --silent < "${PATCH_FILE}" 2>&1>/dev/null; echo $?)
if [ ${STAT} -eq 0 ]; then
# actually apply patch if it wasn't applied yet
patch -p0 -N < "${PATCH_FILE}"
else
echo "Patch was already applied: ${PATCH_FILE}"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment