~ubuntu-core-dev/pkgbinarymangler/ubuntu

1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
1
#!/bin/bash -e
2
67 by Martin Pitt
Allow changing the configuration file directory path with
3
CONFFILE=${PKGBINARYMANGLER_CONF_DIR:-/etc/pkgbinarymangler}/striptranslations.conf
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
4
66 by Martin Pitt
Allow changing the path of "common" with $PKGBINARYMANGLER_COMMON_PATH.
5
. ${PKGBINARYMANGLER_COMMON_PATH:-/usr/share/pkgbinarymangler}/common
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
6
95 by Martin Pitt
Move identification/version string from dpkg-deb to pkgstriptranslations,
7
echo "INFO: pkgstriptranslations version #VERSION#"
8
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
9
# ignore language packs
10
if echo "$srcname" | grep -q ^language-pack; then
11
    echo "pkgstriptranslations: building language pack, doing nothing"
12
    exit 0
13
fi
14
2 by Martin Pitt
* pkg{maintainermangler,striptranslations}.1: Document NO_PKG_MANGLE
15
# ignore backports
16
if dpkg-parsechangelog | grep -q 'Distribution:.*backport'; then
17
    echo "pkgstriptranslations: building backport, doing nothing"
18
    exit 0
19
fi
20
196 by Martin Pitt
pkgstriptranslations: Force stripping and translation tarball build if
21
# first, check if the package explicitly requests stripping
22
if grep -q 'X[[:alpha:]]*-Ubuntu-Use-Langpack: yes' debian/control; then
23
    dostrip=1
63 by Martin Pitt
Replace hardcoded "/CurrentlyBuilding" path with a $BUILDINFO variable set
24
# check whether build info is present; so we can check the component
196 by Martin Pitt
pkgstriptranslations: Force stripping and translation tarball build if
25
elif [ -f "$BUILDINFO" ]; then
57 by Martin Pitt
pkgstriptranslations: Run if we are building in an OEM PPA. If the built
26
    unset dostrip
27
63 by Martin Pitt
Replace hardcoded "/CurrentlyBuilding" path with a $BUILDINFO variable set
28
    if grep -qs '^Purpose: PPA' "$BUILDINFO"; then
77 by Martin Pitt
pkgstriptranslations: Allow overwriting apt config dir with PKGBINARYMANGLER_APT_CONF_DIR
29
        if grep -q '/oem-archive' ${PKGBINARYMANGLER_APT_CONF_DIR:-/etc/apt}/sources.list; then
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
30
            echo "INFO: Running pkgstriptranslations for OEM build"
31
            oemstrip=1
87 by Martin Pitt
add OEM project blacklist which should not get stripped
32
33
	    # check blacklist
88 by Martin Pitt
move OEM blacklist into conffile, and remove OEM project names
34
	    readctrl "$CONFFILE" oem_blacklist
35
	    for project in $RET; do
87 by Martin Pitt
add OEM project blacklist which should not get stripped
36
		if grep -q "oem-archive/$project" ${PKGBINARYMANGLER_APT_CONF_DIR:-/etc/apt}/sources.list; then
37
		    echo "INFO: Disabling pkgstriptranslations for blacklisted OEM project"
38
		    exit 0
39
		fi
40
	    done
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
41
        else
42
            echo "INFO: Disabling pkgstriptranslations for PPA build"
43
            exit 0
44
        fi
57 by Martin Pitt
pkgstriptranslations: Run if we are building in an OEM PPA. If the built
45
    else
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
46
        # we have a PRIMARY build, check component
47
        readctrl "$CONFFILE" "components"
48
        stripcomponents="$RET"
63 by Martin Pitt
Replace hardcoded "/CurrentlyBuilding" path with a $BUILDINFO variable set
49
        readctrl "$BUILDINFO" "Component"
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
50
        for c in $stripcomponents; do
51
            if [ $c = "$RET" ]; then dostrip=1; fi
52
        done
56 by Martin Pitt
Move "PPA" check from dpkg-deb to pkgmaintainermangler and
53
    fi
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
54
else
55
    dostrip=1
