From 7e9a9debfc308a5b77f0aa22353ca18796ca627c Mon Sep 17 00:00:00 2001
From: Tamas Gal <himself@tamasgal.com>
Date: Wed, 28 Feb 2018 21:15:03 +0100
Subject: [PATCH] Add configure script

---
 Makefile => Makefile.in |  6 ++----
 configure               | 47 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 4 deletions(-)
 rename Makefile => Makefile.in (77%)
 create mode 100755 configure

diff --git a/Makefile b/Makefile.in
similarity index 77%
rename from Makefile
rename to Makefile.in
index e5ca298..9590741 100644
--- a/Makefile
+++ b/Makefile.in
@@ -1,6 +1,4 @@
 SHELL := /bin/bash
-SESSION_NAME := km3mon
-DAQ_LIGIER := 192.168.0.110
 STANDARD_TAGS := "IO_EVT, IO_SUM, IO_TSL, IO_TSL0, IO_TSL1, IO_TSL2, IO_TSSN, MSG, IO_MONIT"
 
 default: start
@@ -12,12 +10,12 @@ start:
 	@tmux rename-window -t ${SESSION_NAME}:1 ligier
 
 	@tmux send-keys -t ${SESSION_NAME}:ligier.1 \
-	    "JLigier -d2 -P 5553" Enter
+	    "JLigier -d2 -P ${MONITORING_LIGIER_PORT}" Enter
 	@sleep 1  # wait a second for JLigier
 
 	@tmux split-window -v -t ${SESSION_NAME}:ligier
 	@tmux send-keys -t ${SESSION_NAME}:ligier.2 \
-	    "ligiermirror -m \"${STANDARD_TAGS}\" ${DAQ_LIGIER}" Enter
+	    "ligiermirror -m \"${STANDARD_TAGS}\" -q ${MONITORING_LIGIER_PORT} -p ${DAQ_LIGIER_PORT} ${DAQ_LIGIER_IP}" Enter
 
 stop:
 	tmux kill-session -t ${SESSION_NAME}
diff --git a/configure b/configure
new file mode 100755
index 0000000..90d16cb
--- /dev/null
+++ b/configure
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+daq_ligier_ip="192.168.0.110"
+daq_ligier_port=5553
+monitoring_ligier_port=5553
+tmux_session_name="km3mon"
+
+for arg in "$@"; do
+    case "$arg" in
+    --daq-ligier-ip=*)
+        daq_ligier_ip=`echo $arg | sed 's/--daq-ligier-ip=//'`
+        ;;
+
+    --daq-ligier-port=*)
+        daq_ligier_port=`echo $arg | sed 's/--daq-ligier-port=//'`
+        ;;
+
+    --monitoring-ligier-port=*)
+        monitoring_ligier_port=`echo $arg | sed 's/--monitoring-ligier-port=//'`
+        ;;
+
+    --tmux-session-name=*)
+        tmux_session_name=`echo $arg | sed 's/--tmux-session-name=//'`
+        ;;
+
+    --help)
+        echo 'usage: ./configure [options]'
+        echo 'options:'
+        echo '  --daq-ligier-ip=<ip>: The IP of the DAQ Ligier [default: ${daq_ligier_ip}].'
+        echo '  --daq-ligier-port=<port>: The port of the DAQ Ligier [default: ${daq_ligier_port}].'
+        echo '  --tmux-session-name=<name>: The name of the tmux session [default: ${tmux_session_name}].'
+        echo 'all invalid options are silently ignored'
+        exit 0
+        ;;
+    esac
+done
+
+echo 'Generating makefile...'
+
+echo "DAQ_LIGIER_IP = ${daq_ligier_ip}" > Makefile
+echo "DAQ_LIGIER_PORT = ${daq_ligier_port}" >> Makefile
+echo "MONITORING_LIGIER_PORT = ${monitoring_ligier_port}" >> Makefile
+echo "SESSION_NAME = ${tmux_session_name}" >> Makefile
+
+cat Makefile.in >> Makefile
+
+echo 'Configuration complete, type "make start" to start the monitoring session.'
-- 
GitLab