jolly has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/onomondo-eim/+/42972?usp=email )


Change subject: Add Makefile and start script for installation
......................................................................

Add Makefile and start script for installation

The Makefile allows to compile and install onomondo-eim. This allows to
build it with osmo-dev and therefore build and run it with testenv of
osmo-ttcn3-hacks.

The start script allows to run onomondo-eim without starting erlang by
hand. It was taken from osmo-s1gw repository and log-level option was
added.

The program name changed from 'onomondo_eim_release' to 'onomodo-eim'.

Related: SYS#8100
Change-Id: I4f038c0901c23cbe18ef62eb546e264d0b924cc7
---
A Makefile
A contrib/onomondo-eim.sh
M rebar.config
3 files changed, 143 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/onomondo-eim refs/changes/72/42972/1

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9ca1dee
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,35 @@
+# where rebar3 stores build output
+REBAR_BASE_DIR ?= _build
+# config file used by 'run' and 'shell'
+CONFIG ?= config/sys.config
+# directory paths for 'install'
+BINDIR ?= /usr/bin
+LIBDIR ?= /usr/lib
+CONFDIR ?= /etc/osmocom
+
+all: build
+
+GEN_FILES = src/*
+
+build: $(GEN_FILES)
+       rebar3 compile
+
+release: $(GEN_FILES)
+       rebar3 release
+
+run: shell
+
+shell: build
+       rebar3 shell --config $(CONFIG)
+
+install: release
+       install -d $(DESTDIR)$(LIBDIR)
+       cp -r $(REBAR_BASE_DIR)/default/rel/onomondo-eim $(DESTDIR)$(LIBDIR)/
+       install -Dm0755 contrib/onomondo-eim.sh \
+               $(DESTDIR)$(BINDIR)/onomondo-eim
+       install -Dm0644 config/sys.config \
+               $(DESTDIR)$(CONFDIR)/onomondo-eim.config
+
+clean:
+       rebar3 clean
+       rm -rf $(REBAR_BASE_DIR)
diff --git a/contrib/onomondo-eim.sh b/contrib/onomondo-eim.sh
new file mode 100755
index 0000000..3252610
--- /dev/null
+++ b/contrib/onomondo-eim.sh
@@ -0,0 +1,107 @@
+#!/bin/sh -e
+
+# Simple boot script for Erlang/OTP releases that can be used in systemd unit 
files.
+#
+# Copyright 2025 by sysmocom - s.f.m.c. GmbH <[email protected]>
+# Author: Vadim Yanitskiy <[email protected]>
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+APP_NAME=onomondo-eim
+
+ROOTDIR=${ROOTDIR:-"/usr/lib/${APP_NAME}"}
+CONFIG="/etc/osmocom/${APP_NAME}.config"
+COOKIE="${APP_NAME}"
+NODE_NAME="${APP_NAME}@$(uname -n)"
+ERL_SHELL="-noshell -noinput"
+LOG_LEVEL="notice"
+
+print_usage() {
+  echo "Usage: $0 [-s] [-r ROOTDIR] [-c CONFIG] [-C COOKIE] [-n NAME@HOST] [-l 
LOG_LEVEL]"
+}
+
+print_help() {
+  echo "  -h    This message"
+  echo "  -s    Enable interactive shell"
+  echo "  -r    Application's root directory (default: ${ROOTDIR})"
+  echo "  -c    Config file path (default: ${CONFIG})"
+  echo "  -C    Erlang node cookie (default: ${COOKIE})"
+  echo "  -n    Erlang node name (default: ${NODE_NAME})"
+  echo "  -l    Logger level (default: ${LOG_LEVEL})"
+}
+
+# Parse command line options, if any
+while getopts "c:C:hn:r:sl:" opt; do
+  case "$opt" in
+    c)
+      CONFIG="$OPTARG"
+      ;;
+    C)
+      COOKIE="$OPTARG"
+      ;;
+    n)
+      NODE_NAME="$OPTARG"
+      ;;
+    r)
+      ROOTDIR=$(realpath "$OPTARG")
+      ;;
+    s)
+      ERL_SHELL="-shell"
+      ;;
+    l)
+      LOG_LEVEL="$OPTARG"
+      ;;
+    h)
+      print_usage
+      print_help
+      exit 1
+      ;;
+    *)
+      print_usage
+      exit 1
+      ;;
+  esac
+done
+
+# Make sure that the application's root directory exists
+if [ ! -d "${ROOTDIR}" ]; then
+  echo "Error: ROOTDIR=${ROOTDIR} does not exist"
+  echo "Please specify the root directory using '-r' or via the environment"
+  exit 1
+fi
+
+# Determine the ERTS directory path (if not set)
+if [ -z "${ERTS_DIR}" ]; then
+  # Parse the ERTS version from rebar3-generated bootstrap script
+  ERTS_VSN=$(grep "^ERTS_VSN=" ${ROOTDIR}/bin/${APP_NAME} | cut -d'"' -f2)
+  ERTS_DIR=${ERTS_DIR:-"${ROOTDIR}/erts-${ERTS_VSN}"}
+fi
+
+# Determine the release directory path (if not set)
+if [ -z "${REL_DIR}" ]; then
+  # Parse the release version from rebar3-generated bootstrap script
+  REL_VSN=$(grep "^REL_VSN=" ${ROOTDIR}/bin/${APP_NAME} | cut -d'"' -f2)
+  REL_DIR="${ROOTDIR}/releases/${REL_VSN}"
+fi
+
+# Determine the boot script name
+[ -f "${REL_DIR}/${APP_NAME}.boot" ] && BOOTFILE="${APP_NAME}" || 
BOOTFILE=start
+
+# erlexec requires BINDIR to be set
+export BINDIR="${ERTS_DIR}/bin"
+
+exec ${BINDIR}/erlexec \
+  +C multi_time_warp \
+  -boot "${REL_DIR}/${BOOTFILE}" \
+  -config "${CONFIG}" \
+  -setcookie "${COOKIE}" \
+  -sname "${NODE_NAME}" \
+  -mode embedded \
+  -kernel logger_level "${LOG_LEVEL}" \
+  ${ERL_SHELL}
+
+# vim:set ts=2 sw=2 et:
diff --git a/rebar.config b/rebar.config
index 43b3505..1380062 100644
--- a/rebar.config
+++ b/rebar.config
@@ -30,7 +30,7 @@
 ]}.

 {relx, [
-    {release, {onomondo_eim_release, {git, short}}, [onomondo_eim, sasl, 
runtime_tools]},
+    {release, {'onomondo-eim', {git, short}}, [onomondo_eim, sasl, 
runtime_tools]},
     {dev_mode, false},
     {include_erts, true},
     {include_src, false},

--
To view, visit https://gerrit.osmocom.org/c/onomondo-eim/+/42972?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: onomondo-eim
Gerrit-Branch: master
Gerrit-Change-Id: I4f038c0901c23cbe18ef62eb546e264d0b924cc7
Gerrit-Change-Number: 42972
Gerrit-PatchSet: 1
Gerrit-Owner: jolly <[email protected]>

Reply via email to