merge-config.escript 890 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env escript
  2. %% This script reads up emqx.conf and split the sections
  3. %% and dump sections to separate files.
  4. %% Sections are grouped between CONFIG_SECTION_BGN and
  5. %% CONFIG_SECTION_END pairs
  6. %%
  7. %% NOTE: this feature is so far not used in opensource
  8. %% edition due to backward-compatibility reasons.
  9. -mode(compile).
  10. main(_) ->
  11. {ok, BaseConf} = file:read_file("apps/emqx_machine/etc/emqx_machine.conf"),
  12. Apps = filelib:wildcard("*", "apps/") -- ["emqx_machine"],
  13. Conf = lists:foldl(fun(App, Acc) ->
  14. Filename = filename:join([apps, App, "etc", App]) ++ ".conf",
  15. case filelib:is_regular(Filename) of
  16. true ->
  17. {ok, Bin1} = file:read_file(Filename),
  18. [Acc, io_lib:nl(), Bin1];
  19. false -> Acc
  20. end
  21. end, BaseConf, Apps),
  22. ok = file:write_file("apps/emqx_machine/etc/emqx.conf.all", Conf).