|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# OSX does not support readlink '-f' flag, work |
| 6 | +# around that |
| 7 | +# shellcheck disable=SC2039 |
| 8 | +case $OSTYPE in |
| 9 | + darwin*) |
| 10 | + SCRIPT=$(readlink "$0" || true) |
| 11 | + ;; |
| 12 | + *) |
| 13 | + SCRIPT=$(readlink -f "$0" || true) |
| 14 | + ;; |
| 15 | +esac |
| 16 | + |
| 17 | +ERTS_VSN="{{ erts_vsn }}" |
| 18 | +SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)" |
| 19 | +RELEASE_ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)" |
| 20 | +CONFIG_DIR="$RELEASE_ROOT_DIR/config" |
| 21 | +CONFIG_FILE="$CONFIG_DIR/example.hocon" |
| 22 | + |
| 23 | +find_erts_dir() { |
| 24 | + __erts_dir="$RELEASE_ROOT_DIR/erts-$ERTS_VSN" |
| 25 | + if [ -d "$__erts_dir" ]; then |
| 26 | + ERTS_DIR="$__erts_dir"; |
| 27 | + else |
| 28 | + __erl="$(command -v erl)" |
| 29 | + code="io:format(\"~s\", [code:root_dir()]), halt()." |
| 30 | + __erl_root="$("$__erl" -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$code")" |
| 31 | + ERTS_DIR="$__erl_root/erts-$ERTS_VSN" |
| 32 | + if [ ! -d "$ERTS_DIR" ]; then |
| 33 | + erts_version_code="io:format(\"~s\", [erlang:system_info(version)]), halt()." |
| 34 | + __erts_version="$("$__erl" -boot no_dot_erlang -sasl errlog_type error -noshell -eval "$erts_version_code")" |
| 35 | + ERTS_DIR="${__erl_root}/erts-${__erts_version}" |
| 36 | + if [ -d "$ERTS_DIR" ]; then |
| 37 | + ERTS_VSN=${__erts_version} |
| 38 | + echo "Exact ERTS version (${ERTS_VSN}) match not found, instead using ${__erts_version}. The release may fail to run." 1>&2 |
| 39 | + else |
| 40 | + echo "Can not run the release. There is no ERTS bundled with the release or found on the system." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + fi |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +## generate sys.config and vm.args |
| 48 | +if [ "$CONFIG_FILE" -nt "$RELEASE_ROOT_DIR/sys.conf" ]; then |
| 49 | + find_erts_dir |
| 50 | + |
| 51 | + TIME="$("$ERTS_DIR/bin/escript" "$RELEASE_ROOT_DIR/bin/hocon" generate \ |
| 52 | + --schema_module example_schema \ |
| 53 | + --conf_file "$CONFIG_FILE" \ |
| 54 | + --dest_dir "$CONFIG_DIR" \ |
| 55 | + --pa "$RELEASE_ROOT_DIR/lib/example-0.1.0/ebin")" |
| 56 | + |
| 57 | + cp "$CONFIG_DIR/app.$TIME.config" "$RELEASE_ROOT_DIR/sys.config" |
| 58 | + cp "$CONFIG_DIR/vm.$TIME.args" "$RELEASE_ROOT_DIR/vm.args" |
| 59 | +fi |
| 60 | + |
| 61 | +exec "$SCRIPT_DIR/example" "$@" |
0 commit comments