check-example-configs.sh 1.4 KB

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