From fd250d8aed1e5ec17273de7816ddb33cc0911548 Mon Sep 17 00:00:00 2001
From: "Dr. Thomas Orgis" <thomas.orgis@uni-hamburg.de>
Date: Mon, 30 Mar 2020 13:14:00 +0200
Subject: [PATCH] build_lofar: lofar_prefix properly in init.sh, no arg parsing
 in config

It was a bad idea to have the config snipped take $1 for lofar_prefix,
or anything. Since we source the same code again in init.sh, no
references to the build_lofar.sh command line are allowed. The
config needs to be self-contained in that respect.

So the build_lofar.sh script now has the prefix always as first
mandatory argument itself, and optionally the config file to use
as second.
---
 build_lofar.sh            | 19 ++++++++++++++++---
 build_lofar.sh.config.rrz |  1 -
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/build_lofar.sh b/build_lofar.sh
index 45e120b..5b61cdc 100644
--- a/build_lofar.sh
+++ b/build_lofar.sh
@@ -10,7 +10,6 @@
 #   fetch/patch/build code
 
 mandatory_vars="\
-lofar_prefix      Installation prefix to use. Packages are put into sub-directories of that.
 casacore_version  Version of CASAcore.
 pycasa_version    Version of CASAcore Python bindings.
 dysco_version     Version of Dysco.
@@ -35,7 +34,17 @@ CPATH        Path list for C/C++ include file search.
 idg_mkl      Passed on to idg BUILD_WITH_MKL
 "
 
-config=$0.config
+if test $# -lt 1; then
+  echo "$0: Please provide the installation prefix as mandatory argument."
+  exit 1
+fi
+lofar_prefix=$1; shift
+
+if test $# -ge 1; then
+  config=$1; shift
+else
+  config=$0.config
+fi
 
 if ! test -e "$config"; then
   cat <<EOT
@@ -46,7 +55,8 @@ Please create/link an appropriate config script named
 
   $config
 
-. It should load the correct environment for the site, possibly
+(or any other name you provide as second argument).
+It should load the correct environment for the site, possibly
 using environment modules or just setting variables for paths
 and compilers directly. It also has to set up PATH so that the
 desired python interpreter is directly available as the command
@@ -676,6 +686,9 @@ print_init()
 #
 # Step 1: The build config with all variables used.
 #
+
+lofar_prefix='$lofar_prefix'
+
 EOT
   cat $config
 cat <<EOT
diff --git a/build_lofar.sh.config.rrz b/build_lofar.sh.config.rrz
index 06c92ce..61fecbf 100644
--- a/build_lofar.sh.config.rrz
+++ b/build_lofar.sh.config.rrz
@@ -1,6 +1,5 @@
 # The setup on the Hamburg LOFAR GPU Cluster.
 
-lofar_prefix=$1 # Give installation directory as first argument.
 aoflagger_version=2.14.0
 casacore_version=latest
 dysco_version=1.2.0
-- 
GitLab