From 484e3b681403b0558c5c43d33ea46f7c9d840c02 Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Wed, 9 Sep 2020 15:11:18 +0800
Subject: [PATCH] WIP: add a run.sh script and update the README.

---
 README.md |  8 +++----
 run.sh    | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 5 deletions(-)
 create mode 100755 run.sh

diff --git a/README.md b/README.md
index 27c2474e..898d7bcf 100644
--- a/README.md
+++ b/README.md
@@ -12,14 +12,12 @@ $ /cvmfs/container.ihep.ac.cn/bin/hep_container shell SL6
 Before run following commands, please make sure you setup the CVMFS:
 
 ```
-$ source /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.2/setup.sh
 $ git clone git@github.com:cepc/CEPCSW.git
 $ cd CEPCSW
 $ git checkout master # branch name
-$ mkdir build && cd build
-$ cmake .. -DHOST_BINARY_TAG=${BINARY_TAG}
-$ make
-$ ./run gaudirun.py '$EXAMPLESROOT/options/helloalg.py'
+$ source setup.sh
+$ ./build.sh
+$ ./run.sh Examples/options/helloalg.py
 ```
 
 ## Packages
diff --git a/run.sh b/run.sh
new file mode 100755
index 00000000..d5739c55
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+##############################################################################
+# Run script for CEPCSW:
+# - run a simple job
+#
+# Usage:
+# $ ./run.sh Examples/options/helloalg.py
+# or:
+# $ 
+#
+# Author: Tao Lin <lintao@ihep.ac.cn>
+##############################################################################
+
+function info:() {
+    echo "INFO: $*" 1>&2
+}
+
+function error:() {
+    echo "ERROR: $*" 1>&2
+}
+
+function check-cepcsw-envvar() {
+    # CEPCSWEXTERNAL is defined in /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/
+    if [ -z "${CEPCSWEXTERNAL}" ]; then
+        error: "The CEPCSW is not setup. Please source setup.sh."
+        return 1
+    fi
+}
+
+function build-dir() {
+    local blddir=build
+
+    # If detect the extra env var, append it to the build dir
+    if [ -n "${lcg_version}" ]; then
+        blddir=${blddir}.${lcg_version}
+    fi
+    if [ -n "${lcg_platform}" ]; then
+        blddir=${blddir}.${lcg_platform}
+    fi
+
+    echo $blddir
+}
+
+function check-working-builddir() {
+    local blddir=$(build-dir)
+    if [ ! -d "$blddir" ]; then
+        mkdir $blddir || {
+            error: "Failed to create $blddir"
+            return 1
+        }
+    fi
+}
+
+function run-job() {
+    local blddir=$(build-dir)
+
+    $blddir/run gaudirun.py $*
+}
+
+##############################################################################
+# Parse the command line options
+##############################################################################
+
+# The current default platform
+lcg_platform=x86_64-slc6-gcc8-opt
+lcg_version=97.0.2
+
+check-cepcsw-envvar || exit -1
+
+check-working-builddir || exit -1
+
+run-job $* || exit -1
-- 
GitLab