lang-clean.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. #
  3. # Version 1.0.1 Build 13
  4. #
  5. # clean.sh - multi-language support script
  6. # Remove all language output files from lang folder.
  7. #
  8. #############################################################################
  9. # Change log:
  10. # 1 Nov. 2018, XPila, Initial
  11. # 18 Oct. 2018, XPila, New lang, arduino 1.8.5 - fw-clean.sh and lang-clean.sh fix
  12. # 25 Oct. 2018, XPila, New lang - fixed french langcode and comparsion in lang-clean script
  13. # 10 Dec. 2018, jhoblitt, make all shell scripts executable
  14. # 26 Jul. 2019, leptun, Fix shifted languages. Use \n and \x0a
  15. # 14 Sep. 2019, 3d-gussner, Prepare adding new language
  16. # 01 Mar. 2021, 3d-gussner, Move `Dutch` language parts
  17. # 22 Mar. 2021, 3d-gussner, Move Dutch removing part to correct loaction
  18. # 21 Dec. 2021, 3d-gussner, Use one config file for all languages
  19. # 03 Jan. 2022, 3d-gussner, Cleanup outdated code
  20. # 11 Jan. 2022, 3d-gussner, Also remove temporally files which have been
  21. # generated for message and size count comparison
  22. # Added version and Change log
  23. # colored output
  24. # Add Community language support
  25. # Use `git rev-list --count HEAD lang-clean.sh`
  26. # to get Build Nr
  27. # 25 Jan. 2022, 3d-gussner, clean up lang-import.sh temproray files
  28. # 14 Feb. 2022, 3d-gussner, Fix single language run without config.sh OK
  29. # 16 Mar. 2022, 3d-gussner, Cleanup `output-layout/sorted-??.txt`
  30. #############################################################################
  31. result=0
  32. rm_if_exists()
  33. {
  34. if [ -e $1 ]; then
  35. echo -n "$(tput sgr0) removing $(tput setaf 3)'$1'$(tput sgr0)..." >&2
  36. if rm $1; then
  37. echo "$(tput setaf 2)OK$(tput sgr0)" >&2
  38. else
  39. echo "$(tput setaf 1)NG!$(tput sgr0)" >&2
  40. result=1
  41. fi
  42. fi
  43. }
  44. clean_lang()
  45. {
  46. if [ "$1" = "en" ]; then
  47. rm_if_exists lang_$1.tmp
  48. rm_if_exists lang_$1.cnt
  49. rm_if_exists lang_$1.max
  50. else
  51. rm_if_exists lang_$1.tmp
  52. rm_if_exists lang_en_$1.tmp
  53. rm_if_exists lang_en_$1.dif
  54. rm_if_exists lang_$1.ofs
  55. rm_if_exists lang_$1.txt
  56. rm_if_exists po/new/$1_new.po
  57. rm_if_exists po/new/$1.mo
  58. rm_if_exists po/new/$1_filtered.po
  59. rm_if_exists po/new/lang_en_$1.txt
  60. rm_if_exists po/new/output-layout-$1.txt
  61. rm_if_exists po/new/output-sorted-$1.txt
  62. fi
  63. rm_if_exists lang_$1_check.dif
  64. rm_if_exists lang_$1.bin
  65. rm_if_exists lang_$1.dat
  66. rm_if_exists lang_$1_1.tmp
  67. rm_if_exists lang_$1_2.tmp
  68. rm_if_exists po/new/nonascii.txt
  69. }
  70. echo "$(tput setaf 2)lang-clean.sh started$(tput sgr0)" >&2
  71. #Clean English
  72. clean_lang en
  73. #Clean languages
  74. echo "lang-clean languages:$(tput setaf 2)$LANGUAGES$(tput sgr0)" >&2
  75. if [ -e $1 ]; then
  76. # Config:
  77. if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
  78. if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr0)" >&2; exit 1; fi
  79. if [ ! -z "$COMMUNITY_LANGUAGES" ]; then
  80. LANGUAGES+=" $COMMUNITY_LANGUAGES"
  81. fi
  82. for lang in $LANGUAGES; do
  83. clean_lang $lang
  84. done
  85. else
  86. clean_lang $1
  87. fi
  88. if [ $result -eq 0 ]; then
  89. echo "$(tput setaf 2) lang-clean.sh with success$(tput sgr0)" >&2
  90. else
  91. echo "$(tput setaf 1) lang-clean.sh with errors!$(tput sgr0)" >&2
  92. fi
  93. case "$-" in
  94. *i*) echo "press enter key" >&2; read ;;
  95. esac
  96. exit $result