File: sort-countries

package info (click to toggle)
choose-mirror 2.13etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,208 kB
  • ctags: 120
  • sloc: perl: 1,199; ansic: 636; sh: 195; makefile: 123; python: 38
file content (61 lines) | stat: -rwxr-xr-x 2,014 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

# Note: the first value in the choices list is not sorted

[ -d debian/locales ] || mkdir debian/locales
[ -d debian/sort-tmp ] || mkdir debian/sort-tmp
cd debian/sort-tmp

for protocol in http ftp; do
	if ! grep -q "^Template: mirror/$protocol/countries" ../choose-mirror-bin/DEBIAN/templates; then
		continue
	fi

	rm -f list.* sortedlist.*
	sed -n -e "/^Template: mirror\\/$protocol\\/countries/,/^Description:/p" ../choose-mirror-bin/DEBIAN/templates |
	perl -p -e '
		chomp;
		if (m/Choices-([^.]*)\.UTF-8:/) {
			open (OUT, "> list.$1");
			# 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
		lang=${file#list.}
		unilang=$(grep "^$lang.* UTF-8" /usr/share/i18n/SUPPORTED | sed -e 's/[@. ].*//;q' )
		if [ -z "$unilang" ]; then
			echo "Warning: lang $lang skipped because no UTF-8 variant found" 1>&2
		else
			if [ ! -d ../locales/$unilang.UTF-8 ]; then 
				localedef -c -f UTF-8 -i $unilang ../locales/$unilang.UTF-8
			fi
			# Add 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 ../choose-mirror-bin/DEBIAN/templates must be patched: all sortedlist.*
	#  files have to be added to the mirror/$protocol/countries template.
	sed -e "/$protocol.*countries/{n;q;}" ../choose-mirror-bin/DEBIAN/templates >templates.tmp
	cat sorted* >>templates.tmp
	sed -e "/$protocol.*countries/!d;/$protocol.*countries/{:end;n;b end}" ../choose-mirror-bin/DEBIAN/templates | \
		sed '1,2d' >> templates.tmp
	mv templates.tmp  ../choose-mirror-bin/DEBIAN/templates
done

cd ../..
rm -r debian/locales debian/sort-tmp