lang-clean.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. #
  3. # Version 1.0.1 Build 12
  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. #############################################################################
  30. result=0
  31. rm_if_exists()
  32. {
  33. if [ -e $1 ]; then
  34. echo -n "$(tput sgr0) removing $(tput setaf 3)'$1'$(tput sgr0)..." >&2
  35. if rm $1; then
  36. echo "$(tput setaf 2)OK$(tput sgr0)" >&2
  37. else
  38. echo "$(tput setaf 1)NG!$(tput sgr0)" >&2
  39. result=1
  40. fi
  41. fi
  42. }
  43. clean_lang()
  44. {
  45. if [ "$1" = "en" ]; then
  46. rm_if_exists lang_$1.tmp
  47. rm_if_exists lang_$1.cnt
  48. rm_if_exists lang_$1.max
  49. else
  50. rm_if_exists lang_$1.tmp
  51. rm_if_exists lang_en_$1.tmp
  52. rm_if_exists lang_en_$1.dif
  53. rm_if_exists lang_$1.ofs
  54. rm_if_exists lang_$1.txt
  55. rm_if_exists po/new/$1_new.po
  56. rm_if_exists po/new/$1.mo
  57. rm_if_exists po/new/$1_filtered.po
  58. rm_if_exists po/new/lang_en_$1.txt
  59. rm_if_exists po/new/$1-output.txt
  60. fi
  61. rm_if_exists lang_$1_check.dif
  62. rm_if_exists lang_$1.bin
  63. rm_if_exists lang_$1.dat
  64. rm_if_exists lang_$1_1.tmp
  65. rm_if_exists lang_$1_2.tmp
  66. rm_if_exists po/new/nonascii.txt
  67. }
  68. echo "$(tput setaf 2)lang-clean.sh started$(tput sgr0)" >&2
  69. #Clean English
  70. clean_lang en
  71. #Clean languages
  72. echo "lang-clean languages:$(tput setaf 2)$LANGUAGES$(tput sgr0)" >&2
  73. if [ -e $1 ]; then
  74. # Config:
  75. if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
  76. if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr0)" >&2; exit 1; fi
  77. if [ ! -z "$COMMUNITY_LANGUAGES" ]; then
  78. LANGUAGES+=" $COMMUNITY_LANGUAGES"
  79. fi
  80. for lang in $LANGUAGES; do
  81. clean_lang $lang
  82. done
  83. else
  84. clean_lang $1
  85. fi
  86. if [ $result -eq 0 ]; then
  87. echo "$(tput setaf 2) lang-clean.sh with success$(tput sgr0)" >&2
  88. else
  89. echo "$(tput setaf 1) lang-clean.sh with errors!$(tput sgr0)" >&2
  90. fi
  91. case "$-" in
  92. *i*) echo "press enter key" >&2; read ;;
  93. esac
  94. exit $result