sync-apps.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. set -euo pipefail
  3. force="${1:-no}"
  4. apps=(
  5. "emqx_auth_http"
  6. "emqx_auth_jwt"
  7. "emqx_auth_ldap"
  8. "emqx_auth_mnesia"
  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. "emqx_web_hook")
  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. rm -rf apps/emqx_*
  37. mkdir -p tmp/
  38. download_zip() {
  39. local app="$1"
  40. local ref="$2"
  41. local vsn="$(echo "$ref" | tr '/' '-')"
  42. local file="tmp/${app}-${vsn}.zip"
  43. if [ -f "$file" ] && [ "$force" != "force" ]; then
  44. return 0
  45. fi
  46. local repo="$(echo "$app" | sed 's#_#-#g')"
  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_passwd" "v1.1.1"
  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="$(echo "$ref" | tr '/' '-')"
  61. local vsn
  62. if [ -n "$vsn_arg" ]; then
  63. vsn="$vsn_arg"
  64. else
  65. vsn="$vsn_dft"
  66. fi
  67. local file="tmp/${app}-${vsn_dft}.zip"
  68. local repo="$(echo "$app" | sed 's#_#-#g')"
  69. unzip "$file" -d apps/
  70. mv "apps/${repo}-${vsn}/" "apps/$app/"
  71. }
  72. extract_zip "emqx_passwd" "v1.1.1" "1.1.1"
  73. for app in ${apps[@]}; do
  74. extract_zip "$app" "$default_vsn"
  75. done
  76. cleanup_app(){
  77. local app="$1"
  78. rm -f "apps/$app/Makefile"
  79. rm -f "apps/$app/rebar.config.script"
  80. }
  81. apps+=( "emqx_passwd" )
  82. for app in ${apps[@]}; do
  83. cleanup_app $app
  84. done