find-apps.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # ensure dir
  4. cd -P -- "$(dirname -- "$0")/.."
  5. help() {
  6. echo
  7. echo "-h|--help: To display this usage info"
  8. echo "--ct fast|docker: Print apps which needs docker-compose to run ct"
  9. echo "--json: Print apps in json"
  10. }
  11. WANT_JSON='no'
  12. CT='novalue'
  13. while [ "$#" -gt 0 ]; do
  14. case $1 in
  15. -h|--help)
  16. help
  17. exit 0
  18. ;;
  19. --json)
  20. WANT_JSON='yes'
  21. shift 1
  22. ;;
  23. --ct)
  24. CT="$2"
  25. shift 2
  26. ;;
  27. *)
  28. echo "unknown option $1"
  29. exit 1
  30. ;;
  31. esac
  32. done
  33. if [ "$(./scripts/get-distro.sh)" = 'windows' ]; then
  34. # Otherwise windows may resolve to find.exe
  35. FIND="/usr/bin/find"
  36. else
  37. FIND='find'
  38. fi
  39. find_app() {
  40. local appdir="$1"
  41. "$FIND" "${appdir}" -mindepth 1 -maxdepth 1 -type d
  42. }
  43. CE="$(find_app 'apps')"
  44. EE="$(find_app 'lib-ee')"
  45. if [ "$CT" = 'novalue' ]; then
  46. echo -e "${CE}\n${EE}"
  47. exit 0
  48. fi
  49. APPS_ALL="$(echo -e "${CE}\n${EE}")"
  50. APPS_DOCKER_CT="$(grep -v -E '^#.*' scripts/docker-ct-apps)"
  51. # TODO: fix the tests!
  52. APPS_ALL=("${APPS_ALL[@]/"apps/emqx_auto_subscribe"}")
  53. # shellcheck disable=SC2068
  54. for app in ${APPS_DOCKER_CT[@]}; do
  55. APPS_ALL=("${APPS_ALL[@]/$app}")
  56. done
  57. if [ "$CT" = 'docker' ]; then
  58. RESULT="${APPS_DOCKER_CT}"
  59. else
  60. RESULT="${APPS_ALL[*]}"
  61. fi
  62. if [ "$WANT_JSON" = 'yes' ]; then
  63. echo "${RESULT}" | xargs | tr -d '\n' | jq -R -s -c 'split(" ")'
  64. else
  65. echo "${RESULT}" | xargs
  66. fi