#!/usr/bin/env bash set -euo pipefail if [ -n "${DEBUG:-}" ]; then set -x fi UNAME="$(uname -s)" PROJ_ROOT="$(git rev-parse --show-toplevel)" cd "$PROJ_ROOT" logerr() { if [ "${TERM:-dumb}" = dumb ]; then echo -e "ERROR: $*" 1>&2 else echo -e "$(tput setaf 1)ERROR: $*$(tput sgr0)" 1>&2 fi } usage() { cat < IO.puts()')"/..) for app in "${elixir_libs_root_dir}"/*; do if [ -n "$erl_libs" ]; then erl_libs="${erl_libs}${sep}${app}" else erl_libs="${app}" fi done fi export ERL_LIBS="$erl_libs" } ## poorman's mustache templating mustache() { local name="$1" local value="$2" local file="$3" if [[ "$UNAME" == "Darwin" ]]; then sed -i '' "s|{{[[:space:]]*${name}[[:space:]]*}}|${value}|g" "$file" else sed -i "s|{{\s*${name}\s*}}|${value}|g" "$file" fi } ## render the merged boot conf file. ## the merge action is done before the profile is compiled render_hocon_conf() { input="apps/emqx_conf/etc/emqx.conf.all" output="$EMQX_ETC_DIR/emqx.conf" cp "$input" "$output" mustache emqx_default_erlang_cookie "$COOKIE" "$output" mustache platform_data_dir "${EMQX_DATA_DIR}" "$output" mustache platform_log_dir "${EMQX_LOG_DIR}" "$output" mustache platform_etc_dir "${EMQX_ETC_DIR}" "$output" } ## Make comma separated quoted strings make_erlang_args() { local in=("$@") local args='' for arg in "${in[@]}"; do if [ -z "$args" ]; then args="\"$arg\"" else args="$args, \"$arg\"" fi done echo "$args" } call_hocon() { local args erl_code args="$(make_erlang_args "$@")" erl_code=" {ok, _} = application:ensure_all_started(hocon), \ try mnesia_hook:module_info() catch _:_-> io:format(standard_error, \"Force setting DB backend to 'mnesia', and 'role' to 'core'~n\", []), os:putenv(\"EMQX_NODE__DB_BACKEND\", \"mnesia\"), os:putenv(\"EMQX_NODE__DB_ROLE\", \"core\") end, ok = hocon_cli:main([$args]), init:stop(). " erl -noshell -eval "$erl_code" } # Function to generate app.config and vm.args # sets two environment variables CONF_FILE and ARGS_FILE generate_app_conf() { ## timestamp for each generation local NOW_TIME NOW_TIME="$(date +'%Y.%m.%d.%H.%M.%S')" ## this command populates two files: app.