Skip to content

Instantly share code, notes, and snippets.

@luckman212
Last active February 15, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckman212/f58329c5c0e98d38154bcab910783f30 to your computer and use it in GitHub Desktop.
Save luckman212/f58329c5c0e98d38154bcab910783f30 to your computer and use it in GitHub Desktop.
simple shell script to test system patches at the console
#!/bin/sh
c='https://github.com/pfsense/pfsense/commit'
retval=0
if [ "$1" = "-r" ]; then
verb='reverted'
shift
else
verb='applied'
fi
if [ -z "$1" ]; then
echo "specify a hash from github commits: ${c}s"
exit
fi
mkdir /tmp/patches 2>/dev/null
rm /tmp/patches/*.patch 2>/dev/null
if ! fetch --quiet --output=/tmp/patches/ "$c/$1.patch"; then
echo "error fetching commit $1"
exit 1
fi
s=$(/usr/bin/sed -En 's/^Subject: \[PATCH\] (.*)$/\1/p' </tmp/patches/$1.patch)
if [ "$verb" = "reverted" ]; then
if ! /usr/bin/patch --directory=/ -f -p2 -i /tmp/patches/$1.patch --quiet --check --reverse --ignore-whitespace; then
retval=1
fi
else
if ! /usr/bin/patch --directory=/ -t -p2 -i /tmp/patches/$1.patch --quiet --check --forward --ignore-whitespace; then
retval=1
fi
fi
echo
echo " commit: $c/$1"
echo " subject: $s"
if [ "$retval" -ne 0 ]; then
echo " result: patch can NOT be cleanly $verb"
else
echo " result: patch CAN be cleanly $verb"
fi
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment