lang-clean.sh 3.0 KB

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