3 # This script installs a subset of products necessary for SALOME application
5 # Usage: install <target-directory> [all]
6 # install <target-directory> <product> ... <product>
8 # Type 'install --help' to get more information
11 # <target-directory> must be an absolute path
13 # The script is the part of the SALOME PRO installation procedure.
15 # Copyright : 2003 CEA/DEN, EDF R&D
16 ####################################################################################
19 export SHRC="salome.sh"
20 export CSHRC="salome.csh"
23 #this function takes several parameters
24 #first parameter contains descriptor of output file
25 #next parameters is command for execution
26 #in case of bad result of execution ask user about furher steps
27 #(user can cancel installation procedure)
32 echo -e "`pwd` -> $* >> $out"
33 if [ $DEBUG == 0 ] ; then
36 if [ $out == "1" ] ; then
42 if [ "$?" -ne "0" ] ; then
43 if [ $out != "1" ] ; then
46 # VSR : 10/11/05: disable answer mode ==>
48 #echo -e "NOT DONE !!! => $*"
49 #echo -n "Would you like to continue to install this product: (Y,N) [Y] : "
51 #rep=`echo $rep | tr "[A-Z]" "[a-z]"`
52 #if test -z $rep || [ $rep = "y" ] ; then
55 # VSR : 10/11/05: disable answer mode <==
61 #invoke check_job function
62 #all output will be put into terminal
72 rm -rf "$1" > /dev/null
76 #create environment for sh and csh
79 install_root=$1; shift
81 for i in $SHRC $CSHRC ; do
82 if [ -e ${install_work}/$i ]; then
85 touch ${install_work}/$i
88 if [ $# -eq 3 ] ; then
90 product_env=${install_work}/env_${product_name}.sh
91 (test -e ${product_env} && rm ${product_env} )
93 ### !!! writing salome.sh file !!! -> define INSTALL_ROOT
94 cat >> ${install_work}/$SHRC <<EOF
95 #${DELIM} Setting products installation directory ${DELIM}
96 export INSTALL_ROOT=${install_root}
98 #${DELIM} Environment switch: 0 for SALOME building, 1 for SALOME launching ${DELIM}
99 export ENV_FOR_LAUNCH=1
102 ### !!! The next is for RedHat 9 only !!!
103 if [ -f /etc/redhat-release ] ; then
104 grep -e "Red Hat Linux release 9" /etc/redhat-release > /dev/null
105 if [ $? -eq 0 ] ; then
106 cat >> ${install_work}/$SHRC <<EOF
107 #${DELIM} Force RH9 to use old implementation of threads ${DELIM}
108 export LD_ASSUME_KERNEL=2.4.18
113 ### !!! writing salome.csh file !!! -> set inital variables
114 pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
115 for i in $pre_vars ; do
116 cat >> ${install_work}/$CSHRC <<EOF
117 #${DELIM} setting initial ${i} ${DELIM}
118 if (! (\$?${i}) ) then
125 ### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|p)' where necessary
126 ### Note, that for performance reasons temporary environment files used during installation procedure itself
127 ### are created without using setenv(a|p) aliases.
129 # 1. first dump all environment files into the $SHRC file
130 product_sequence="$2"
131 for i in $product_sequence ; do
132 cat ${install_work}/env_${i}.sh >> ${install_work}/$SHRC 2>/dev/null
135 # 2. writing global functions to _salome.sh file
136 cat >> ${install_work}/_$SHRC <<EOF
137 ##########################################################################
138 # Functions exporta and exportp are used to append/prepend correspondingly
139 # one directory or a set of directories separated by semicolon symbol (':')
140 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
142 # The main purpose is to replace default setenv command behavior:
143 # exporta, exportp also remove duplicated entries, shortening in that way
144 # the environment variables.
145 # If some directory being added is already included into the variable
146 # nothing is done for it.
147 # Note, that these functions work some slower that setenv command itself.
150 # appends/prepends set of directories (second parameter)
151 # to the another set of directories (first parameter) and
152 # removes duplicated entries;
153 # the third parameter defines the mode: 0 - append, 1 - prepend
155 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{ \\
156 na = split(\$2,a,":"); \\
157 if ( \$1 == "<empty>") nb = split("",b,":"); \\
158 else nb = split(\$1,b,":"); \\
160 for(i=1;i<=nb;i++) { \\
161 if(!(b[i] in ccc)) { \\
163 s = sprintf("%s:",s); \\
164 s = sprintf("%s%s",s,b[i]); \\
169 for(i=1;i<=na;i++) { \\
170 if(!(a[i] in ccc)) { \\
172 s1 = sprintf("%s:",s1); \\
173 s1 = sprintf("%s%s",s1,a[i]); \\
178 s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\
180 s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\
186 # appends directory or set of directories, separated by ':' (second parameter)
187 # to the variable (first parameter)
189 xenv=\`printenv \$1\`
190 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
191 out_var=\`cleandup \$xenv \$2 0\`
195 # prepends directory or set of directories, separated by ':' (second parameter)
196 # to the variable (first parameter)
198 xenv=\`printenv \$1\`
199 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
200 out_var=\`cleandup \$xenv \$2 1\`
203 ###########################################################################
207 # 3. writing global functions to _salome.csh file
208 cat >> ${install_work}/_$CSHRC <<EOF
209 ###########################################################################
210 # Aliases setenva and setenvp are used to append/prepend correspondingly
211 # one directory or a set of directories separated by semicolon symbol (':')
212 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
214 # The main purpose is to replace default setenv command behavior:
215 # setenva, setenvp also remove duplicated entries, shortening in that way
216 # the environment variables.
217 # If some directory being added is already included into the variable
218 # nothing is done for it.
219 # Note, that these aliases work some slower that setenv command itself.
222 # appends/prepends set of directories (second parameter)
223 # to the another set of directories (first parameter) and
224 # removes duplicated entries;
225 # the third parameter defines the mode: 0 - append, 1 - prepend
226 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3 \\\\
227 '"'{ na = split(\$2,a,":"); \\\\
228 nb = split(\$1,b,":"); \\\\
230 for(i=1;i<=nb;i++) { \\\\
231 if(!(b[i] in ccc)) { \\\\
232 if(length(s)!=0) \\\\
233 s = sprintf("%s:",s); \\\\
234 s = sprintf("%s%s",s,b[i]); \\\\
239 for(i=1;i<=na;i++) { \\\\
240 if(!(a[i] in ccc)) { \\\\
241 if(length(s1)!=0) \\\\
242 s1 = sprintf("%s:",s1); \\\\
243 s1 = sprintf("%s%s",s1,a[i]); \\\\
248 s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\\\
250 s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\\\
251 printf("%s\n",s); \\\\
254 # appends directory or set of directories, separated by ':' (second parameter)
255 # to the variable (first parameter)
256 alias setenva 'set a=\!:1 ; set b=\!:2 ; \\
257 set c=\`printenv \$a\` ; \\
258 set b=\`cleandup \$c \$b 0\` ; \\
263 # prepends directory or set of directories, separated by ':' (second parameter)
264 # to the variable (first parameter)
265 alias setenvp 'set a=\!:1 ; set b=\!:2 ; \\
266 set c=\`printenv \$a\` ; \\
267 set b=\`cleandup \$c \$b 1\` ; \\
270 ###########################################################################
273 cat ${install_work}/$CSHRC >> ${install_work}/_$CSHRC
275 # 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
276 sed -e 's%export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%exporta\1PATH \2%g' -e 's%export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%exportp\1PATH \2%g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
277 sed -e 's%export\([[:blank:]]*\)LD_LIBRARY_PATH=\$[{]\?LD_LIBRARY_PATH[}]\?:\(.*\)%exporta\1LD_LIBRARY_PATH \2%g' -e 's%export\([[:blank:]]*\)LD_LIBRARY_PATH=\(.*\):\$[{]\?LD_LIBRARY_PATH[}]\?%exportp\1LD_LIBRARY_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
278 sed -e 's%export\([[:blank:]]*\)PYTHONPATH=\$[{]\?PYTHONPATH[}]\?:\(.*\)%exporta\1PYTHONPATH \2%g' -e 's%export\([[:blank:]]*\)PYTHONPATH=\(.*\):\$[{]\?PYTHONPATH[}]\?%exportp\1PYTHONPATH \2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
279 sed -e 's%export\([[:blank:]]*\)LD_RUN_PATH=\$[{]\?LD_RUN_PATH[}]\?:\(.*\)%exporta\1LD_RUN_PATH \2%g' -e 's%export\([[:blank:]]*\)LD_RUN_PATH=\(.*\):\$[{]\?LD_RUN_PATH[}]\?%exportp\1LD_RUN_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2
280 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$SHRC
282 # 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
283 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
284 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC
286 # 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
287 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
288 sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
289 sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
290 sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
291 sed -e 's%if \[ "\${ENV_FOR_LAUNCH}" == "1" \] ; then%if ( "\${ENV_FOR_LAUNCH}" == "1" ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
292 sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
293 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$CSHRC 2>/dev/null
295 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
297 if [ $# -eq 4 ] ; then
299 if [ -e ${product_dir} ] ; then
300 cp -f ${install_work}/_$SHRC ${product_dir}/$SHRC
301 cp -f ${install_work}/_$CSHRC ${product_dir}/$CSHRC
304 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_build.csh
305 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC > ${install_root}/env_build.sh
306 cp -f ${install_work}/_$CSHRC ${install_root}/env_products.csh
307 cp -f ${install_work}/_$SHRC ${install_root}/env_products.sh
308 rm -f ${install_work}/_$SHRC ${install_work}/_$CSHRC
309 ### !!! copying build.csh script
310 if [ -e ./build.csh ]; then
311 cp -f ./build.csh ${install_root}
315 #try use already existing product
318 product_dir=$1; install_root=$2; install_work=$3; product_sequence="$4"; product_type=$5
319 env_file=${product_dir}/env_${product_type}.sh
320 if [ -f ${env_file} ] ; then
321 cp -f ${env_file} ${install_work}
322 make_env ${install_root} ${install_work} "${product_sequence}"
323 source ${install_work}/$SHRC
325 if [ $? -eq 0 ] ; then
326 if [ -d ${product_dir} ] && [ -w ${product_dir} ] ; then
327 #makedir ${product_dir}
336 #check existance of lib passed as first parameter
337 #return 0 if lib exists
338 #if you pass second parameter search will be done in it
339 #otherwise search will be done in $LD_LIBRARY_PATH
340 #you should use : as dilimeter if you are going to pass second parameter
345 whereIs=$LD_LIBRARY_PATH
347 for L in `echo ${whereIs} | sed -e"s%:% %g"` ; do
348 ret=`find $L -name $1 2>/dev/null`
349 if [ -n "$ret" ] ; then
350 #echo "The $1 exists on yours system in a $L folder"
360 for i in `echo ${path} | sed -e"s%:% %g"` ; do
361 ret=`find $i -name $file 2>/dev/null`
362 if [ -n "$ret" ] ; then
363 ret=`echo $ret | sed -e"s%/\$file$%%g"`
372 arg1=$1; val1=$2; arg2=$3; val2=$4
373 tmp="^$val1$|^$val1:|:$val1$|:$val1:"
374 #echo $val2 | grep -E "$tmp" >/dev/null 2>&1
375 #if [ $? -eq 0 ] ; then
380 exclude_list="usr lib bin sbin etc"
381 for i in ${exclude_list} ; do
383 echo ${val1} | grep -E "$tmp" >/dev/null 2>&1
384 if [ $? == 0 ] ; then to_tail=0; break; fi
386 if [ $to_tail -eq 0 ] ; then
395 if test -z "${TCLHOME}"; then
398 tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
402 ver=`cat $f | grep -e "TCL_VERSION=.*" | sed -e "s%TCL_VERSION=[\'|\"]\(.*\)[\'|\"]%\1%g" | awk -F. '{x=0;for(i=1;i<=3;i++){x=x*100;if(i<=NF)x+=$i;}print x;}'`
403 if [ $maxver -lt $ver ]; then
408 if test -n "$file"; then
418 if test -z "${TCLHOME}"; then
421 tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
425 ver=`cat $f | grep -e "TK_VERSION=.*" | sed -e "s%TK_VERSION=[\'|\"]\(.*\)[\'|\"]%\1%g" | awk -F. '{x=0;for(i=1;i<=3;i++){x=x*100;if(i<=NF)x+=$i;}print x;}'`
426 if [ $maxver -lt $ver ]; then
431 if test -n "$file"; then
442 if [ -z "$ldir" ] || [ ! -d "$ldir" ]; then return 1; fi
446 SALOME_MODULES="`env | awk -F_ '/[[:alnum:]]*_ROOT_DIR/ { print $1 }'`"
449 la_files=`find . -name "*.la" -maxdepth 1`
451 for l in X ${la_files}; do
452 if [ "$l" != "X" ] ; then
454 # 1. process salome modules dependencies
455 for mod in $SALOME_MODULES; do
456 moddir=`printenv ${mod}_ROOT_DIR`
457 if [ -n "${moddir}" ] ; then
458 #echo $l $mod $moddir
459 sed -e "s%-L[^[:space:]]*${mod}[^[:space:]]*/lib/salome%-L${moddir}/lib/salome%g" $l > _$l
463 # 2. process CAS.CADE dependencies
464 casdir=`printenv CASROOT`/lib
465 if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/Linux/lib ; fi
466 if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/lin/lib ; fi
467 if [ -n "${CASROOT}" ] && [ -d "${casdir}" ] ; then
468 # echo $l $CASROOT $casdir
469 sed -e "s%-L[^[:space:]]*\(OCT\|CAS\)[^[:space:]]*%-L${casdir}%g" $l > _$l
472 # 3. process omniORB dependencies
473 omnidir=`printenv OMNIORBDIR`/lib/i586_linux_2.0_glibc2.1
474 if [ ! -d ${omnidir} ] ; then omnidir=`printenv OMNIORBDIR`/lib ; fi
475 if [ -n "${OMNIORBDIR}" ] && [ -d "${omnidir}" ] ; then
476 # echo $l $OMNIORBDIR $omnidir
477 sed -e "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g" $l > _$l
480 # 4. process VTK dependencies
481 vtkdir=`printenv VTKHOME`/lib/vtk
482 if [ -n "${VTKHOME}" ] && [ -d "${vtkdir}" ] ; then
483 # echo $l $VTKHOME $vtkdir
484 sed -e "s%-L[^[:space:]]*VTK[^[:space:]]*/lib/vtk%-L${vtkdir}%g" $l > _$l
487 # 5. process HDF dependencies
488 hdfdir=`printenv HDF5HOME`/lib
489 if [ -n "${HDF5HOME}" ] && [ -d "${hdfdir}" ] ; then
490 # echo $l $HDF5HOME $hdfdir
491 sed -e "s%-L[^[:space:]]*hdf[^[:space:]]*/lib%-L${hdfdir}%g" $l > _$l
494 # 6. process MED dependencies
495 meddir=`printenv MED2HOME`/lib
496 if [ -n "${MED2HOME}" ] && [ -d "${meddir}" ] ; then
497 # echo $l $MED2HOME $meddir
498 sed -e "s%-L[^[:space:]]*med[^[:space:]]*/lib%-L${meddir}%g" $l > _$l
501 # 7. process qwt dependencies
502 qwtdir=`printenv QWTHOME`/lib
503 if [ -n "${QWTHOME}" ] && [ -d "${qwtdir}" ] ; then
504 # echo $l $QWTHOME $qwtdir
505 sed -e "s%-L[^[:space:]]*qwt[^[:space:]]*/lib%-L${qwtdir}%g" $l > _$l
508 # 8. process qt dependencies
509 qtdir=`printenv QTDIR`/lib
510 if [ -n "${QTDIR}" ] && [ -d "${qtdir}" ] ; then
511 # echo $l $QTDIR $qtdir
512 sed -e "s%-L[^[:space:]]*qt[^[:space:]]*/lib%-L${qtdir}%g" $l > _$l
515 # 9. process python dependencies
516 where_python=`which python` # e.g. /usr/bin/python
517 if [ -n "$where_python" ] ; then
518 where_python=`dirname $where_python` # --> /usr/bin
519 where_python=`dirname $where_python` # --> /usr
520 python_version=`python -c "import sys; print sys.version[:3]"`
521 # echo $l $where_python $python_version
522 sed -e "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${where_python}/lib/python${python_version}\1%g" $l > _$l
525 # 10. process sip dependencies
526 sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
527 if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
529 sed -e "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" $l > _$l
532 # 11. process PyQt dependencies
533 pyqtdir=`find_in_path qt.so ${LD_LIBRARY_PATH}`
534 if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
536 sed -e "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" $l > _$l
539 # 12. process tcl/tk dependencies
540 tcldir=`printenv TCLHOME`/lib
541 if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
542 # echo $l $TCLHOME $tcldir
543 sed -e "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" $l > _$l
547 sed -e "s%^libdir='\(.*\)'%libdir='${PRODUCT_DIR}/lib/salome'%g" $l > _$l