Salome HOME
Rollback previous integration
[modules/kernel.git] / bin / appliskel / runRemote.sh
1 #!/bin/bash
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, 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.
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 # --- run command in SALOME environment from remote call, ssh or rsh
24 #     - SALOME configuration is defined by :
25 #        - list of MODULE_ROOT_DIR
26 #        - prerequisite environment
27 #        - specific configuration for a particular SALOME application
28 #     - These elements of configuration are defined locally on each computer
29 #       in the directory APPLI:
30 #     - A SALOME application distributed on several computers needs APPLI
31 #       directories on the same path ($APPLI) relative to $HOME directory
32 #       of the user, on each computer.
33 # --- call example (from cli76cd to cli76ce):
34 # ssh cli76ce ${APPLI}/runRemote.sh cli76cd 2810 SALOME_Container myContainerName
35 # --- local arguments
36 #     $0 : ${APPLI}/runRemote.sh: from arg name, rebuild and export $APPLI variable
37 #     $1 : computer name for CORBA name service (where SALOME was launched)
38 #     $2 : port for CORBA name service
39 #     $3 : WORKINGDIR (if $3 == WORKINDIR a working dir is given in $4. If not the working dir is $HOME)
40 #     $4 : if $3 == WORKINGDIR, the path to the workingdir
41 #     $5 (or $3 if no workingdir given) and following : local command to execute, with args
42 # --- retrieve APPLI path, relative to $HOME, set ${APPLI}
43 #
44 APPLI_HOME=`dirname $0`
45 export APPLI=`${APPLI_HOME}/getAppliPath.py`
46
47 # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...)
48
49 . ${HOME}/${APPLI}/envd ${HOME}/${APPLI}
50
51 # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
52
53 OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_$1_$2.cfg
54 export OMNIORB_CONFIG
55 NSHOST=$1
56 export NSHOST
57 NSPORT=$2
58 export NSPORT
59 initref="NameService=corbaname::"$1":$2"
60 echo "InitRef = $initref" > $OMNIORB_CONFIG
61
62 #go to the requested working directory if any
63 if test "x$3" == "xWORKINGDIR"; then
64   if test "x$4" = "x\$TEMPDIR"; then
65     #create a temp working dir and change to it
66     WDIR=`mktemp -d` && {
67       cd $WDIR
68     }
69   else
70     if test -d $4; then
71       #the dir exists, go to it
72       cd $4
73     else
74       if test -a $4; then
75         # It's a file do nothing
76         echo $4 "is an existing file. Can't use it as a working directory"
77       else
78         #It does not exists, create it
79         mkdir -p $4 && {
80           cd $4
81         }
82       fi
83     fi
84   fi
85   shift 4
86 else
87   shift 2
88 fi
89
90 # --- execute the command in the SALOME environment
91
92
93 # suppress --rcfile option because of problem on Mandriva2006 - B Secher mai 2007
94 #${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/sh --rcfile $HOME/$APPLI/.bashrc -c "$*"
95 ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/sh -c "$*"