From 5af19857dae602974dc68dd4ed68b2b709e06e05 Mon Sep 17 00:00:00 2001
From: aschwinn <al.schwinn@gsi.de>
Date: Fri, 29 Jul 2016 16:20:55 +0200
Subject: [PATCH] fixed return/exit chaos

---
 silecs-communication-cpp/releaseSilecs.sh | 47 ++++++++++++++++-------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/silecs-communication-cpp/releaseSilecs.sh b/silecs-communication-cpp/releaseSilecs.sh
index 999031f..22fcb5e 100755
--- a/silecs-communication-cpp/releaseSilecs.sh
+++ b/silecs-communication-cpp/releaseSilecs.sh
@@ -1,6 +1,3 @@
-#!/bin/sh
-set -e
-
 # Usage examples:
 # first you need to source this script, so that you can use it's methods:
 # $ source releaseSilecs.sh
@@ -18,12 +15,24 @@ set -e
 # List of silecs packages which is released or patched
 PACKAGES="silecs-codegen silecs-model silecs-communication-cpp silecs-diagnostic-cpp snap7"
 
+# Check that folder exists, print proper error if not
+checkFolderExists()
+{
+    FOLDER=$1
+    if [ ! -d ${FOLDER} ]; then
+        echo "Error: The folder '${FOLDER}' is needed in order to finish the installation."
+        echo "Installation cancelled."
+        exit 1
+    fi
+}
+
 # releases all silecs-packages to release-dir
-function release
+release()
 {
     VERSION=$1
     RELEASE_DIR_BASE=$2
     WORKSPACE=$3
+    checkFolderExists ${WORKSPACE}
     
     for PACKAGE in $PACKAGES; do
         INSTALL_DIR=${RELEASE_DIR_BASE}/${PACKAGE}/${VERSION}
@@ -31,6 +40,7 @@ function release
             echo "Error: Silecs version ${VERSION} is already installed in ${INSTALL_DIR}. Exiting now."
             return 1
         else
+            checkFolderExists ${WORKSPACE}/${PACKAGE}
             echo "installing ${INSTALL_DIR} from ${WORKSPACE}/${PACKAGE}"
             ${WORKSPACE}/${PACKAGE}/install.sh ${INSTALL_DIR}
         fi
@@ -38,40 +48,49 @@ function release
     return 0
 }
 
-function plugin_release
+plugin_release()
 {
-    RELEASE_DIR_BASE=$1
-    WORKSPACE=$2
-    PACKAGE=silecs-eclipse-plugin-update-site
-    INSTALL_DIR=${RELEASE_DIR_BASE}/${PACKAGE}
-    echo "installing ${INSTALL_DIR} from ${WORKSPACE}/${PACKAGE}"
-    ${WORKSPACE}/${PACKAGE}/install.sh ${INSTALL_DIR}
+    (
+        set -e
+        RELEASE_DIR_BASE=$1
+        WORKSPACE=$2
+        PACKAGE=silecs-eclipse-plugin-update-site
+        INSTALL_DIR=${RELEASE_DIR_BASE}/${PACKAGE}
+        checkFolderExists ${WORKSPACE}/${PACKAGE}
+        echo "installing ${INSTALL_DIR} from ${WORKSPACE}/${PACKAGE}"
+        ${WORKSPACE}/${PACKAGE}/install.sh ${INSTALL_DIR}
+        return 0
+    )
 }
     
 # releases a specific package to release-dir. For all other packages symlinks to the base-version are generated
-function patch
+patch()
 {
     PACKAGE_TO_PATCH=$1
     NEW_VERSION=$2
     BASE_VERSION=$3
     RELEASE_DIR_BASE=$4
     WORKSPACE=$5
+    checkFolderExists ${WORKSPACE}
 
     for PACKAGE in $PACKAGES; do
         INSTALL_DIR=${RELEASE_DIR_BASE}/${PACKAGE}/${NEW_VERSION}
         BASE_DIR=${RELEASE_DIR_BASE}/${PACKAGE}/${BASE_VERSION}
+        checkFolderExists ${BASE_DIR}
         if [ "$PACKAGE" == "$PACKAGE_TO_PATCH" ]; then
             if [ -d ${INSTALL_DIR} ]; then
-               if [ -L ${INSTALL_DIR} ]; then 
+               if [ -L ${INSTALL_DIR} ]; then
+                  checkFolderExists ${WORKSPACE}/${PACKAGE}
                   # Replace Sym-Link with patch-version ... needed if more than one package is patched for the same version
                   unlink ${INSTALL_DIR}
-                  echo "installing ${INSTALL_DIR} from ${WORKSPACE}/${PACKAGE}"
+                  checkFolderExists ${WORKSPACE}/${PACKAGE}
                   ${WORKSPACE}/${PACKAGE}/install.sh ${INSTALL_DIR}
                else
                   echo "Error: Silecs version ${NEW_VERSION} of package ${PACKAGE} is already installed in ${INSTALL_DIR}. Exiting now."
                   return 1
                fi
             else
+               checkFolderExists ${WORKSPACE}/${PACKAGE}
                echo "installing ${INSTALL_DIR} from ${WORKSPACE}/${PACKAGE}"
                ${WORKSPACE}/${PACKAGE}/install.sh ${INSTALL_DIR}
             fi
-- 
GitLab