find-apps.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. APPS_ALL="$(echo -e "${CE}\n${EE}")"
  46. if [ "$CT" = 'novalue' ]; then
  47. RESULT="${APPS_ALL}"
  48. else
  49. APPS_NORMAL_CT=( )
  50. APPS_DOCKER_CT=( )
  51. for app in ${APPS_ALL}; do
  52. if [ -f "${app}/docker-ct" ]; then
  53. APPS_DOCKER_CT+=("$app")
  54. else
  55. APPS_NORMAL_CT+=("$app")
  56. fi
  57. done
  58. if [ "$CT" = 'docker' ]; then
  59. RESULT="${APPS_DOCKER_CT[*]}"
  60. else
  61. RESULT="${APPS_NORMAL_CT[*]}"
  62. fi
  63. fi
  64. if [ "$WANT_JSON" = 'yes' ]; then
  65. echo "${RESULT}" | xargs | tr -d '\n' | jq -R -s -c 'split(" ")'
  66. else
  67. echo "${RESULT}" | xargs
  68. fi