56
fi
57
7 by Martin Pitt
The "Make doko love me again" release.
58
# determine tarball name
59
readctrl "$CONFFILE" "posuffix"
60
posuffix=$RET
34 by Martin Pitt
* pkgstriptranslations: Extract GNOME help translations into a new tarball
61
arch=$(dpkg --print-architecture)
7 by Martin Pitt
The "Make doko love me again" release.
62
[ "$posuffix" ] || posuffix=translations
63
tarball=${srcname}_${version}_${arch}_$posuffix.tar.gz
34 by Martin Pitt
* pkgstriptranslations: Extract GNOME help translations into a new tarball
64
tarball_static=${srcname}_${version}_static_${posuffix}.tar.gz
7 by Martin Pitt
The "Make doko love me again" release.
65
25 by Martin Pitt
* pkgstriptranslations: Use a lockfile to ensure that only one
66
# make sure that only one pkgstriptranslations runs at a time, so that we don't
67
# corrupt the tarball
68
lockfile-create --retry 20 "../$tarball"
69
70
tmp=$(mktemp -t -d pkgstriptranslations.XXXXXX)
71
trap "lockfile-remove '../$tarball'; rm -rf $tmp" 0 1 2 3 7 10 13 15
72
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
73
# process every directory that looks like a package, remove all
74
# usr/share/locale/*.mo files, and copy them into the tarball
75
for PKGCTL in $(find -regex '\./debian/.*/DEBIAN/control$'); do
76
    # skip installer udebs
77
    readctrl $PKGCTL Section
78
    if [ "$RET" = debian-installer ]; then
79
        continue
80
    fi
81
82
    readctrl $PKGCTL Package
83
    PKGNAME=$RET
84
    PKGDIR=$(dirname $(dirname $PKGCTL))
85
    echo "pkgstriptranslations: processing control file: $PKGCTL, package $PKGNAME, directory $PKGDIR"
86
57 by Martin Pitt
pkgstriptranslations: Run if we are building in an OEM PPA. If the built
87
    # special-case OEM builds here: strip packages if we are building a package
88
    # for an OEM archive which would be stripped in Ubuntu
89
    if [ -n "$oemstrip" ]; then
199 by Martin Pitt
pkgstriptranslations: Run apt-cache under env -u LD_PRELOAD to avoid
90
        if env -u LD_PRELOAD apt-cache madison "$PKGNAME" | egrep -v '://[^ ]*ppa' | grep -q '/ubuntu.*/main .*Packages'; then
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
91
            echo "INFO (OEM mode): Package is in Ubuntu main, enabling stripping of *.mo"
92
            dostrip=1
93
        else
94
            echo "INFO (OEM mode): Package is not in Ubuntu main, not stripping"
95
            unset dostrip
96
        fi
57 by Martin Pitt
pkgstriptranslations: Run if we are building in an OEM PPA. If the built
97
    fi
98
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
99
    # read blacklist file and test all regexps
100
    unset blacklisted
101
    if [ -f /etc/pkgbinarymangler/striptranslations.blacklist ]; then
102
        while read regex; do
103
            if echo "$PKGNAME" | egrep -xq "$regex"; then
104
                blacklisted=1
105
                echo "pkgstriptranslations: $PKGNAME is blacklisted, not stripping"
106
                break
107
            fi
108
        done < /etc/pkgbinarymangler/striptranslations.blacklist
109
    fi
110
29 by Martin Pitt
* pkgstriptranslations: Remove translations from .desktop files if they have
111
    # strip translations from .desktop files if they have a gettext domain (since
112
    # inline translations are preferred)
113
    for desktop in `find "$PKGDIR" -type f -name "*.desktop"`; do
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
114
        if grep -q '^X-.*-Gettext-Domain=' "$desktop"; then
115
            echo "$desktop: stripping translations"
116
            sed -ri '/^(Name|GenericName|Comment)\[/d' "$desktop";
117
            # adapt md5sums file
118
            if [ -f $PKGDIR/DEBIAN/md5sums ]; then
