Repository navigation
Expand file tree
/
Copy pathsort-templates
More file actions
executable file
·75 lines (65 loc) · 2.18 KB
/
Copy pathsort-templates
File metadata and controls
executable file
·75 lines (65 loc) · 2.18 KB
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
#!/bin/sh
# NOTE: In this script the first value in the Choices lists will *not* be
# sorted (the "enter information manually" option is kept at the top).
[ -d debian/locales ] || mkdir debian/locales
[ -d debian/sort-tmp ] || mkdir debian/sort-tmp
cd debian/sort-tmp
tplfile=../choose-mirror-bin/DEBIAN/templates
templates=$(grep -E "^Template: mirror/(ht|f)tp/countries" $tplfile | cut -d" " -f2-)
# The first template will take longer because of locale generation
for template in $templates; do
echo "Sorting template '$template'..."
rm -f list.* sortedlist.*
sed -n -e "\%^Template: $template$%,\%^Description:%p" $tplfile |
perl -p -e '
chomp;
if (m/Choices-([^.]*)\.UTF-8:/) {
open (OUT, "> list.$1");
s/Choices-([^.]*)\.UTF-8: //;
# split on commas, except for backslash-escaped ones
@t = split(/(?<!\\), /);
# Skip first value in list
shift(@t);
my $cnt = 1;
foreach my $name (@t) {$cnt++; print OUT "$cnt $name\n";}
close OUT;
}
$_="";'
for file in list.*; do
[ -e "$file" ] || continue
[ $(cat "$file" | wc -l) -gt 1 ] || continue
lang=${file#list.}
unilang=$(grep "^$lang.* UTF-8" /usr/share/i18n/SUPPORTED | \
sed -e 's/[@. ].*//;q' )
if [ -z "$unilang" ]; then
echo "W: language '$lang' skipped: no UTF-8 variant found" >&2
else
if [ ! -d ../locales/$unilang.UTF-8 ]; then
localedef -c -f UTF-8 -i $unilang ../locales/$unilang.UTF-8
fi
# sed statement adds index for 1st (unsorted) value back in
LOCPATH=`pwd` LC_ALL=../locales/$unilang.UTF-8 \
sort -k 2.1 $file | sed -e 's/ .*/, /' | tr -d '\n' | \
sed -e "s/^/Indices-$lang.UTF-8: 1, /" -e 's/, $//' \
>sorted$file
if [ -s sorted$file ]; then
echo "" >>sorted$file
else
rm -f sorted$file
fi
fi
done
# Now the template file must be patched: all sortedlist.* files have
# to be added to the current template.
if ls sorted* >/dev/null 2>&1; then
sed -e "\%$template$%{n;q;}" $tplfile >templates.tmp
cat sorted* >>templates.tmp
sed -e "\%$template$%!d;\%$template$%{:end;n;b end}" $tplfile | \
sed '1,2d' >> templates.tmp
mv templates.tmp $tplfile
else
echo "I: nothing to be sorted"
fi
done
cd ../..
rm -r debian/locales debian/sort-tmp