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
47 echo -e "NOT DONE !!! => $*"
48 echo -n "Would you like to continue to install this product: (Y,N) [Y] : "
50 rep=`echo $rep | tr "[A-Z]" "[a-z]"`
51 if test -z $rep || [ $rep = "y" ] ; then
59 #invoke check_job function
60 #all output will be put into terminal
70 rm -rf "$1" > /dev/null
74 #create environment for sh and csh
77 install_root=$1; shift
79 for i in $SHRC $CSHRC ; do
80 if [ -e ${install_work}/$i ]; then
83 touch ${install_work}/$i
86 if [ $# -eq 3 ] ; then
88 product_env=${install_work}/env_${product_name}.sh
89 (test -e ${product_env} && rm ${product_env} )
91 ### !!! writing salome.sh file !!! -> define INSTALL_ROOT
92 cat >> ${install_work}/$SHRC <<EOF
93 #${DELIM} Setting products installation directory ${DELIM}
94 export INSTALL_ROOT=${install_root}
96 #${DELIM} Environment switch: 0 for SALOME building, 1 for SALOME launching ${DELIM}
97 export ENV_FOR_LAUNCH=1
100 ### !!! The next is for RedHat 9 only !!!
101 if [ -f /etc/redhat-release ] ; then
102 grep -e "Red Hat Linux release 9" /etc/redhat-release > /dev/null
103 if [ $? -eq 0 ] ; then
104 cat >> ${install_work}/$SHRC <<EOF
105 #${DELIM} Force RH9 to use old implementation of threads ${DELIM}
106 export LD_ASSUME_KERNEL=2.4.18
111 ### !!! writing salome.csh file !!! -> set inital variables
112 pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
113 for i in $pre_vars ; do
114 cat >> ${install_work}/$CSHRC <<EOF
115 #${DELIM} setting initial ${i} ${DELIM}
116 if (! (\$?${i}) ) then
123 ### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|p)' where necessary
124 ### Note, that for performance reasons temporary environment files used during installation procedure itself
125 ### are created without using setenv(a|p) aliases.
127 # 1. first dump all environment files into the $SHRC file
128 product_sequence="$2"
129 for i in $product_sequence ; do
130 cat ${install_work}/env_${i}.sh >> ${install_work}/$SHRC 2>/dev/null
133 # 2. writing global functions to _salome.sh file
134 cat >> ${install_work}/_$SHRC <<EOF
135 ##########################################################################
136 # Functions exporta and exportp are used to append/prepend correspondingly
137 # one directory or a set of directories separated by semicolon symbol (':')
138 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
140 # The main purpose is to replace default setenv command behavior:
141 # exporta, exportp also remove duplicated entries, shortening in that way
142 # the environment variables.
143 # If some directory being added is already included into the variable
144 # nothing is done for it.
145 # Note, that these functions work some slower that setenv command itself.
148 # appends/prepends set of directories (second parameter)
149 # to the another set of directories (first parameter) and
150 # removes duplicated entries;
151 # the third parameter defines the mode: 0 - append, 1 - prepend
153 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{ \\
154 na = split(\$2,a,":"); \\
155 if ( \$1 == "<empty>") nb = split("",b,":"); \\
156 else nb = split(\$1,b,":"); \\
158 for(i=1;i<=nb;i++) { \\
159 if(!(b[i] in ccc)) { \\
161 s = sprintf("%s:",s); \\
162 s = sprintf("%s%s",s,b[i]); \\
167 for(i=1;i<=na;i++) { \\
168 if(!(a[i] in ccc)) { \\
170 s1 = sprintf("%s:",s1); \\
171 s1 = sprintf("%s%s",s1,a[i]); \\
176 s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\
178 s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\
184 # appends directory or set of directories, separated by ':' (second parameter)
185 # to the variable (first parameter)
187 xenv=\`printenv \$1\`
188 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
189 out_var=\`cleandup \$xenv \$2 0\`
193 # prepends directory or set of directories, separated by ':' (second parameter)
194 # to the variable (first parameter)
196 xenv=\`printenv \$1\`
197 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
198 out_var=\`cleandup \$xenv \$2 1\`
201 ###########################################################################
205 # 3. writing global functions to _salome.csh file
206 cat >> ${install_work}/_$CSHRC <<EOF
207 ###########################################################################
208 # Aliases setenva and setenvp are used to append/prepend correspondingly
209 # one directory or a set of directories separated by semicolon symbol (':')
210 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
212 # The main purpose is to replace default setenv command behavior:
213 # setenva, setenvp also remove duplicated entries, shortening in that way
214 # the environment variables.
215 # If some directory being added is already included into the variable
216 # nothing is done for it.
217 # Note, that these aliases work some slower that setenv command itself.
220 # appends/prepends set of directories (second parameter)
221 # to the another set of directories (first parameter) and
222 # removes duplicated entries;
223 # the third parameter defines the mode: 0 - append, 1 - prepend
224 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3 \\\\
225 '"'{ na = split(\$2,a,":"); \\\\
226 nb = split(\$1,b,":"); \\\\
228 for(i=1;i<=nb;i++) { \\\\
229 if(!(b[i] in ccc)) { \\\\
230 if(length(s)!=0) \\\\
231 s = sprintf("%s:",s); \\\\
232 s = sprintf("%s%s",s,b[i]); \\\\
237 for(i=1;i<=na;i++) { \\\\
238 if(!(a[i] in ccc)) { \\\\
239 if(length(s1)!=0) \\\\
240 s1 = sprintf("%s:",s1); \\\\
241 s1 = sprintf("%s%s",s1,a[i]); \\\\
246 s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\\\
248 s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\\\
249 printf("%s\n",s); \\\\
252 # appends directory or set of directories, separated by ':' (second parameter)
253 # to the variable (first parameter)
254 alias setenva 'set a=\!:1 ; set b=\!:2 ; \\
255 set c=\`printenv \$a\` ; \\
256 set b=\`cleandup \$c \$b 0\` ; \\
261 # prepends directory or set of directories, separated by ':' (second parameter)
262 # to the variable (first parameter)
263 alias setenvp 'set a=\!:1 ; set b=\!:2 ; \\
264 set c=\`printenv \$a\` ; \\
265 set b=\`cleandup \$c \$b 1\` ; \\
268 ###########################################################################
271 cat ${install_work}/$CSHRC >> ${install_work}/_$CSHRC
273 # 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
274 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
275 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
276 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
277 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
278 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$SHRC
280 # 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
281 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
282 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC
284 # 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
285 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
286 sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
287 sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
288 sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
289 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
290 sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
291 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$CSHRC 2>/dev/null
293 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
295 if [ $# -eq 4 ] ; then
297 if [ -e ${product_dir} ] ; then
298 cp -f ${install_work}/_$SHRC ${product_dir}/$SHRC
299 cp -f ${install_work}/_$CSHRC ${product_dir}/$CSHRC
302 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_products.csh
303 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC > ${install_root}/env_products.sh
304 rm -f ${install_work}/_$SHRC
305 rm -f ${install_work}/_$CSHRC
306 ### !!! copying build.csh script
307 if [ -e ./build.csh ]; then
308 cp -f ./build.csh ${install_root}
312 #try use already existing product
315 product_dir=$1; install_root=$2; install_work=$3; product_sequence="$4"; product_type=$5
316 env_file=${product_dir}/env_${product_type}.sh
317 if [ -f ${env_file} ] ; then
318 cp -f ${env_file} ${install_work}
319 make_env ${install_root} ${install_work} "${product_sequence}"
320 source ${install_work}/$SHRC
322 if [ $? -eq 0 ] ; then
323 if [ -d ${product_dir} ] && [ -w ${product_dir} ] ; then
324 #makedir ${product_dir}
333 #check existance of lib passed as first parameter
334 #return 0 if lib exists
335 #if you pass second parameter search will be done in it
336 #otherwise search will be done in $LD_LIBRARY_PATH
337 #you should use : as dilimeter if you are going to pass second parameter
342 whereIs=$LD_LIBRARY_PATH
344 for L in `echo ${whereIs} | sed -e"s%:% %g"` ; do
345 ret=`find $L -name $1 2>/dev/null`
346 if [ -n "$ret" ] ; then
347 #echo "The $1 exists on yours system in a $L folder"
357 for i in `echo ${path} | sed -e"s%:% %g"` ; do
358 ret=`find $i -name $file 2>/dev/null`
359 if [ -n "$ret" ] ; then
360 ret=`echo $ret | sed -e"s%/\$file$%%g"`
369 arg1=$1; val1=$2; arg2=$3; val2=$4
370 tmp="^$val1$|^$val1:|:$val1$|:$val1:"
371 #echo $val2 | grep -E "$tmp" >/dev/null 2>&1
372 #if [ $? -eq 0 ] ; then
377 exclude_list="usr lib bin sbin etc"
378 for i in ${exclude_list} ; do
380 echo ${val1} | grep -E "$tmp" >/dev/null 2>&1
381 if [ $? == 0 ] ; then to_tail=0; break; fi
383 if [ $to_tail -eq 0 ] ; then