Salome HOME
2f6167c9c3adac2d637b0f585f9adfbee63f4863
[modules/gui.git] / bin / runLightSalome.sh
1 #!/bin/bash -f
2
3 # Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24
25 ###
26 # function show_usage() : print help an exit
27 ###
28
29 show_usage()
30 {
31     echo
32     echo "Run standalone SALOME desktop".
33     echo
34     echo "Usage: $(basename ${0}) [options]"
35     echo
36     echo "Options:"
37     echo "-h, --help                       Print this information and exit."
38     echo "-v, --version                    Print SALOME version and exit."
39     echo "-m MODULES, --modules=MODULES    Comma-separated list of modules to be used within SALOME session."
40     echo "-r RCFILE, --resources=RCFILE    User preferences file to be used within SALOME session, instead of default one."
41     echo "-a LANGUAGE, --language=LANGUAGE Language to be used within SALOME session, instead of default one."
42     echo "-z, --no-splash                  Do not display splash screeen."
43     echo "-c, --no-exception-handler       Do not install exception handler (allows debugging exceptions)."
44     echo "-l, --show-license               Show license dialog at start-up."
45     echo
46     echo "Example:"
47     echo "  $(basename ${0}) --modules=LIGHT,PYLIGHT"
48     echo
49     exit 0
50 }
51
52 ###
53 # function show_version() : print SALOME version an exit
54 ###
55
56 show_version()
57 {
58     local where=$(readlink -f $(dirname "${0}"))
59     if [ -f ${where}/VERSION ]
60     then
61         cat ${where}/VERSION
62     else
63         echo
64         echo "Error: can't find VERSION file"  > /dev/stderr
65         echo
66         exit 1
67     fi
68     exit 0
69 }
70
71 ###
72 # function long_option() : extract value from long command line option
73 ###
74
75 long_option()
76 {
77     local option=${1}
78     local value=${2}
79
80     if [ $(echo ${value} | grep -e "^${option}=") ]
81     then
82         value=$(echo ${value} | sed -e "s%^${option}=%%")
83     else
84         value=
85     fi
86
87     if [ "${value}" = "" ]
88     then
89         echo "Error: please, specify value for option '--${option}'" > /dev/stderr
90         exit 1
91     fi
92
93     echo ${value}
94 }
95
96 ###
97 # function remove_duplications() : remove duplications
98 ###
99
100 remove_duplications()
101 {
102     local unique
103     local m
104     for m in ${@}
105     do
106         case ${m} in
107             KERNEL | GUI )
108                 ;;
109             * )
110                 echo ${unique} | grep -qvE "\<${m}\>" && unique+=" ${m}"
111                 ;;
112         esac
113     done
114     echo ${unique}
115 }
116
117
118 ###
119 # function run_light_salome(): run SALOME
120 ###
121
122 run_light_salome()
123 {
124     local modules
125     local rcfile
126     local language
127     local no_splash=0
128     local debug_exceptions=0
129     local show_license=0
130
131     ###
132     # process command line options
133     ###
134
135     local option
136     while getopts ":-:hvzclm:r:a:" option "${@}"
137     do
138         if [ "${option}" = "-" ]
139         then
140             case ${OPTARG} in
141                 help ) show_usage ;;
142                 version ) show_version ;;    
143                 no-splash ) no_splash=1 ;;
144                 no-exception-handler ) debug_exceptions=1 ;;
145                 show-license ) show_license=1 ;;
146                 modules* ) modules=$(long_option modules ${OPTARG}) ;;
147                 resources* ) rcfile=$(long_option resources ${OPTARG}) ;;
148                 language* ) language=$(long_option language ${OPTARG}) ;;
149                 * ) echo "Wrong option: --${OPTARG}" ; return 1 ;;
150             esac
151         else
152             case ${option} in
153                 h ) show_usage ;;
154                 v ) show_version ;;
155                 z ) no_splash=1 ;;
156                 c ) debug_exceptions=1 ;;
157                 l ) show_license=1 ;;
158                 m* ) modules=${OPTARG} ;;
159                 r* ) rcfile=${OPTARG} ;;
160                 a* ) language=${OPTARG} ;;
161                 ? ) echo "Wrong option" ; return 1 ;;
162             esac
163         fi
164     done
165     shift $((OPTIND - 1))
166
167     modules=$(echo ${modules} | sed -e "s%,% %g")
168
169     ###
170     # if modules aren't given in command line option, try to detect all available modules
171     ###
172
173     if [ "${modules}" = "" ]
174     then
175         local envvar
176         for envvar in $(env | awk -F= '{print $1}' | grep _ROOT_DIR)
177         do
178             local mdir=${!envvar}
179             local mname=$(echo ${envvar} | awk -F_ '{print $1}')
180             local mname_lc=$(echo ${mname} | tr 'A-Z' 'a-z')
181             if [ -f ${mdir}/share/salome/resources/${mname_lc}/LightApp.xml ] || [ -f ${mdir}/share/salome/resources/LightApp.xml ]
182             then
183                 modules+=" ${mname}"
184             fi
185         done
186     fi
187
188     ###
189     # remove duplications from modules list
190     ###
191
192     modules=$(remove_duplications ${modules})
193
194     ###
195     # set-up environment
196     ###
197
198     if [ "${LightAppResources}" = "" ]
199     then
200         export LightAppResources=${GUI_ROOT_DIR}/share/salome/resources/gui
201     else
202         export LightAppResources=${LightAppResources}:${GUI_ROOT_DIR}/share/salome/resources/gui
203     fi
204
205     local pyversion=$(python3 -c "import sys; print(sys.version[:3])" 2>/dev/null)
206     local my_path
207     local my_ld_library_path
208     local my_pythonpath
209
210     local m
211     for m in KERNEL GUI ${modules}
212     do
213         local root=${m}_ROOT_DIR
214         root=${!root}
215         if [ "${root}" != "" ]
216         then
217             local m_lc=$(echo ${m} | tr 'A-Z' 'a-z')
218             test -d ${root}/bin/salome && my_path+=:${root}/bin/salome
219             test -d ${root}/lib/salome && my_ld_library_path+=:${root}/lib/salome
220             if [ "${pyversion}" != "" ]
221             then
222                 test -d ${root}/bin/salome && my_pythonpath+=:${root}/bin/salome
223                 test -d ${root}/lib/salome && my_pythonpath+=:${root}/lib/salome
224                 test -d ${root}/lib/python${pyversion}/site-packages/salome && my_pythonpath+=:${root}/lib/python${pyversion}/site-packages/salome
225             fi
226             if [ -f ${root}/share/salome/resources/${m_lc}/LightApp.xml ]
227             then
228                 export LightAppConfig+=:${root}/share/salome/resources/${m_lc}
229             elif [ -f ${root}/share/salome/resources/LightApp.xml ]
230             then
231                 export LightAppConfig+=:${root}/share/salome/resources
232             fi
233             export SALOMEPATH+=:${root}
234         fi
235     done
236
237     PATH=${my_path}:${PATH}
238     PATH=$(echo ${PATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g")
239     export PATH
240     LD_LIBRARY_PATH=${my_ld_library_path}:${LD_LIBRARY_PATH}
241     LD_LIBRARY_PATH=$(echo ${LD_LIBRARY_PATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g")
242     export LD_LIBRARY_PATH
243     PYTHONPATH=${my_pythonpath}:${PYTHONPATH}
244     PYTHONPATH=$(echo ${PYTHONPATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g")
245     export PYTHONPATH
246     LightAppConfig=$(echo ${LightAppConfig} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g")
247     export LightAppConfig
248     SALOMEPATH=$(echo ${SALOMEPATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g")
249     export SALOMEPATH
250
251     ###
252     # start application
253     ###
254
255     local options="--modules=$(echo ${modules} | tr ' ' ',')"
256     test "${rcfile}" != "" && options+=" --resources=${rcfile}"
257     test "${language}" != "" && options+=" --language=${language}"
258     test "${no_splash}" = "1" && options+=" --no-splash"
259     test "${debug_exceptions}" = "1" && options+=" --no-exception-handler"
260     test "${show_license}" = "1" && options+=" --show-license"
261     suitexe LightApp ${options} "${@}"
262 }
263
264 ###
265 # call wrapper function (entry point)
266 ###
267
268 run_light_salome "${@}"