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 !!! -> add global functions
92 cat >> ${install_work}/$SHRC <<EOF
93 export INSTALL_ROOT=${install_root}
95 ##########################################################################
96 # Functions exporta and exportp are used to append/prepend correspondingly
97 # one directory or a set of directories separated by semicolon symbol (':')
98 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
100 # The main purpose is to replace default setenv command behavior:
101 # exporta, exportp also remove duplicated entries, shortening in that way
102 # the environment variables.
103 # If some directory being added is already included into the variable
104 # nothing is done for it.
105 # Note, that these functions work some slower that setenv command itself.
108 # appends/prepends set of directories (second parameter)
109 # to the another set of directories (first parameter) and
110 # removes duplicated entries;
111 # the third parameter defines the mode: 0 - append, 1 - prepend
113 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{ \\
114 na = split(\$2,a,":"); \\
115 nb = split(\$1,b,":"); \\
117 for(i=1;i<=nb;i++) { \\
118 if(!(b[i] in ccc)) { \\
120 s = sprintf("%s:",s); \\
121 s = sprintf("%s%s",s,b[i]); \\
126 for(i=1;i<=na;i++) { \\
127 if(!(a[i] in ccc)) { \\
129 s1 = sprintf("%s:",s1); \\
130 s1 = sprintf("%s%s",s1,a[i]); \\
135 s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\
137 s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\
143 # appends directory or set of directories, separated by ':' (second parameter)
144 # to the variable (first parameter)
146 xenv=\`printenv \$1\`
147 out_var=\`cleandup \$xenv \$2 0\`
151 # prepends directory or set of directories, separated by ':' (second parameter)
152 # to the variable (first parameter)
154 xenv=\`printenv \$1\`
155 out_var=\`cleandup \$xenv \$2 1\`
158 ###########################################################################
161 ### !!! writing salome.csh file !!! -> add global aliases
162 cat >> ${install_work}/$CSHRC <<EOF
163 setenv INSTALL_ROOT ${install_root}
165 ###########################################################################
166 # Aliases setenva and setenvp are used to append/prepend correspondingly
167 # one directory or a set of directories separated by semicolon symbol (':')
168 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
170 # The main purpose is to replace default setenv command behavior:
171 # setenva, setenvp also remove duplicated entries, shortening in that way
172 # the environment variables.
173 # If some directory being added is already included into the variable
174 # nothing is done for it.
175 # Note, that these aliases work some slower that setenv command itself.
178 # appends/prepends set of directories (second parameter)
179 # to the another set of directories (first parameter) and
180 # removes duplicated entries;
181 # the third parameter defines the mode: 0 - append, 1 - prepend
182 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3 \\\\
183 '"'{ na = split(\$2,a,":"); \\\\
184 nb = split(\$1,b,":"); \\\\
186 for(i=1;i<=nb;i++) { \\\\
187 if(!(b[i] in ccc)) { \\\\
188 if(length(s)!=0) \\\\
189 s = sprintf("%s:",s); \\\\
190 s = sprintf("%s%s",s,b[i]); \\\\
195 for(i=1;i<=na;i++) { \\\\
196 if(!(a[i] in ccc)) { \\\\
197 if(length(s1)!=0) \\\\
198 s1 = sprintf("%s:",s1); \\\\
199 s1 = sprintf("%s%s",s1,a[i]); \\\\
204 s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\\\
206 s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\\\
207 printf("%s\n",s); \\\\
210 # appends directory or set of directories, separated by ':' (second parameter)
211 # to the variable (first parameter)
212 alias setenva 'set a=\!:1 ; set b=\!:2 ; \\
213 set c=\`printenv \$a\` ; \\
214 set b=\`cleandup \$c \$b 0\` ; \\
219 # prepends directory or set of directories, separated by ':' (second parameter)
220 # to the variable (first parameter)
221 alias setenvp 'set a=\!:1 ; set b=\!:2 ; \\
222 set c=\`printenv \$a\` ; \\
223 set b=\`cleandup \$c \$b 1\` ; \\
226 ###########################################################################
229 ### !!! writing salome.csh file !!! -> set inital variables
230 pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
231 for i in $pre_vars ; do
232 cat >> ${install_work}/$CSHRC <<EOF
233 #$DELIM $i : initial settings $DELIM
234 if (! (\$?${i}) ) then
239 ### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|p)' where necessary
240 product_sequence="$2"
241 for i in $product_sequence ; do
242 sed -e 's%^export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%exporta\1PATH \2%g' -e 's%^export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%exportp\1PATH \2%g' ${install_work}/env_${i}.sh > ${INSTALL_WORK}/_tmp1 2>/dev/null
243 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
244 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
245 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 2>/dev/null
246 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/$SHRC 2>/dev/null
248 sed -e 's%^export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
249 sed -e 's%^exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
250 sed -e 's%^exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
251 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC 2>/dev/null
253 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
256 if [ $# -eq 4 ] ; then
258 if [ -e ${product_dir} ] ; then
259 cp -f ${install_work}/$SHRC ${install_work}/$CSHRC ${product_dir}/.
262 cp -f ${install_work}/$CSHRC ${install_root}/env_products.csh
263 cp -f ${install_work}/$SHRC ${install_root}/env_products.sh
264 ### !!! copying build.csh script
265 if [ -e ./build.csh ]; then
266 cp -f ./build.csh ${install_root}
270 #try use already existing product
273 product_dir=$1; install_root=$2; install_work=$3; product_sequence="$4"; product_type=$5
274 env_file=${product_dir}/env_${product_type}.sh
275 if [ -f ${env_file} ] ; then
276 cp -f ${env_file} ${install_work}
277 make_env ${install_root} ${install_work} "${product_sequence}"
278 source ${install_work}/$SHRC
280 if [ $? -eq 0 ] ; then
281 if [ -d ${product_dir} ] && [ -w ${product_dir} ] ; then
282 #makedir ${product_dir}
291 #check existance of lib passed as first parameter
292 #return 0 if lib exists
293 #if you pass second parameter search will be done in it
294 #otherwise search will be done in $LD_LIBRARY_PATH
295 #you should use : as dilimeter if you are going to pass second parameter
300 whereIs=$LD_LIBRARY_PATH
302 for L in `echo ${whereIs} | sed -e"s%:% %g"` ; do
303 ret=`find $L -name $1 2>/dev/null`
304 if [ -n "$ret" ] ; then
305 #echo "The $1 exists on yours system in a $L folder"
315 for i in `echo ${path} | sed -e"s%:% %g"` ; do
316 ret=`find $i -name $file 2>/dev/null`
317 if [ -n "$ret" ] ; then
318 ret=`echo $ret | sed -e"s%/\$file$%%g"`
327 arg1=$1; val1=$2; arg2=$3; val2=$4
328 tmp="^$val1$|^$val1:|:$val1$|:$val1:"
329 #echo $val2 | grep -E "$tmp" >/dev/null 2>&1
330 #if [ $? -eq 0 ] ; then
335 exclude_list="usr lib bin sbin etc"
336 for i in ${exclude_list} ; do
338 echo ${val1} | grep -E "$tmp" >/dev/null 2>&1
339 if [ $? == 0 ] ; then to_tail=0; break; fi
341 if [ $to_tail -eq 0 ] ; then