4 # Copyright (C) 2007, 2008 by Raphael Geissert <atomo64@gmail.com>
6 # This file is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This file is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this file If not, see <http://www.gnu.org/licenses/>.
19 # On Debian systems, the complete text of the GNU General
20 # Public License 3 can be found in '/usr/share/common-licenses/GPL-3'.
23 PROGNAME=$(basename "$0")
27 "Usage: $PROGNAME [options] FILE.diff.gz
29 --help Show this message
30 --version Show version and copyright information
31 debian/control must exist on the current path for this script to work
32 If debian/patches exists and is a directory, patches are extracted there,
33 otherwise they are extracted under debian/ (unless the environment variable
34 DEB_PATCHES is defined and points to a valid directory, in which case
35 patches are extracted there)."
40 "This is $PROGNAME, from the Debian devscripts package, version ###VERSION###
41 This code is copyright 2007, 2008 by Raphael Geissert, all rights reserved.
42 This program comes with ABSOLUTELY NO WARRANTY.
43 You are free to redistribute this code under the terms of the
44 GNU General Public License, version 3 or later."
48 --help) usage; exit 0 ;;
49 --version) version; exit 0 ;;
52 if ! which lsdiff >/dev/null 2>&1; then
53 echo "lsdiff was not found in \$PATH, package patchutils probably not installed!"
59 if [ ! -f "$diffgz" ]; then
60 [ -z "$diffgz" ] && diffgz="an unspecified .diff.gz"
61 echo "Couldn't find $diffgz, aborting!"
65 if [ -x /usr/bin/dh_testdir ]; then
66 /usr/bin/dh_testdir || exit 1
68 [ ! -f debian/control ] && echo "Couldn't find debian/control!" && exit 1
71 if [ -z "$DEB_PATCHES" ] || [ ! -d "$DEB_PATCHES" ]; then
73 [ -d debian/patches ] && DEB_PATCHES=debian/patches
75 DEB_PATCHES="$(readlink -f "$DEB_PATCHES")"
78 echo "Patches will be extracted under $DEB_PATCHES/"
80 FILES=$(zcat "$diffgz" | lsdiff --strip 1 | egrep -v ^debian/) || \
81 echo "$(basename "$diffgz") doesn't contain any patch outside debian/"
83 for file in $FILES; do
84 [ ! -z "$file" ] || continue
85 echo -n "Extracting $file..."
86 newFileName="$DEB_PATCHES/$(echo "$file" | sed 's#/#___#g').patch"
87 zcat "$diffgz" | filterdiff -i "$file" -p1 > "$newFileName"