#!/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(/(?&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