From 14d0bd5bdda6898bb242ac36f601ce2c095ec866 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Fri, 17 Mar 2023 08:53:38 +0100
Subject: [PATCH] detect ms win; load env file

---
 jobhelper.sh | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/jobhelper.sh b/jobhelper.sh
index 9d73c94..86d39ad 100755
--- a/jobhelper.sh
+++ b/jobhelper.sh
@@ -42,6 +42,11 @@ STORAGEFILE="${DIR_JOBS}/transfer.job"
 function j_init(){
 
   j_banner
+  if [ -r "${DIR_JOBS}/env" ];
+  then
+    echo "INFO: loading custom environment ${DIR_JOBS}/env"
+    . "${DIR_JOBS}/env"
+  fi
 
   if [ ! -d "${DIR_LOGS}" ]; then
     mkdir -p "${DIR_LOGS}" && echo "INFO: dir created ${DIR_LOGS}"
@@ -374,20 +379,27 @@ function j_requireProcess(){
   fi
 }
 
+# detect ms windows by cygwin, mingw, msys ...
+# see https://en.wikipedia.org/wiki/Uname
+# return code is 0 for YES
+function _isMswindows(){
+  uname | grep -iE "(CYGWIN_NT|MINGW|MSYS_NT|Windows_NT|WindowsNT)" >/dev/null
+}
+
 # ------------------------------------------------------------
 # check if it was startet with a given user
 # This is skipped if MS windows was detected with "mingw".
 # param  string  username, i.e. root
 # ------------------------------------------------------------
 function j_requireUser(){
-  # TODO: this is an incomplete check. Check more strings eg. cygwin
-  if uname | grep -iE "mingw" >/dev/null; then
-    return 0
-  fi  
-  sUser=$(id | cut -f 2 -d "(" | cut -f 1 -d ")")
-  if [[ "$sUser" != "$1" ]]; then
-    >&2 echo "ERROR: user $1 is reqired."
-    exit 5
+  if _isMswindows; then
+    echo "SKIP: j_requireUser $1 is not handled on MS Windows."
+  else
+    sUser=$(id | cut -f 2 -d "(" | cut -f 1 -d ")")
+    if [[ "$sUser" != "$1" ]]; then
+      >&2 echo "ERROR: user $1 is reqired."
+      exit 5
+    fi
   fi
 }
 
-- 
GitLab