Salome HOME
updated copyright message
[modules/kernel.git] / bin / appliskel / runRemoteSSL.sh
1 #!/bin/bash
2 # Copyright (C) 2021-2023  CEA, EDF
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 #     --noenvd : optional argument. If present, the envd file is NOT sourced.
36 #     $1 : IOR_OF_CURSTOM_NS of reference to Engines::EmbeddedNamingService servant
37 #     $2 : WORKINGDIR (if $2 == WORKINDIR a working dir is given in $3. If not the working dir is $HOME)
38 #     $3 : if $2 == WORKINGDIR, the path to the workingdir
39 #     $4 (or $2 if no workingdir given) and following : local command to execute, with args
40 # --- retrieve APPLI path, relative to $HOME, set ${APPLI}
41
42 APPLI_HOME=$(dirname "$0")
43 export APPLI=$("${APPLI_HOME}/getAppliPath.py")
44
45 # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...)
46 # Sourcing files with parameters works with bash, not with dash. This is why
47 # we must use bash for this script.
48
49 if [ "$1" == "--noenvd" ]
50 then
51   shift
52 else
53   . "${HOME}/${APPLI}/envd" "${HOME}/${APPLI}"
54 fi
55
56 #go to the requested working directory if any
57 if test "x$2" == "xWORKINGDIR"; then
58   if test "x$3" = "x\$TEMPDIR"; then
59     #create a temp working dir and change to it
60     WDIR=$(mktemp -d) && {
61       cd "$WDIR"
62     }
63   else
64     if test -d "$3"; then
65       #the dir exists, go to it
66       cd "$3"
67     else
68       if test -a "$3"; then
69         # It's a file do nothing
70         echo "$3 is an existing file. Can't use it as a working directory"
71       else
72         #It does not exists, create it
73         mkdir -p "$3" && {
74           cd "$3"
75         }
76       fi
77     fi
78   fi
79   shift 3
80 else
81   shift 1
82 fi
83
84 # --- execute the command in the SALOME environment
85
86 "${KERNEL_ROOT_DIR}/bin/salome/envSalome.py" /bin/sh -c "$* "