Salome HOME
updated copyright message
[modules/kernel.git] / bin / appliskel / runRemote.sh
1 #!/bin/bash
2 # Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 # --- run command in SALOME environment from remote call, ssh or rsh
25 #     - SALOME configuration is defined by :
26 #        - list of MODULE_ROOT_DIR
27 #        - prerequisite environment
28 #        - specific configuration for a particular SALOME application
29 #     - These elements of configuration are defined locally on each computer
30 #       in the directory APPLI:
31 #     - A SALOME application distributed on several computers needs APPLI
32 #       directories on the same path ($APPLI) relative to $HOME directory
33 #       of the user, on each computer.
34 # --- call example (from cli76cd to cli76ce):
35 # ssh cli76ce ${APPLI}/runRemote.sh cli76cd 2810 SALOME_Container myContainerName
36 # --- local arguments
37 #     $0 : ${APPLI}/runRemote.sh: from arg name, rebuild and export $APPLI variable
38 #     --noenvd : optional argument. If present, the envd file is NOT sourced.
39 #     $1 : computer name for CORBA name service (where SALOME was launched)
40 #     $2 : port for CORBA name service
41 #     $3 : WORKINGDIR (if $3 == WORKINDIR a working dir is given in $4. If not the working dir is $HOME)
42 #     $4 : if $3 == WORKINGDIR, the path to the workingdir
43 #     $5 (or $3 if no workingdir given) and following : local command to execute, with args
44
45 # --- retrieve APPLI path, relative to $HOME, set ${APPLI}
46
47 APPLI_HOME=$(dirname "$0")
48 export APPLI=$("${APPLI_HOME}/getAppliPath.py")
49
50 # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...)
51 # Sourcing files with parameters works with bash, not with dash. This is why
52 # we must use bash for this script.
53
54 if [ "$1" == "--noenvd" ]
55 then
56   shift
57 else
58   . "${HOME}/${APPLI}/envd" "${HOME}/${APPLI}"
59 fi
60
61 # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
62 export NSHOST=$1
63 export NSPORT=$2
64
65 #go to the requested working directory if any
66 if test "x$3" == "xWORKINGDIR"; then
67   if test "x$4" = "x\$TEMPDIR"; then
68     #create a temp working dir and change to it
69     WDIR=$(mktemp -d) && {
70       cd "$WDIR"
71     }
72   else
73     if test -d "$4"; then
74       #the dir exists, go to it
75       cd "$4"
76     else
77       if test -a "$4"; then
78         # It's a file do nothing
79         echo "$4 is an existing file. Can't use it as a working directory"
80       else
81         #It does not exists, create it
82         mkdir -p "$4" && {
83           cd "$4"
84         }
85       fi
86     fi
87   fi
88   shift 4
89 else
90   shift 2
91 fi
92
93 # Get (in bash) the configuration filename from (Python) ORBConfigFile return values
94 RETURN_VALUES=$("${KERNEL_ROOT_DIR}/bin/salome/envSalome.py" python "${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py" "${OMNIORB_USER_PATH}" "${NSHOST}" "${NSPORT}" "with_username=${USER}")
95 export OMNIORB_CONFIG=$(echo "${RETURN_VALUES}" | cut -d' ' -f1)
96
97 # --- execute the command in the SALOME environment
98
99
100 # suppress --rcfile option because of problem on Mandriva2006 - B Secher mai 2007
101 #${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/sh --rcfile $HOME/$APPLI/.bashrc -c "$*"
102 "${KERNEL_ROOT_DIR}/bin/salome/envSalome.py" /bin/sh -c "$*"