Skip to content

Instantly share code, notes, and snippets.

@nadavkav
Last active March 26, 2017 15:28
Show Gist options
  • Save nadavkav/de1adae835eb7310b339eff642a1cc41 to your computer and use it in GitHub Desktop.
Save nadavkav/de1adae835eb7310b339eff642a1cc41 to your computer and use it in GitHub Desktop.
get security patch for moodle (bash script)
#!/bin/bash
#
# Example:
# ./get-security-patch-for-moodle.sh MOODLE_31_STABLE MDL-57596 --dry-run
#
SECURITY_FIX=$(curl -k "https://git.moodle.org/gw?p=moodle.git&a=search&h=$1&st=commit&s=$2")
SF_COMMIT=$(echo $SECURITY_FIX | grep -oP '<td class="link"><a href="(.*)">commit<\/a>' | grep -oP 'f=\"(.*)\"' | cut -d\" -f2)
SF_COMMIT_URL=$(echo "https://git.moodle.org".$SF_COMMIT | sed "s/a=commit/a=patch/")
curl -k $SF_COMMIT_URL > "security_fix_$2.patch"
patch -p1 $3 < "security_fix_$2.patch"
# Uncomment the following line to delete the redundant security patch file.
#rf -rf "security_fix_$2.patch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment