]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGPP/QA/scripts/alienSync.sh
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGPP / QA / scripts / alienSync.sh
index 4c2d7b7bd709267949f5841cbca2f8c6032dcb22..92aa5f2429c44a5a33b209b629db69be678d6e29 100755 (executable)
@@ -6,6 +6,9 @@
 #    (the local chache location and paths can be manipulated.)
 #  - needs a configured config file (by default alienSync.config)
 #    and a working alien environment (token and at least $ALIEN_DIR or $ALIEN_ROOT set)
+#  - can be also used without a config file
+#  
+# run the script without argument to see the examples
 #
 #  origin: Mikolaj Krzewicki, mikolaj.krzewicki@cern.ch
 #
@@ -21,11 +24,15 @@ main()
     echo "expert: ${0##*/} alienFindCommand=\"alien_find /some/path/ file\" [opt=value]"
     echo "        ${0##*/} alienFindCommand=\"alien_find /some/path/ file\" localPathPrefix=\${PWD}"
     echo
-    echo "by default files are downloaded to current dir, or \${alienSync_localPathPrefix} if set."
+    echo "by default files are downloaded to current dir, or \${alienSync_localPathPrefix}, if set."
     echo "At least specify alienFindCommand, either on command line or in the configFile."
+    echo "the logs go by default to localPathPrefix/alienSyncLogs"
     return
   fi
   
+  #be nice and allow group members access as well (002 will create dirs with 775 and files with 664)
+  umask 0002
+
   # try to load the config file
   #[[ ! -f $1 ]] && echo "config file $1 not found, exiting..." | tee -a $logFile && exit 1
   if ! parseConfig "$@"; then return 1; fi
@@ -44,12 +51,9 @@ main()
   echo ""|tee -a $logFile
   echo log: $logFile
   
-  #be nice and allow group members access as well (002 will create dirs with 775 and files with 664)
-  umask 0002
-
   #lock
   lockFile=$logOutputPath/runningNow.lock
-  [[ -f $lockFile ]] && echo "locked. Another process running? ($lockFile)" | tee -a $logFile && exit 1
+  [[ -f $lockFile && ${allowConcurrent} -ne 1 ]] && echo "locked. Another process running? ($lockFile)" | tee -a $logFile && exit 1
   touch $lockFile
   [[ ! -f $lockFile ]] && echo "unable to create lock. exiting..." | tee -a $logFile && exit 1
 
@@ -161,6 +165,12 @@ main()
     destinationdir=${destination%/*}
     [[ -n $softLinkName ]] && softlinktodestination=${destinationdir}/${softLinkName}
     tmpdestination="${destination}.aliensyncTMP"
+    
+    #if we allow concurrent running (DANGEROUS) check if somebody is already trying to process this file
+    if [[ -f ${tmpdestination} && ${allowConcurrent} -eq 1 ]]; then 
+      echo "$tmpdestination exists - concurrent donwload? skipping..."
+      continue
+    fi
 
     if [[ -n ${destinationModifyCommand} ]]; then
       #find the candidate in the database, in case there are more files trying to go to the same
@@ -226,7 +236,6 @@ main()
     #fi
     
     export copyMethod
-    export copyScript
     export copyTimeout
     export copyTimeoutHard
     echo copyFromAlien "$alienFile" "$tmpdestination"
@@ -290,9 +299,11 @@ main()
       continue
     fi
 
+    [[ -f $tmpdestination ]] && echo "WARNING: tmpdestination should not still be here! removing..." && rm -r ${tmpdestination}
+
     if [[ $unzipFiles -eq 1 ]]; then
-      echo unzip $tmpdestination -d $destinationdir
-      unzip $tmpdestination -d $destinationdir
+      echo unzip -o ${destination} -d ${destinationdir}
+      unzip -o ${destination} -d ${destinationdir}
     fi
 
     echo
@@ -334,11 +345,13 @@ main()
   
   [[ -n ${MAILTO} ]] && echo $logFile | mail -s "alienSync ${alienFindCommand} done" ${MAILTO}
 
-  echo
-  echo
-  echo '###############################'
-  echo "eval ${executeEnd}"
-  eval "${executeEnd}"
+  if [[ -n ${executeEnd} ]]; then
+    echo
+    echo
+    echo '###############################'
+    echo "eval ${executeEnd}"
+    eval "${executeEnd}"
+  fi
 
   exitScript 0
 }
@@ -492,11 +505,18 @@ copyFromAlien()
   dst=$2
   if [[ "$copyMethod" == "tfilecp" ]]; then
     if which timeout &>/dev/null; then
-      echo timeout $copyTimeout root -b -q "$copyScript(\"$src\",\"$dst\")"
-      timeout $copyTimeout root -b -q "$copyScript(\"$src\",\"$dst\")"
+      echo timeout $copyTimeout "TFile::Cp(\"$src\",\"$dst\")"
+      timeout $copyTimeout root -b <<EOF
+TGrid::Connect("alien://");
+TFile::Cp("${src}","${dst}");
+EOF
+
     else
-      echo root -b -q "$copyScript(\"$src\",\"$dst\")"
-      root -b -q "$copyScript(\"$src\",\"$dst\")"
+      echo "TFile::Cp(\"$src\",\"$dst\")"
+      root -b <<EOF
+TGrid::Connect("alien://");
+TFile::Cp("${src}","${dst}");
+EOF
     fi
   else
     if which timeout &>/dev/null; then
@@ -518,7 +538,6 @@ parseConfig()
   localPathPrefix="${PWD}"
   #define alienSync_localPathPrefix in your env to have a default central location
   [[ -n ${alienSync_localPathPrefix} ]] && localPathPrefix=${alienSync_localPathPrefix}
-  logOutputPath="${localPathPrefix}/alienSyncLogs"
   unzipFiles=0
   allOutputToLog=0
 
@@ -548,6 +567,10 @@ parseConfig()
     echo "${var} = ${value}"
     export ${var}="${value}"
   done
+
+  #things that by default depend on other variables should be set here, after the dependencies
+  [[ -z ${logOutputPath} ]] && logOutputPath="${localPathPrefix}/alienSyncLogs"
+  return 0
 }
 
 checkMD5sum()