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.
 
 
 
 

117 lines
4.0 KiB

  1. #!/bin/bash
  2. set -e
  3. # Script for generating a debconf templates file from both files
  4. # in debian/po/*.po and country names translations from the
  5. # iso-codes package
  6. TEMPLATES="$@"
  7. # Translations location (relative to the build root directory)
  8. ISO3166TRANSLATIONS=debian/iso-codes
  9. if [ -z "$DEB_HOST_ARCH" ]; then
  10. DEB_HOST_ARCH="$(dpkg-architecture -qDEB_HOST_ARCH)"
  11. fi
  12. # Get the English names for the country codes in the list
  13. country_names() {
  14. local list=$1
  15. local code name
  16. for code in $(xargs < $list); do
  17. # Ensure commas in country names are escaped
  18. name="$(cat debian/iso_3166.tab | \
  19. sed -n -r "/^$code[[:space:]]/ s/^[^[:space:]]+[[:space:]]+//p" | \
  20. sed 's/,/\\\\,/g')"
  21. if [ "$name" ]; then
  22. echo -n ", $name"
  23. else
  24. echo "Warning: no country name found for '$code'" >&2
  25. echo -n ", $code"
  26. fi
  27. done
  28. }
  29. # Get the ordered list of countries from the iso_3166.xml, sorted
  30. # according to the regionmap.
  31. printf "Creating the list of countries for HTTP mirrors..."
  32. HTTPCODECHOICES="$(xargs < debian/httplist-countries | sed 's/ /, /g')"
  33. HTTPCHOICES="$(country_names debian/httplist-countries)"
  34. printf " Done.\n"
  35. printf "Creating the list of countries for FTP mirrors..."
  36. FTPCODECHOICES="$(xargs < debian/ftplist-countries | sed 's/ /, /g')"
  37. FTPCHOICES="$(country_names debian/ftplist-countries)"
  38. printf " Done.\n"
  39. printf "Insert the lists of choices into the templates file..."
  40. (
  41. for t in $TEMPLATES; do
  42. cat $t
  43. echo
  44. done
  45. ) | debian/templates-build.pl "$DEB_HOST_ARCH" | \
  46. perl -pe 'if (m,http/countries$,) { $found = 2; } elsif ($found and /^Choices-C:/ && length "'"$HTTPCODECHOICES"'") { s/$/, '"$HTTPCODECHOICES"'/; $found -= 1; } elsif ($found and /^__Choices:/ && length "'"$HTTPCHOICES"'") { s/$/'"$HTTPCHOICES"'/; $found -= 1; }' | \
  47. perl -pe 'if (m,ftp/countries$,) { $found = 2; } elsif ($found and /^Choices-C:/ && length "'"$FTPCODECHOICES"'") { s/$/, '"$FTPCODECHOICES"'/; $found -= 1; } elsif ($found and /^__Choices:/ && length "'"$FTPCHOICES"'") { s/$/'"$FTPCHOICES"'/; $found -= 1; }' \
  48. >debian/templates.tmp
  49. printf " Done.\n"
  50. # Create temporary "pobuild" directories
  51. rm -rf debian/pobuild* >/dev/null 2>&1
  52. mkdir debian/pobuild
  53. # Create the appropriate POTFILES.in file there
  54. cat >debian/pobuild/POTFILES.in <<EOF
  55. [type: gettext/rfc822deb] templates.tmp
  56. EOF
  57. # Create the appropriate output file also
  58. cat >debian/pobuild/output <<EOF
  59. 2 utf8
  60. EOF
  61. # Run debconf-updatepo to create pobuild/templates.pot
  62. debconf-updatepo --podir debian/pobuild
  63. printf "Include country names translations into the templates file:\n"
  64. # The following takes place for each language
  65. # (each existing file in debian/po)
  66. for pofile in debian/po/*.po ; do
  67. pofilename=`basename $pofile`
  68. langname=`basename $pofilename .po`
  69. printf " $langname..."
  70. cp $pofile debian/pobuild/$pofilename.d-i
  71. # update with generated templates.pot
  72. msgmerge -U debian/pobuild/$pofilename.d-i \
  73. debian/pobuild/templates.pot 2>/dev/null
  74. if [ -f $ISO3166TRANSLATIONS/$pofilename ]; then
  75. # ensure iso-codes translations are in UTF-8
  76. msgconv -t UTF-8 "$ISO3166TRANSLATIONS/$pofilename" \
  77. > debian/pobuild/$pofilename.iso-codes
  78. # merge with iso-codes translations
  79. msgmerge debian/pobuild/$pofilename.iso-codes \
  80. debian/pobuild/$pofilename.d-i \
  81. > debian/pobuild/$pofilename 2>/dev/null
  82. # clean out the generated file
  83. msgmerge -U debian/pobuild/$pofilename \
  84. debian/pobuild/templates.pot 2>/dev/null
  85. else
  86. cp debian/pobuild/$pofilename.d-i debian/pobuild/$pofilename
  87. fi
  88. printf " done\n"
  89. done
  90. # and now we generate the templates file from all this
  91. PODEBCONF_LIB=. po2debconf --podir debian/pobuild debian/templates.tmp | \
  92. sed "s/\[ Default value for .*\]//" \
  93. >debian/choose-mirror-bin.templates
  94. # give the new templates file the same mtime as the input file, so that
  95. # po2debconf doesn't decide that it needs to run debconf-updatepo
  96. touch -mr debian/choose-mirror-bin.templates-in debian/choose-mirror-bin.templates
  97. rm -f debian/templates.tmp