~ubuntu-branches/ubuntu/precise/devscripts/precise

« back to all changes in this revision

Viewing changes to scripts/dscextract.sh

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2011-08-23 22:09:52 UTC
  • mfrom: (10.9.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110823220952-xtj02fmmewsa8exr
Tags: 2.11.1ubuntu1
* Merge from Debian unstable; remaining changes:
  - Demote Recommends to Suggests:
    + libcrypt-ssleay-perl: only needed for a corner case (uscan on SSL
      download sites), wasn't installed by default in previous releases
      either, and seems quite dead upstream; universe only.
    + debian-keyring: not useful enough in Ubuntu; universe only.
    + equivs: too much of a hack to install by default; universe only.
    + libyaml-syck-perl: transition-check is fairly Debian-specific.
  - scripts/debchange.{pl,1}:
    + Adjust --security template for Ubuntu.
    + Add -U/--upstream flag that forces original "just increment
      the end" behaviour; Ubuntu is upstream for some pieces of software.
    + Add --distributor= and DEBCHANGE_DISTRIBUTOR to override lsb_release
      output.
    + Default to "oneiric" as distribution.
    + Add "ubuntu1" to version string for new versions, with tweaks for
      special cases.
    + Add -R/--rebuild flag for Ubuntu's no-change rebuilds.
    + Don't use the last distribution in debian/changelog when doing
      "dch -r" on Ubuntu. "Just because it was last uploaded to jaunty
      doesn't mean that's the right thing to do now." Thanks to Colin
      Watson. (LP: #429288)
  - Add test/debchange.pl, test/Makefile: debchange test suite.
  - Rename XS-Vcs-* to XS-Debian-Vcs-*.
* Remove debian-maintainers from Recommends (the key moved to debian-keyring).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
#   dscextract.sh - Extract a single file from a Debian source package
 
4
#   Copyright (C) 2011 Christoph Berg <myon@debian.org>
 
5
#
 
6
#   This program 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 2 of the License, or
 
9
#   (at your option) any later version.
 
10
#
 
11
#   This program 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.
 
15
#
 
16
#   You should have received a copy of the GNU General Public License
 
17
#   along with this program; if not, write to the Free Software
 
18
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
19
 
 
20
set -eu
 
21
 
 
22
die () {
 
23
        echo "$*" >&2
 
24
        exit 2
 
25
}
 
26
 
 
27
FAST=""
 
28
while getopts "f" opt ; do
 
29
        case $opt in
 
30
                f) FAST=yes ;;
 
31
                *) exit 2 ;;
 
32
        esac
 
33
done
 
34
# shift away args
 
35
shift $(($OPTIND - 1))
 
36
 
 
37
[ $# = 2 ] || die "Usage: $(basename $0) <dsc> <file>"
 
38
DSC="$1"
 
39
test -e "$DSC" || die "$DSC not found"
 
40
FILE="$2"
 
41
 
 
42
DSCDIR=$(dirname "$DSC")
 
43
WORKDIR=$(mktemp -d --tmpdir dscextract.XXXXXX)
 
44
trap "rm -rf $WORKDIR" 0 2 3 15
 
45
 
 
46
if DIFFGZ=$(egrep '^ [0-9a-f]{32,64} [0-9]+ [^ ]+\.diff\.(gz|bz2)$' "$DSC") ; then
 
47
        DIFFGZ=$(echo "$DIFFGZ" | cut -d ' ' -f 4 | head -n 1)
 
48
        test -e "$DSCDIR/$DIFFGZ" || die "$DSCDIR/$DIFFGZ: not found"
 
49
        filterdiff -p1 -i "$FILE" -z "$DSCDIR/$DIFFGZ" > "$WORKDIR/patch"
 
50
        if test -s "$WORKDIR/patch" ; then
 
51
                # case 1: file found in .diff.gz
 
52
                if ! grep -q '^@@ -0,0 ' "$WORKDIR/patch" ; then
 
53
                        # case 1a: patch requires original file
 
54
                        ORIGTGZ=$(egrep '^ [0-9a-f]{32,64} [0-9]+ [^ ]+\.orig\.tar\.(gz|bz2)$' "$DSC") || die "no orig.tar.gz found in $DSC"
 
55
                        ORIGTGZ=$(echo "$ORIGTGZ" | cut -d ' ' -f 4 | head -n 1)
 
56
                        case $ORIGTGZ in
 
57
                                *.gz) ZIP=--gzip ;;
 
58
                                *.bz2) ZIP=--bzip2 ;;
 
