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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#!/bin/bash -e
CONFFILE=${PKGBINARYMANGLER_CONF_DIR:-/etc/pkgbinarymangler}/striptranslations.conf
. ${PKGBINARYMANGLER_COMMON_PATH:-/usr/share/pkgbinarymangler}/common
echo "INFO: pkgstriptranslations version #VERSION#"
# ignore language packs
if echo "$srcname" | grep -q ^language-pack; then
echo "pkgstriptranslations: building language pack, doing nothing"
exit 0
fi
# ignore backports
if dpkg-parsechangelog | grep -q 'Distribution:.*backport'; then
echo "pkgstriptranslations: building backport, doing nothing"
exit 0
fi
# first, check if the package explicitly requests stripping
if grep -q 'X[[:alpha:]]*-Ubuntu-Use-Langpack: yes' debian/control; then
dostrip=1
# check whether build info is present; so we can check the component
elif [ -f "$BUILDINFO" ]; then
unset dostrip
if grep -qs '^Purpose: PPA' "$BUILDINFO"; then
if grep -q '/oem-archive' ${PKGBINARYMANGLER_APT_CONF_DIR:-/etc/apt}/sources.list; then
echo "INFO: Running pkgstriptranslations for OEM build"
oemstrip=1
# check blacklist
readctrl "$CONFFILE" oem_blacklist
for project in $RET; do
if grep -q "oem-archive/$project" ${PKGBINARYMANGLER_APT_CONF_DIR:-/etc/apt}/sources.list; then
echo "INFO: Disabling pkgstriptranslations for blacklisted OEM project"
exit 0
fi
done
else
echo "INFO: Disabling pkgstriptranslations for PPA build"
exit 0
fi
else
# we have a PRIMARY build, check component
readctrl "$CONFFILE" "components"
stripcomponents="$RET"
readctrl "$BUILDINFO" "Component"
for c in $stripcomponents; do
if [ $c = "$RET" ]; then dostrip=1; fi
done
fi
else
dostrip=1
fi
# determine tarball name
readctrl "$CONFFILE" "posuffix"
posuffix=$RET
arch=$(dpkg --print-architecture)
[ "$posuffix" ] || posuffix=translations
tarball=${srcname}_${version}_${arch}_$posuffix.tar.gz
tarball_static=${srcname}_${version}_static_${posuffix}.tar.gz
# make sure that only one pkgstriptranslations runs at a time, so that we don't
# corrupt the tarball
lockfile-create --retry 20 "../$tarball"
tmp=$(mktemp -t -d pkgstriptranslations.XXXXXX)
trap "lockfile-remove '../$tarball'; rm -rf $tmp" 0 1 2 3 7 10 13 15
# process every directory that looks like a package, remove all
# usr/share/locale/*.mo files, and copy them into the tarball
for PKGCTL in $(find -regex '\./debian/.*/DEBIAN/control$'); do
# skip installer udebs
readctrl $PKGCTL Section
if [ "$RET" = debian-installer ]; then
continue
fi
readctrl $PKGCTL Package
PKGNAME=$RET
PKGDIR=$(dirname $(dirname $PKGCTL))
echo "pkgstriptranslations: processing control file: $PKGCTL, package $PKGNAME, directory $PKGDIR"
# special-case OEM builds here: strip packages if we are building a package
# for an OEM archive which would be stripped in Ubuntu
if [ -n "$oemstrip" ]; then
if env -u LD_PRELOAD apt-cache madison "$PKGNAME" | egrep -v '://[^ ]*ppa' | grep -q '/ubuntu.*/main .*Packages'; then
echo "INFO (OEM mode): Package is in Ubuntu main, enabling stripping of *.mo"
dostrip=1
else
echo "INFO (OEM mode): Package is not in Ubuntu main, not stripping"
unset dostrip
fi
fi
# read blacklist file and test all regexps
unset blacklisted
if [ -f /etc/pkgbinarymangler/striptranslations.blacklist ]; then
while read regex; do
if echo "$PKGNAME" | egrep -xq "$regex"; then
blacklisted=1
echo "pkgstriptranslations: $PKGNAME is blacklisted, not stripping"
break
fi
done < /etc/pkgbinarymangler/striptranslations.blacklist
fi
# strip translations from .desktop files if they have a gettext domain (since
# inline translations are preferred)
for desktop in `find "$PKGDIR" -type f -name "*.desktop"`; do
if grep -q '^X-.*-Gettext-Domain=' "$desktop"; then
echo "$desktop: stripping translations"
sed -ri '/^(Name|GenericName|Comment)\[/d' "$desktop";
# adapt md5sums file
if [ -f $PKGDIR/DEBIAN/md5sums ]; then
P=${desktop#$PKGDIR}
P=${P#/}
(cd "$PKGDIR"; sed -i "s#^[[:alnum:]]\+ $P\$#`md5sum $P`#" DEBIAN/md5sums)
fi
else
echo "$desktop: does not have gettext domain, not stripping"
fi
done
# save/strip GNOME help files
if [ "$dostrip" -a -z "$blacklisted" -a -d "$PKGDIR/usr/share/gnome/help" ]; then
r=`pwd`
pushd "$PKGDIR/usr/share/gnome/help" >/dev/null
# replace help files which are copies of the C version with a symlink
# to the C version
find -type f ! -wholename '*/C/*' | while read f; do
f=${f#./}
# construct relative path to C file
numslash=`echo "$f" | tr -cd / | wc -c`
dirqueue=./${f#*\/*\/*} # strip off initial pkgname/locale prefix
back=""
dir=""
while [ $numslash -gt 1 ]; do
back="../$back"
dir=$dir${dirqueue%%/*}/
dirqueue=${dirqueue#*/}
numslash=$((numslash-1))
done
dir=${dir#./} # beautify
c_file="${back}C/$dir$(basename "$f")"
# if C file exists and is identical, symlink it
fdir=`dirname "$f"`
if [ -e "$fdir/$c_file" ] && zcmp "$f" "$fdir/$c_file" >/dev/null; then
echo "symlinking duplicate GNOME help file $f to $c_file"
rm "$f"
ln -s "$c_file" "$f"
[ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" $r/DEBIAN/md5sums
fi
done
popd >/dev/null
# extract the files which are actually translated and replace with
# links to the langpack
pushd "$PKGDIR" >/dev/null
(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
install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"
rm "$f"
dest=${f/gnome\/help/gnome\/help-langpack}
dest=${dest/share\/omf/share\/omf-langpack}
ln -s "/$dest" "$f"
[ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums
done
popd >/dev/null
fi
[ -d "$PKGDIR/usr/share/locale" ] || {
echo "pkgstriptranslations: $PKGNAME does not contain translations, skipping"
continue
}
# save *.mo files if we don't have a tarball yet
if [ ! -f "../$tarball" ]; then
pushd "$PKGDIR" >/dev/null
find -type f -name "*.mo" -exec install -D -m 644 '{}' "$tmp/$PKGNAME/{}" \;
popd >/dev/null
fi
if [ "$dostrip" -a -z "$blacklisted" ]; then
find "$PKGDIR/usr/share/locale" -type f -name "*.mo" -exec rm '{}' \;
find "$PKGDIR/usr/share/locale" -depth -type d -empty -exec rmdir '{}' \; || true
# adapt md5sums file
if [ -f $PKGDIR/DEBIAN/md5sums ]; then
sed -i '/usr\/share\/locale\/.*\.mo$/d' $PKGDIR/DEBIAN/md5sums
fi
# adapt Installed-Size
is=`cd $PKGDIR; du -k -s .|cut -f1`
sed -i "s/^Installed-Size:.*$/Installed-Size: $is/" $PKGDIR/DEBIAN/control
fi
done
# check for empty files, as they indicate a package bug
EMPTYFILES="`find -mindepth 1 -name '.*' -prune -o \( -name "*.po" -o -name "*.pot" \) -empty -print`"
if [ -n "$EMPTYFILES" ]; then
cat <<EOF
pkgstriptranslations: The following PO/POT files are empty. This is known to
cause trouble in the translation importer and generally indicates a package
bug:
$EMPTYFILES
EOF
fi
# create tarball if there are files and we stripped the package
if [ "$dostrip" -a -z "$blacklisted" ]; then
if [ ! -f "../$tarball" ]; then
# copy po/pot files
find \( -name "*.po" -o -name "*.pot" -o -name "*.ts" \) ! -wholename '*/.pc/*' ! -empty -exec install -D -m 644 '{}' "$tmp/source/{}" \;
# grab sdf files from OO.o
if [ "$srcname" = "openoffice.org" ]; then
find debian/ -name "*.sdf" -exec install -D -m 644 '{}' "$tmp/source/{}" \;
fi
# grab XPI files for Mozilla-ish packages
if [ -d debian/lp-export-xpis ]; then
install -d $tmp/source/
cp -a debian/lp-export-xpis $tmp/source/
fi
if [ "$(ls -I _static $tmp | wc -l)" -gt 0 ]; then
echo -n "pkgstriptranslations: preparing translation tarball $tarball..."
pwd=$(pwd)
pushd $tmp > /dev/null
tar c --exclude=_static . | gzip -9 > "$pwd/../$tarball"
numfiles=$(find -type f | wc -l)
popd > /dev/null
echo "done ($numfiles files)"
dpkg-distaddfile "$tarball" raw-translations -
else
echo "pkgstriptranslations: no translation files, not creating tarball"
fi
else
echo "pkgstriptranslations: tarball already exists"
fi
fi
# create static tarball if there are files
if [ -d "$tmp/_static" ]; then
if [ -f "../$tarball_static" ]; then
echo -n "pkgstriptranslations: updating static translation tarball $tarball_static..."
tar -C "$tmp/_static" -xzf "../$tarball_static"
else
echo -n "pkgstriptranslations: preparing static translation tarball $tarball_static..."
dpkg-distaddfile "$tarball_static" raw-translations-static -
fi
pwd=$(pwd)
pushd $tmp/_static > /dev/null
tar c . | gzip -9 > "$pwd/../$tarball_static"
numfiles=$(find -type f | wc -l)
popd > /dev/null
echo "done ($numfiles files)"
fi
|