sync-apps.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. set -euo pipefail
  3. force="${1:-no}"
  4. apps=(
  5. # "emqx_auth_http" # permanently diverged
  6. # "emqx_web_hook" # permanently diverged
  7. "emqx_auth_jwt"
  8. "emqx_auth_ldap"
  9. "emqx_auth_mongo"
  10. "emqx_auth_mysql"
  11. "emqx_auth_pgsql"
  12. "emqx_auth_redis"
  13. "emqx_bridge_mqtt"
  14. "emqx_coap"
  15. "emqx_dashboard"
  16. "emqx_exhook"
  17. "emqx_exproto"
  18. "emqx_lua_hook"
  19. "emqx_lwm2m"
  20. "emqx_management"
  21. "emqx_plugin_template"
  22. "emqx_prometheus"
  23. "emqx_psk_file"
  24. "emqx_recon"
  25. "emqx_retainer"
  26. "emqx_rule_engine"
  27. "emqx_sasl"
  28. "emqx_sn"
  29. "emqx_stomp"
  30. "emqx_telemetry"
  31. )
  32. if git status --porcelain | grep -qE 'apps/'; then
  33. echo 'apps dir is not git-clear, refuse to sync'
  34. # exit 1
  35. fi
  36. mkdir -p tmp/
  37. download_zip() {
  38. local app="$1"
  39. local ref="$2"
  40. local vsn="$(echo "$ref" | tr '/' '-')"
  41. local file="tmp/${app}-${vsn}.zip"
  42. if [ -f "$file" ] && [ "$force" != "force" ]; then
  43. return 0
  44. fi
  45. local repo="$(echo "$app" | sed 's#_#-#g')"
  46. local url="https://github.com/emqx/$repo/archive/$ref.zip"
  47. echo "downloading ${url}"
  48. curl -fLsS -o "$file" "$url"
  49. }
  50. default_vsn="dev/v4.3.0"
  51. download_zip "emqx_auth_mnesia" "e4.2.3"
  52. for app in ${apps[@]}; do
  53. download_zip "$app" "$default_vsn"
  54. done
  55. extract_zip(){
  56. local app="$1"
  57. local ref="$2"
  58. local vsn_arg="${3:-}"
  59. local vsn_dft="$(echo "$ref" | tr '/' '-')"
  60. local vsn
  61. if [ -n "$vsn_arg" ]; then
  62. vsn="$vsn_arg"
  63. else
  64. vsn="$vsn_dft"
  65. fi
  66. local file="tmp/${app}-${vsn_dft}.zip"
  67. local repo="$(echo "$app" | sed 's#_#-#g')"
  68. rm -rf "apps/${app}/"
  69. unzip "$file" -d apps/
  70. mv "apps/${repo}-${vsn}/" "apps/$app/"
  71. }
  72. extract_zip "emqx_auth_mnesia" "e4.2.3" "e4.2.3"
  73. for app in ${apps[@]}; do
  74. extract_zip "$app" "$default_vsn"
  75. done
  76. cleanup_app(){
  77. local app="$1"
  78. pushd "apps/$app"
  79. rm -f Makefile rebar.config.script LICENSE src/*.app.src.script src/*.appup.src
  80. rm -rf ".github" ".ci"
  81. # restore rebar.config and app.src
  82. git checkout rebar.config
  83. git checkout src/*.app.src
  84. popd
  85. }
  86. apps+=( "emqx_auth_mnesia" )
  87. for app in ${apps[@]}; do
  88. cleanup_app $app
  89. done