Created
June 25, 2017 11:43
-
-
Save denvazh/aa67d75ea1b0595e16b824b3f317bdb4 to your computer and use it in GitHub Desktop.
Bash wrapper to conditionally apply patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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