119
                P=${desktop#$PKGDIR}
120
                P=${P#/}
121
                (cd "$PKGDIR"; sed -i "s#^[[:alnum:]]\+  $P\$#`md5sum $P`#" DEBIAN/md5sums)
122
            fi
123
        else
124
            echo "$desktop: does not have gettext domain, not stripping"
125
        fi
29 by Martin Pitt
* pkgstriptranslations: Remove translations from .desktop files if they have
126
    done
127
51 by Martin Pitt
pkgstriptranslations: Work on all binary packages, not just the first one.
128
    # save/strip GNOME help files
129
    if [ "$dostrip" -a -z "$blacklisted" -a -d "$PKGDIR/usr/share/gnome/help" ]; then
179 by Martin Pitt
pkgstriptranslations: Symlink identical GNOME help files (which often
130
	r=`pwd`
131
        pushd "$PKGDIR/usr/share/gnome/help" >/dev/null
132
	# replace help files which are copies of the C version with a symlink
133
	# to the C version
134
        find -type f ! -wholename '*/C/*' | while read f; do
135
	    f=${f#./}
136
137
	    # construct relative path to C file
138
	    numslash=`echo "$f" | tr -cd / | wc -c`
139
	    dirqueue=./${f#*\/*\/*} # strip off initial pkgname/locale prefix
140
	    back=""
141
	    dir=""
142
	    while [ $numslash -gt 1 ]; do
143
		back="../$back"
144
		dir=$dir${dirqueue%%/*}/
145
		dirqueue=${dirqueue#*/}
146
		numslash=$((numslash-1))
147
	    done
148
	    dir=${dir#./} # beautify
149
	    c_file="${back}C/$dir$(basename "$f")"
150
151
	    # if C file exists and is identical, symlink it
152
	    fdir=`dirname "$f"`
153
	    if [ -e "$fdir/$c_file" ] && zcmp "$f" "$fdir/$c_file" >/dev/null; then
154
		echo "symlinking duplicate GNOME help file $f to $c_file"
155
		rm "$f"
156
		ln -s "$c_file" "$f"
157
		[ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" $r/DEBIAN/md5sums
158
	    fi
159
	done
160
	popd >/dev/null
161
162
	# extract the files which are actually translated and replace with
163
	# links to the langpack
34 by Martin Pitt
* pkgstriptranslations: Extract GNOME help translations into a new tarball
164
        pushd "$PKGDIR" >/dev/null
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
165
        (find usr/share/gnome/help -type f ! -wholename '*/C/*'; [ ! -d usr/share/omf ] || find usr/share/omf -type f -name '*.omf' ! -name '*-C.omf') | while read f; do
35 by Martin Pitt
* pkgstriptranslations:
166
	    install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"
167
	    rm "$f"
168
	    dest=${f/gnome\/help/gnome\/help-langpack}
169
	    dest=${dest/share\/omf/share\/omf-langpack}
170
	    ln -s "/$dest" "$f"
171
	    [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums
172
	done
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
173
	popd >/dev/null
34 by Martin Pitt
* pkgstriptranslations: Extract GNOME help translations into a new tarball
174
    fi
175
29 by Martin Pitt
* pkgstriptranslations: Remove translations from .desktop files if they have
176
    [ -d "$PKGDIR/usr/share/locale" ] || {
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
177
	echo "pkgstriptranslations: $PKGNAME does not contain translations, skipping"
178
	continue
29 by Martin Pitt
* pkgstriptranslations: Remove translations from .desktop files if they have
179
    }
180
7 by Martin Pitt
The "Make doko love me again" release.
181
    # save *.mo files if we don't have a tarball yet
182
    if [ ! -f "../$tarball" ]; then
183
        pushd "$PKGDIR" >/dev/null
184
        find -type f -name "*.mo" -exec install -D -m 644 '{}' "$tmp/$PKGNAME/{}" \;
185
        popd >/dev/null
186
    fi
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
187
188
    if [ "$dostrip" -a -z "$blacklisted" ]; then
189
        find "$PKGDIR/usr/share/locale" -type f -name "*.mo" -exec rm '{}' \;
190
        find "$PKGDIR/usr/share/locale" -depth -type d -empty -exec rmdir '{}' \; || true
191
192
        # adapt md5sums file
193
        if [ -f $PKGDIR/DEBIAN/md5sums ]; then
194
            sed -i '/usr\/share\/locale\/.*\.mo$/d' $PKGDIR/DEBIAN/md5sums
195
        fi
85 by Martin Pitt
pkgstriptranslations: Adapt Installed-Size: header in control file if we
196
197
	# adapt Installed-Size
99 by Martin Pitt
pkgstriptranslations: Fix another typo. Bah.
198
	is=`cd $PKGDIR; du -k -s .|cut -f1`
85 by Martin Pitt
pkgstriptranslations: Adapt Installed-Size: header in control file if we
199
	sed -i "s/^Installed-Size:.*$/Installed-Size: $is/" $PKGDIR/DEBIAN/control
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
200
    fi
201
done
202
203
# check for empty files, as they indicate a package bug
8 by Martin Pitt
pkgstriptranslations: Do not complain about empty .po/.pot files in hidden
204
EMPTYFILES="`find -mindepth 1 -name '.*' -prune -o \( -name "*.po" -o -name "*.pot" \) -empty -print`"
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
205
if [ -n "$EMPTYFILES" ]; then
206
    cat <<EOF
207
pkgstriptranslations: The following PO/POT files are empty. This is known to
208
cause trouble in the translation importer and generally indicates a package
209
bug:
210
211
$EMPTYFILES
212
EOF
213
fi
214
194 by Martin Pitt
* test/run: Drop separate check_translation_tarball() test, and integrate it
215
# create tarball if there are files and we stripped the package
216
if [ "$dostrip" -a -z "$blacklisted" ]; then
217
    if [ ! -f "../$tarball" ]; then
218
	# copy po/pot files
219
	find \( -name "*.po" -o -name "*.pot" -o -name "*.ts" \) ! -wholename '*/.pc/*' ! -empty -exec install -D -m 644 '{}' "$tmp/source/{}" \;
220
221
	# grab sdf files from OO.o
222
	if [ "$srcname" = "openoffice.org" ]; then
223
	    find debian/ -name "*.sdf" -exec install -D -m 644 '{}' "$tmp/source/{}" \;
224
	fi
225
226
	# grab XPI files for Mozilla-ish packages
227
	if [ -d debian/lp-export-xpis ]; then
228
	    install -d $tmp/source/
229
	    cp -a debian/lp-export-xpis $tmp/source/
230
	fi
231
232
	if [ "$(ls -I _static $tmp | wc -l)" -gt 0 ]; then
233
	    echo -n "pkgstriptranslations: preparing translation tarball $tarball..."
234
	    pwd=$(pwd)
235
	    pushd $tmp > /dev/null
236
	    tar c --exclude=_static . | gzip -9 > "$pwd/../$tarball"
237
	    numfiles=$(find -type f | wc -l)
238
	    popd > /dev/null
239
	    echo "done ($numfiles files)"
240
	    dpkg-distaddfile "$tarball" raw-translations -
241
	else
242
	    echo "pkgstriptranslations: no translation files, not creating tarball"
243
	fi
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
244
    else
194 by Martin Pitt
* test/run: Drop separate check_translation_tarball() test, and integrate it
245
	echo "pkgstriptranslations: tarball already exists"
1 by Adam Conrad
* Rename source package to pkgbinarymangler, providing a transitional
246
    fi
247
fi
248
34 by Martin Pitt
* pkgstriptranslations: Extract GNOME help translations into a new tarball
249
# create static tarball if there are files
51 by Martin Pitt
pkgstriptranslations: Work on all binary packages, not just the first one.
250
if [ -d "$tmp/_static" ]; then
251
54 by Martin Pitt
pkgstriptranslations: Fix dpkg-distaddfile call for static tarballs (previously called in wrong directory)
252
    if [ -f "../$tarball_static" ]; then
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
253
        echo -n "pkgstriptranslations: updating static translation tarball $tarball_static..."
254
        tar -C "$tmp/_static" -xzf "../$tarball_static"
51 by Martin Pitt
pkgstriptranslations: Work on all binary packages, not just the first one.
255
    else
61 by Martin Pitt
Apply a consistent indentation to all source files (4 spaces, expand
256
        echo -n "pkgstriptranslations: preparing static translation tarball $tarball_static..."
257
        dpkg-distaddfile "$tarball_static" raw-translations-static -
51 by Martin Pitt
pkgstriptranslations: Work on all binary packages, not just the first one.
258
    fi
259
54 by Martin Pitt
pkgstriptranslations: Fix dpkg-distaddfile call for static tarballs (previously called in wrong directory)
260
    pwd=$(pwd)
261
    pushd $tmp/_static > /dev/null
34 by Martin Pitt
* pkgstriptranslations: Extract GNOME help translations into a new tarball
262
    tar c . | gzip -9 > "$pwd/../$tarball_static"
263
    numfiles=$(find -type f | wc -l)
264
    popd > /dev/null
265
    echo "done ($numfiles files)"
266
fi