summaryrefslogtreecommitdiff
path: root/pkgkde-debs2symbols
blob: dcc95c083c614b965a7d13589bf4fb5e38fa0eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/sh

# Copyright (C) 2010 Modestas Vainius <modax@debian.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

set -e

include_common() {
    local _dirname
    _dirname="`dirname "$0"`"
    if [ -n "$_dirname" ] && [ -f "$_dirname/datalib/shell_common" ]; then
        . "$_dirname/datalib/shell_common"
    else
        . /usr/share/pkg-kde-tools/lib/shell_common
    fi
}

usage() {
    echo "$PROGNAME: usage:" "$0" "[ -i symbol_file ]" "[ -d debdir ]" "[ -s symboldir ]" package version "[ download_url ]" >&2
}


download() {
    local debdir
    debdir="$1"
    # Download debs
    info "Downloading packages from $URL ..."
    wget -e robots=off --timestamping --no-directories --directory-prefix="$debdir" \
         --recursive --level=1 --no-parent --accept "$DEB_WILDCARD" "$URL"
}

extract_deb() {
    local deb tmpdir outdir
    local arch package version outfile

    deb="$1"
    tmpdir="$2"
    outdir="$3"

    info2 "Extracting `basename $deb` ..."
    dpkg-deb -e "$deb" "$tmpdir/DEBIAN"
    dpkg-deb -x "$deb" "$tmpdir"
}

dump_symbols() {
    local tmpdir outdir reffile
    local arch package version outfile outpatch

    tmpdir="$1"
    outdir="$2"
    reffile="$3"

    # Collection information about package
    package=$(sed -n '/^Package:/ {s/[^:]\+:[[:space:]]*\(.\+\)/\1/; p; q}' "$tmpdir/DEBIAN/control")
    version=$(sed -n '/^Version:/ {s/[^:]\+:[[:space:]]*\(.\+\)/\1/; p; q}' "$tmpdir/DEBIAN/control")
    arch=$(sed -n '/^Architecture:/ {s/[^:]\+:[[:space:]]*\(.\+\)/\1/; p; q}' "$tmpdir/DEBIAN/control")

    if [ "$arch" = "all" ]; then
        error "it does not make sense to process arch:all package ($deb)"
    fi

    if [ -n "$reffile" ]; then
	outfile="${package}_${arch}"
	patchfile="$outdir/$outfile.patch"
	info2 "[$arch] Dumping patch & symbol file as $outfile/$outfile.{patch,symbols} ..."
	pkgkde-gensymbols "-p$package" "-P$tmpdir" "-v$version" "-a$arch" \
	    -c1 "-I$reffile" -O"$outdir/$outfile.symbols" > "$patchfile" || true
	test -s "$patchfile" || rm -f "$patchfile"
    else
	outfile="${package}_${arch}"
	info2 "[$arch] Dumping symbol file as $outfile ..."
	pkgkde-gensymbols "-p$package" "-P$tmpdir" "-v$version" "-a$arch" \
	    -c0 -q -I/dev/null "-O$outdir/$outfile"
    fi
}

include_common

# Process options
REFFILE=""
DEBDIR=""
SYMBOLDIR=""
while getopts "i:d:s:" name; do
    case "$name" in
	i)  REFFILE="$OPTARG" ;;
	d)  DEBDIR="$OPTARG" ;;
	s)  SYMBOLDIR="$OPTARG" ;;
	\?)  usage; exit 2 ;;
    esac
done

shift `expr $OPTIND - 1`

PACKAGE="$1"
VERSION="$2"
URL="$3"

DEB_WILDCARD="${PACKAGE}_${VERSION}_*.deb"

if [ -z "$PACKAGE" ] || [ -z "$VERSION" ]; then
    usage
    exit 2
fi

# Create directories to store downloaded debs and symbol files
debdir="${DEBDIR:-${PACKAGE}_${VERSION}_debs}"
symboldir="${SYMBOLDIR:-${PACKAGE}_${VERSION}_symbols}"

info "Selected directory for packages (*.deb):" "$debdir/"
if [ -n "$URL" ]; then
    if [ "${URL#http://}" != "$URL" ] || [ "${URL#ftp://}" != "$URL" ]; then
        if [ ! -d "$debdir" ]; then
            mkdir "$debdir"
        fi
        download "$debdir"
    else
        error "only http:// and ftp:// download URLs are supported"
    fi
fi

# Extract and process debs
c=0
if [ -d "$debdir" ]; then
    tmpdir=`mktemp -d --tmpdir=. tmpdeb.XXXXXX`
    rmdir "$tmpdir"
    if [ ! -d "$symboldir" ]; then
	mkdir "$symboldir"
    fi

    info "Selected temporary directory:" "$tmpdir/"
    info "Selected directory for symbol files:" "$symboldir/"
    for deb in `ls -1 "$debdir"/$DEB_WILDCARD 2>/dev/null | sort`; do
        mkdir "$tmpdir"
        extract_deb "$deb" "$tmpdir" "$symboldir"
        dump_symbols "$tmpdir" "$symboldir" "$REFFILE"
        rm -rf "$tmpdir"
        c=$(($c+1))
    done
fi

if [ $c -eq 0 ]; then
    error "no '$DEB_WILDCARD' binary packages found in $debdir/"
fi

info "$c arch specific symbol files dumped successfully to $symboldir/"