sync-apps.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_prometheus"
  22. "emqx_psk_file"
  23. "emqx_recon"
  24. "emqx_retainer"
  25. "emqx_rule_engine"
  26. "emqx_sasl"
  27. "emqx_sn"
  28. "emqx_stomp"
  29. "emqx_telemetry"
  30. )
  31. if git status --porcelain | grep -qE 'apps/'; then
  32. echo 'apps dir is not git-clear, refuse to sync'
  33. # exit 1
  34. fi
  35. mkdir -p tmp/
  36. download_zip() {
  37. local app="$1"
  38. local ref="$2"
  39. local vsn
  40. 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
  46. repo=${app//_/-}
  47. local url="https://github.com/emqx/$repo/archive/$ref.zip"
  48. echo "downloading ${url}"
  49. curl -fLsS -o "$file" "$url"
  50. }
  51. default_vsn="dev/v4.3.0"
  52. download_zip "emqx_auth_mnesia" "e4.2.3"
  53. for app in "${apps[@]}"; do
  54. download_zip "$app" "$default_vsn"
  55. done
  56. extract_zip(){
  57. local app="$1"
  58. local ref="$2"
  59. local vsn_arg="${3:-}"
  60. local vsn_dft
  61. vsn_dft="$(echo "$ref" | tr '/' '-')"
  62. local vsn
  63. if [ -n "$vsn_arg" ]; then
  64. vsn="$vsn_arg"
  65. else
  66. vsn="$vsn_dft"
  67. fi
  68. local file="tmp/${app}-${vsn_dft}.zip"
  69. local repo
  70. repo=${app//_/-}
  71. rm -rf "apps/${app}/"
  72. unzip "$file" -d apps/
  73. mv "apps/${repo}-${vsn}/" "apps/$app/"
  74. }
  75. extract_zip "emqx_auth_mnesia" "e4.2.3" "e4.2.3"
  76. for app in "${apps[@]}"; do
  77. extract_zip "$app" "$default_vsn"
  78. done
  79. cleanup_app(){
  80. local app="$1"
  81. pushd "apps/$app"
  82. rm -f Makefile rebar.config.script LICENSE src/*.app.src.script src/*.appup.src
  83. rm -rf ".github" ".ci"
  84. # restore rebar.config and app.src
  85. git checkout rebar.config
  86. git checkout src/*.app.src
  87. popd
  88. }
  89. apps+=( "emqx_auth_mnesia" )
  90. for app in "${apps[@]}"; do
  91. cleanup_app "$app"
  92. done