1
0

fix.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. # fix some English and ASCII specific stuff which can not be handled by po4a
  3. # This should be handled by po4a, but if some pages are not done yet
  4. # we will need to do it manually.
  5. sed -e '/encoding=/s|ISO-8859-1|UTF-8|' -i $(find -name \*.xml)
  6. # Let tidy output UTF-8
  7. sed -e '/output-encoding:/s|latin1|utf8|' -i tidy.conf
  8. sed -e 's|<book>|<book lang="zh_cn">|' -i index.xml
  9. sed -e '/xreflabel/s|Chapter.nbsp.1 - Mailing Lists|第 1 章 - 邮件列表|' \
  10. -e '/xreflabel/s|Chapter.nbsp.1 - Mirror sites|第 1 章 - 镜像站|' \
  11. -i chapter01/resources.xml
  12. sed -e '/xreflabel/s|Chapter.nbsp.\([0-9]\+\)|第 \1 章|' \
  13. -i chapter*/chapter*.xml
  14. sed -e '/xreflabel/s|Host System Requirements|宿主系统需求|' \
  15. -i chapter02/hostreqs.xml
  16. sed -e '/xreflabel/s|General Compilation Instructions|编译过程的一般说明|' \
  17. -i part3intro/generalinstructions.xml
  18. sed -e '/xreflabel/s|Toolchain Technical Notes|工具链技术说明|' \
  19. -i part3intro/toolchaintechnotes.xml
  20. sed -e '/xreflabel/s|Package build instructions|软件包构建说明|' \
  21. -i part3intro/generalinstructions.xml
  22. sed -e '/xreflabel/s|"gcc-pass1"|"第一遍的 GCC"|' \
  23. -i chapter05/gcc-pass1.xml
  24. sed -e '/xreflabel/s|"gcc-pass2"|"第二遍的 GCC"|' \
  25. -i chapter06/gcc-pass2.xml
  26. sed -e '/xreflabel/s|Appendix|附录|' -i \
  27. appendices/acknowledgments.xml \
  28. appendices/acronymlist.xml \
  29. appendices/dependencies.xml \
  30. appendices/license.xml \
  31. appendices/scripts.xml \
  32. appendices/udev-rules.xml
  33. sed -e 's/Approximate build time/估计构建时间/' \
  34. -e 's/Required disk space/需要硬盘空间/' \
  35. -e 's/Installation depends on/安装依赖于/' \
  36. -e 's/Test suite depends on/测试依赖于/' \
  37. -e 's/Must be installed before/必须在下列软件包之前安装/' \
  38. -e 's/Optional dependencies/可选依赖项/' \
  39. -i general.ent
  40. sed -e 's/less than/不到/' \
  41. -e 's/typically about/一般约/' \
  42. -e 's/about \(.*\) with tests/计入测试时间为约 \1/' \
  43. -e 's/with tests/已计入测试时间/' \
  44. -e '/encoding=/s/ISO-8859-1/UTF-8/' \
  45. -i packages.ent
  46. reldate=$(grep 'releasedate' general.ent.orig |
  47. sed 's/.*"\(.*\)".*/\1/;s/\(st\|nd\|rd\|th\),/,/');
  48. reldate_cn=$(LANG=en_US.UTF-8 \
  49. date -d "$reldate" "+%Y 年 %m 月 %d 日" \
  50. 2>/dev/null | sed 's@ 0@ @g')
  51. sed "/releasedate/s/\".*\"/\"${reldate_cn}\"/" -i general.ent
  52. # Some buggy comments produced by po4a are adding extra empty lines.
  53. # Remove them.
  54. sed_cmd='
  55. 1h
  56. 1!{
  57. /<screen[^\n]*><!--.*-->\n/!H
  58. g
  59. /<screen[^\n]*><!--.*-->\n/{
  60. s/\(<screen[^\n]*>\)\(\(<!--.*-->\)\+\n\)\+/\1/
  61. p
  62. n
  63. h
  64. }
  65. }
  66. $p
  67. '
  68. sed -n "${sed_cmd}" -i \
  69. chapter06/ncurses.xml \
  70. chapter08/glibc.xml \
  71. chapter08/flex.xml \
  72. chapter08/ninja.xml \
  73. chapter08/texinfo.xml \
  74. chapter08/systemd.xml \
  75. chapter08/strippingagain.xml \
  76. chapter09/networkd.xml \
  77. chapter09/network.xml \
  78. chapter09/consoled.xml \
  79. chapter09/usage.xml
  80. # Looks stupid, but I don't know any better way.
  81. for iter in 1 2 3; do
  82. sed -n "${sed_cmd}" -i chapter08/strippingagain.xml
  83. done
  84. # Apply lfs-l10n.xml patch, if it's not applied
  85. grep "Simplified Chinese" stylesheets/lfs-xsl/lfs-l10n.xml ||
  86. patch -N -p1 -i ../patches/lfs-l10n.xml.patch
  87. # Opts in the xsl specifying fonts
  88. cp -v ../zh_CN-fonts.xsl stylesheets/lfs-xsl/pdf/
  89. grep zh_CN-fonts stylesheets/lfs-xsl/pdf.xsl ||
  90. sed '/<\/xsl:stylesheet>/i <xsl:include href="pdf/zh_CN-fonts.xsl"/>' \
  91. -i stylesheets/lfs-xsl/pdf.xsl
  92. # Edit Makefile
  93. cp -v Makefile.orig Makefile
  94. # Remove two seds causing encoding error in UTF-8
  95. sed -e '/xa9/d' -i Makefile
  96. # Copy fonts to tmp dir, and let fop to use our custom config
  97. sed '/fop -q/i \\tmkdir -pv $(RENDERTMP)/fonts; cp -v fonts/* $(RENDERTMP)/fonts' -i Makefile
  98. sed 's|fop -q|& -c ../fop.xml|' -i Makefile