You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
2.2 KiB

  1. #!/bin/sh
  2. # NOTE: In this script the first value in the Choices lists will *not* be
  3. # sorted (the "enter information manually" option is kept at the top).
  4. [ -d debian/locales ] || mkdir debian/locales
  5. [ -d debian/sort-tmp ] || mkdir debian/sort-tmp
  6. cd debian/sort-tmp
  7. tplfile=../choose-mirror-bin/DEBIAN/templates
  8. templates=$(grep -E "^Template: mirror/(ht|f)tp/countries" $tplfile | cut -d" " -f2-)
  9. # The first template will take longer because of locale generation
  10. for template in $templates; do
  11. echo "Sorting template '$template'..."
  12. rm -f list.* sortedlist.*
  13. sed -n -e "\%^Template: $template$%,\%^Description:%p" $tplfile |
  14. perl -p -e '
  15. chomp;
  16. if (m/Choices-([^.]*)\.UTF-8:/) {
  17. open (OUT, "> list.$1");
  18. s/Choices-([^.]*)\.UTF-8: //;
  19. # split on commas, except for backslash-escaped ones
  20. @t = split(/(?<!\\), /);
  21. # Skip first value in list
  22. shift(@t);
  23. my $cnt = 1;
  24. foreach my $name (@t) {$cnt++; print OUT "$cnt $name\n";}
  25. close OUT;
  26. }
  27. $_="";'
  28. for file in list.*; do
  29. [ -e "$file" ] || continue
  30. [ $(cat "$file" | wc -l) -gt 1 ] || continue
  31. lang=${file#list.}
  32. unilang=$(grep "^$lang.* UTF-8" /usr/share/i18n/SUPPORTED | \
  33. sed -e 's/[@. ].*//;q' )
  34. if [ -z "$unilang" ]; then
  35. echo "W: language '$lang' skipped: no UTF-8 variant found" >&2
  36. else
  37. if [ ! -d ../locales/$unilang.UTF-8 ]; then
  38. localedef -c -f UTF-8 -i $unilang ../locales/$unilang.UTF-8
  39. fi
  40. # sed statement adds index for 1st (unsorted) value back in
  41. LOCPATH=`pwd` LC_ALL=../locales/$unilang.UTF-8 \
  42. sort -k 2.1 $file | sed -e 's/ .*/, /' | tr -d '\n' | \
  43. sed -e "s/^/Indices-$lang.UTF-8: 1, /" -e 's/, $//' \
  44. >sorted$file
  45. if [ -s sorted$file ]; then
  46. echo "" >>sorted$file
  47. else
  48. rm -f sorted$file
  49. fi
  50. fi
  51. done
  52. # Now the template file must be patched: all sortedlist.* files have
  53. # to be added to the current template.
  54. if ls sorted* >/dev/null 2>&1; then
  55. sed -e "\%$template$%{n;q;}" $tplfile >templates.tmp
  56. cat sorted* >>templates.tmp
  57. sed -e "\%$template$%!d;\%$template$%{:end;n;b end}" $tplfile | \
  58. sed '1,2d' >> templates.tmp
  59. mv templates.tmp $tplfile
  60. else
  61. echo "I: nothing to be sorted"
  62. fi
  63. done
  64. cd ../..
  65. rm -r debian/locales debian/sort-tmp