WordPress.org

Make WordPress Core

Ticket #9724: wppatch

File wppatch, 1.1 KB (added by Denis-de-Bernardy, 5 years ago)
Line 
1#!/bin/sh
2#
3# Automatically download and apply a patch from core.trac.wordpress.org
4#
5# Usage:
6#
7#   wp_patch http://core.trac.wordpress.org/attachment/ticket/132/132.diff
8#   wp_patch 123                        -- http://core.trac.wordpress.org/attachment/ticket/132/132.diff
9#   wp_patch 123.2.diff         -- http://core.trac.wordpress.org/attachment/ticket/132/132.2.diff
10#   wp_patch 123 456.diff       -- http://core.trac.wordpress.org/attachment/ticket/132/456.diff
11#
12
13if [ ! -f wp-config.php ];
14then
15        echo 'Invalid WP install'
16        exit 1
17fi
18
19case $#
20in
21        1 )
22                ticket=$1
23                if [ $ticket != ${ticket%/*} ];
24                then
25                        ticket=${ticket##*/ticket/}
26                        patch=${ticket##*/}
27                        ticket=${ticket%%/*}
28                elif [ $ticket != ${ticket%%.*} ];
29                then
30                        patch=$ticket
31                        ticket=${ticket%%.*}
32                else
33                        patch=$ticket.diff
34                fi
35                ;;
36        2 )
37                ticket=$1
38                patch=$2
39                ;;
40        * )
41                echo 'Invalid number of args'
42                exit 1
43esac
44
45curl -s --connect-timeout 3 http://core.trac.wordpress.org/raw-attachment/ticket/$ticket/$patch -o $PWD/$patch
46
47if [ $? -ne 0 ];
48then
49        echo 'Error downloading patch'
50        exit 1
51fi
52
53patch -p0 -i $PWD/$patch && rm $PWD/$patch