59
                        esac
 
60
                        test -e "$DSCDIR/$ORIGTGZ" || die "$DSCDIR/$ORIGTGZ not found"
 
61
                        tar --extract --to-stdout --gzip --file "$DSCDIR/$ORIGTGZ" --wildcards "*/$FILE" > "$WORKDIR/output" 2>/dev/null || :
 
62
                        test -s "$WORKDIR/output" || die "$FILE not found in $DSCDIR/$ORIGTGZ, but required by patch"
 
63
                fi
 
64
                patch --silent "$WORKDIR/output" < "$WORKDIR/patch"
 
65
                test -s "$WORKDIR/output" || die "patch $FILE did not produce any output"
 
66
                cat "$WORKDIR/output"
 
67
                exit 0
 
68
        elif [ "$FAST" ] ; then
 
69
                # in fast mode, don't bother looking into .orig.tar.gz
 
70
                exit 1
 
71
        fi
 
72
fi
 
73
 
 
74
if DEBIANTARGZ=$(egrep '^ [0-9a-f]{32,64} [0-9]+ [^ ]+\.debian\.tar\.(gz|bz2)$' "$DSC") ; then
 
75
        case $FILE in
 
76
                debian/*)
 
77
                        DEBIANTARGZ=$(echo "$DEBIANTARGZ" | cut -d ' ' -f 4 | head -n 1)
 
78
                        test -e "$DSCDIR/$DEBIANTARGZ" || die "$DSCDIR/$DEBIANTARGZ not found"
 
79
                        case $DEBIANTARGZ in
 
80
                                *.gz) ZIP=--gzip ;;
 
81
                                *.bz2) ZIP=--bzip2 ;;
 
82
                        esac
 
83
                        tar --extract --to-stdout $ZIP --file "$DSCDIR/$DEBIANTARGZ" "$FILE" > "$WORKDIR/output" 2>/dev/null || :
 
84
                        test -s "$WORKDIR/output" || exit 1
 
85
                        # case 2a: file found in .debian.tar.gz
 
86
                        cat "$WORKDIR/output"
 
87
                        exit 0
 
88
                        # for 3.0 format, no need to look in other places here
 
89
                        ;;
 
90
                *)
 
91
                        ORIGTGZ=$(egrep '^ [0-9a-f]{32,64} [0-9]+ [^ ]+\.orig\.tar\.(gz|bz2)$' "$DSC") || die "no orig.tar.gz found in $DSC"
 
92
                        ORIGTGZ=$(echo "$ORIGTGZ" | cut -d ' ' -f 4 | head -n 1)
 
93
                        test -e "$DSCDIR/$ORIGTGZ" || die "$DSCDIR/$ORIGTGZ not found"
 
94
                        case $ORIGTGZ in
 
95
                                *.gz) ZIP=--gzip ;;
 
96
                                *.bz2) ZIP=--bzip2 ;;
 
97
                        esac
 
98
                        tar --extract --to-stdout $ZIP --file "$DSCDIR/$ORIGTGZ" --wildcards --no-wildcards-match-slash "*/$FILE" > "$WORKDIR/output" 2>/dev/null || :
 
99
                        test -s "$WORKDIR/output" || exit 1
 
100
                        # case 2b: file found in .orig.tar.gz
 
101
                        # TODO: apply patches from debian.tar.gz
 
102
                        cat "$WORKDIR/output"
 
103
                        exit 0
 
104
                        ;;
 
105
        esac
 
106
fi
 
107
 
 
108
if TARGZ=$(egrep '^ [0-9a-f]{32,64} [0-9]+ [^ ]+\.tar\.(gz|bz2)$' "$DSC") ; then
 
109
        TARGZ=$(echo "$TARGZ" | cut -d ' ' -f 4 | head -n 1)
 
110
        test -e "$DSCDIR/$TARGZ" || die "$DSCDIR/$TARGZ not found"
 
111
        case $TARGZ in
 
112
                *.gz) ZIP=--gzip ;;
 
113
                *.bz2) ZIP=--bzip2 ;;
 
114
        esac
 
115
        tar --extract --to-stdout $ZIP --file "$DSCDIR/$TARGZ" --wildcards --no-wildcards-match-slash "*/$FILE" > "$WORKDIR/output" 2>/dev/null || :
 
116
        test -s "$WORKDIR/output" || exit 1
 
117
        # case 3: file found in .tar.gz or .orig.tar.gz
 
118
        cat "$WORKDIR/output"
 
119
        exit 0
 
120
fi
 
121
 
 
122
exit 1