Salome HOME
ff81b9e66c3a2d7cccee36921e88d74fb83c443c
[modules/kernel.git] / bin / appliskel / runRemoteSSL.sh
1 #!/bin/bash
2 # Copyright (C) 2021  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # --- run command in SALOME environment from remote call, ssh or rsh
22 #     - SALOME configuration is defined by :
23 #        - list of MODULE_ROOT_DIR
24 #        - prerequisite environment
25 #        - specific configuration for a particular SALOME application
26 #     - These elements of configuration are defined locally on each computer
27 #       in the directory APPLI:
28 #     - A SALOME application distributed on several computers needs APPLI
29 #       directories on the same path ($APPLI) relative to $HOME directory
30 #       of the user, on each computer.
31 # --- call example (from cli76cd to cli76ce):
32 # ssh cli76ce ${APPLI}/runRemoteSSL.sh IOR_OF_CURSTOM_NS SALOME_Container myContainerName
33 # --- local arguments
34 #     $0 : ${APPLI}/runRemote.sh: from arg name, rebuild and export $APPLI variable
35 #     $1 : IOR_OF_CURSTOM_NS of reference to Engines::EmbeddedNamingService servant
36 #     $2 : WORKINGDIR (if $2 == WORKINDIR a working dir is given in $3. If not the working dir is $HOME)
37 #     $3 : if $2 == WORKINGDIR, the path to the workingdir
38 #     $4 (or $2 if no workingdir given) and following : local command to execute, with args
39 # --- retrieve APPLI path, relative to $HOME, set ${APPLI}
40
41 APPLI_HOME=$(dirname "$0")
42 export APPLI=$("${APPLI_HOME}/getAppliPath.py")
43
44 # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...)
45 # Sourcing files with parameters works with bash, not with dash. This is why
46 # we must use bash for this script.
47
48 . "${HOME}/${APPLI}/envd" "${HOME}/${APPLI}"
49
50 # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
51 export CUSTOM_NS_IOR=$1
52
53 #go to the requested working directory if any
54 if test "x$2" == "xWORKINGDIR"; then
55   if test "x$3" = "x\$TEMPDIR"; then
56     #create a temp working dir and change to it
57     WDIR=$(mktemp -d) && {
58       cd "$WDIR"
59     }
60   else
61     if test -d "$3"; then
62       #the dir exists, go to it
63       cd "$3"
64     else
65       if test -a "$3"; then
66         # It's a file do nothing
67         echo "$3 is an existing file. Can't use it as a working directory"
68       else
69         #It does not exists, create it
70         mkdir -p "$3" && {
71           cd "$3"
72         }
73       fi
74     fi
75   fi
76   shift 3
77 else
78   shift 1
79 fi
80
81 # --- execute the command in the SALOME environment
82
83 "${KERNEL_ROOT_DIR}/bin/salome/envSalome.py" /bin/sh -c "$* $CUSTOM_NS_IOR"