check-example-configs.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. cd -P -- "$(dirname -- "$0")/../.."
  4. PROFILE="${PROFILE:-emqx}"
  5. DIR_NAME='examples'
  6. SCHEMA_MOD='emqx_conf_schema'
  7. if [ "${PROFILE}" = 'emqx-enterprise' ]; then
  8. DIR_NAME='ee-examples'
  9. SCHEMA_MOD='emqx_enterprise_schema'
  10. fi
  11. IFS=$'\n' read -r -d '' -a FILES < <(find "rel/config/${DIR_NAME}" -name "*.example" 2>/dev/null | sort && printf '\0')
  12. prepare_erl_libs() {
  13. local libs_dir="$1"
  14. local erl_libs="${ERL_LIBS:-}"
  15. local sep=':'
  16. for app in "${libs_dir}"/*; do
  17. if [ -d "${app}/ebin" ]; then
  18. if [ -n "$erl_libs" ]; then
  19. erl_libs="${erl_libs}${sep}${app}"
  20. else
  21. erl_libs="${app}"
  22. fi
  23. fi
  24. done
  25. export ERL_LIBS="$erl_libs"
  26. }
  27. # This is needed when checking schema
  28. export EMQX_ETC_DIR="apps/emqx/etc"
  29. prepare_erl_libs "_build/$PROFILE/lib"
  30. check_file() {
  31. local file="$1"
  32. erl -noshell -eval \
  33. "File=\"$file\",
  34. case emqx_hocon:load_and_check($SCHEMA_MOD, File) of
  35. {ok, _} ->
  36. io:format(\"check_example_config_ok: ~s~n\", [File]),
  37. halt(0);
  38. {error, Reason} ->
  39. io:format(\"failed_to_check_example_config: ~s~n~p~n\", [File, Reason]),
  40. halt(1)
  41. end."
  42. }
  43. for file in "${FILES[@]}"; do
  44. check_file "$file"
  45. done