[2380] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # palmbuild - script for compiling the PALM code and its utility programs |
---|
| 4 | |
---|
| 5 | #------------------------------------------------------------------------------# |
---|
| 6 | # This file is part of PALM. |
---|
| 7 | # |
---|
| 8 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 9 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
| 10 | # either version 3 of the License, or (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 15 | # |
---|
| 16 | # You should have received a copy of the GNU General Public License along with |
---|
| 17 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | # |
---|
| 19 | # Copyright 2017 Leibniz Universitaet Hannover |
---|
| 20 | #------------------------------------------------------------------------------# |
---|
| 21 | # |
---|
| 22 | # Current revisions: |
---|
| 23 | # ------------------ |
---|
| 24 | # Initial revision |
---|
| 25 | # |
---|
| 26 | # Former revisions: |
---|
| 27 | # ----------------- |
---|
| 28 | # $Id: palmbuild 2380 2017-09-01 08:33:46Z raasch $ |
---|
| 29 | # |
---|
| 30 | #------------------------------------------------------------------------------# |
---|
| 31 | # palmbuild - script for compiling the PALM code and its utility programs |
---|
| 32 | # |
---|
| 33 | # Procedure to compile code on local and remote hosts using the |
---|
| 34 | # make-mechanism. The source code must be provided on the local host. |
---|
| 35 | # |
---|
| 36 | # @note This script does not work on MAC OS |
---|
| 37 | #------------------------------------------------------------------------------# |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | # VARIABLE DECLARATIONS + DEFAULT VALUES |
---|
| 41 | calltime="" |
---|
| 42 | column1="" |
---|
| 43 | column2="" |
---|
| 44 | config_file=.palm.config |
---|
| 45 | host=default |
---|
| 46 | host_found=false |
---|
| 47 | locat=normal |
---|
| 48 | makefile="" |
---|
| 49 | make_options="" |
---|
| 50 | module_commands="" |
---|
| 51 | program_name=palm |
---|
| 52 | remote_ip="" |
---|
| 53 | silent=false |
---|
| 54 | ssh_key="" |
---|
| 55 | suf=f90 |
---|
| 56 | version="PALMBUILD 0.1 Rev$Rev: 2316 $" |
---|
| 57 | working_directory=`pwd` |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | # ERROR HANDLING |
---|
| 62 | # IN CASE OF EXIT: |
---|
| 63 | trap 'if [[ $locat != normal ]] |
---|
| 64 | then |
---|
| 65 | printf "\n\n +++ palmbuild killed \n\n" |
---|
| 66 | exit 1 |
---|
| 67 | else |
---|
| 68 | printf "\n\n *** palmbuild finished \n\n" |
---|
| 69 | exit 0 |
---|
| 70 | fi' exit |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | # IN CASE OF TERMINAL-BREAK: |
---|
| 74 | trap 'printf "\n\n +++ palmbuild killed by \"^C\" \n\n" |
---|
| 75 | exit |
---|
| 76 | ' 2 |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | # READ SHELLSCRIPT-OPTIONS |
---|
| 81 | while getopts :d:h:m:s:S:uv option |
---|
| 82 | do |
---|
| 83 | case $option in |
---|
| 84 | (d) fname=$OPTARG;; |
---|
| 85 | (h) host=$OPTARG;; |
---|
| 86 | (m) makefile=$OPTARG;; |
---|
| 87 | (s) suf=$OPTARG;; |
---|
| 88 | (S) source_list="$OPTARG";; |
---|
| 89 | (v) silent=true;; |
---|
| 90 | (\?) printf "\n +++ unknown option $OPTARG \n"; |
---|
| 91 | locat=parameter; exit;; |
---|
| 92 | esac |
---|
| 93 | done |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | # BUILD THE CONFIGURATION-FILE NAME |
---|
| 97 | config_file=${config_file}.$host |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | # CHECK, IF CONFIGURATION-FILE EXISTS |
---|
| 101 | if [[ ! -f $config_file ]] |
---|
| 102 | then |
---|
| 103 | printf "\n +++ configuration file: " |
---|
| 104 | printf "\n $config_file" |
---|
| 105 | printf "\n does not exist" |
---|
| 106 | locat=configuration; exit |
---|
| 107 | fi |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | # ### is this really required? |
---|
| 111 | config_file=$PWD/$config_file |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | # READ VARIABLE SETTINGS FROM CONFIG FILE LINE BY LINE |
---|
| 115 | while read line |
---|
| 116 | do |
---|
| 117 | |
---|
| 118 | # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES |
---|
| 119 | eval line=\"$line\" |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | # INTERPRET THE LINE |
---|
| 123 | if [[ "$(echo $line)" = "" ]] |
---|
| 124 | then |
---|
| 125 | |
---|
| 126 | # EMPTY LINE, NO ACTION |
---|
| 127 | continue |
---|
| 128 | |
---|
| 129 | elif [[ "$(echo $line | cut -c1)" = "#" ]] |
---|
| 130 | then |
---|
| 131 | |
---|
| 132 | # LINE IS A COMMENT LINE |
---|
| 133 | continue |
---|
| 134 | |
---|
| 135 | elif [[ "$(echo $line | cut -c1)" = "%" ]] |
---|
| 136 | then |
---|
| 137 | |
---|
| 138 | # LINE DEFINES AN ENVIRONMENT-VARIABLE |
---|
| 139 | var=`echo $line | cut -d" " -s -f1 | cut -c2-` |
---|
| 140 | value=`echo $line | cut -d" " -s -f2-` |
---|
| 141 | |
---|
| 142 | # REPLACE ":" BY " " IN COMPILER- CPP- OR LINKER-OPTIONS, |
---|
| 143 | # "::" IS REPLACED BY ":". |
---|
| 144 | #value=`echo $value | sed 's/::/%DUM%/g' | sed 's/:/ /g' | sed 's/%DUM%/:/g'` |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE |
---|
| 148 | # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY |
---|
| 149 | # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS). |
---|
| 150 | # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER). |
---|
| 151 | # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE |
---|
| 152 | # CONFIGURATION-FILE. |
---|
| 153 | if [[ "$(eval echo \$$var)" = "" || "$(eval echo \$$var)" = "0" ]] |
---|
| 154 | then |
---|
| 155 | eval export $var="\$value" |
---|
| 156 | |
---|
| 157 | # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on |
---|
| 158 | if [[ $do_trace = true ]] |
---|
| 159 | then |
---|
| 160 | printf "\n*** ENVIRONMENT-VARIABLE $var = $value" |
---|
| 161 | fi |
---|
| 162 | fi |
---|
| 163 | |
---|
| 164 | else |
---|
| 165 | |
---|
| 166 | # SKIP ALL OTHER LINES |
---|
| 167 | continue |
---|
| 168 | |
---|
| 169 | fi |
---|
| 170 | |
---|
| 171 | done < $config_file |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | # CHECK SOURCE-CODE PATH |
---|
| 175 | if [[ "$source_path" = "" ]] |
---|
| 176 | then |
---|
| 177 | printf "\n +++ no source path found in configuration file" |
---|
| 178 | locat=config_file; exit |
---|
| 179 | else |
---|
| 180 | if [[ ! -d $source_path ]] |
---|
| 181 | then |
---|
| 182 | printf "\n\n +++ source path \"$source_path\" " |
---|
| 183 | printf "\n does not exist" |
---|
| 184 | locat=source_path; exit |
---|
| 185 | fi |
---|
| 186 | fi |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | # CHECK DEPOSITORY-PATH |
---|
| 190 | if [[ "$depository_path" = "" ]] |
---|
| 191 | then |
---|
| 192 | printf "\n +++ no depository path found in configuration file" |
---|
| 193 | locat=config_file; exit |
---|
| 194 | fi |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | # CHECK MAKEFILE |
---|
| 198 | [[ "$makefile" = "" ]] && makefile=$source_path/Makefile |
---|
| 199 | if [[ ! -f $makefile ]] |
---|
| 200 | then |
---|
| 201 | printf "\n +++ makefile: " |
---|
| 202 | printf "\n $makefile" |
---|
| 203 | printf "\n does not exist" |
---|
| 204 | locat=makefile; exit |
---|
| 205 | fi |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | # CHECK COMPILERNAME |
---|
| 209 | if [[ "$compiler_name" = "" ]] |
---|
| 210 | then |
---|
| 211 | printf "\n +++ no compiler name found in configuration file" |
---|
| 212 | locat=config_file; exit |
---|
| 213 | fi |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | # CHECK SERIAL COMPILERNAME |
---|
| 217 | if [[ "$compiler_name_ser" = "" ]] |
---|
| 218 | then |
---|
| 219 | printf "\n +++ no compiler name for serial compilation in configuration file" |
---|
| 220 | locat=config_file; exit |
---|
| 221 | fi |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | # DETERMINE SSH-KEY TO BE USED |
---|
| 225 | if [[ "$ssh_key" != "" ]] |
---|
| 226 | then |
---|
| 227 | ssh_key="-i $HOME/.ssh/`echo $line | cut -d" " -s -f2`" |
---|
| 228 | fi |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | #CHECK CPP-OPTIONS |
---|
| 232 | if [[ "$cpp_options" = "" ]] |
---|
| 233 | then |
---|
| 234 | printf "\n +++ WARNING: no cpp-options found in configuration file" |
---|
| 235 | fi |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | # CHECK SETTINGS IN CASE OF COMPILING ON REMOTE MACHINE |
---|
| 239 | if [[ "$remote_ip" != "" ]] |
---|
| 240 | then |
---|
| 241 | |
---|
| 242 | if [[ "$remote_username" = "" ]] |
---|
| 243 | then |
---|
| 244 | printf "\n +++ no user name given in configuration file" |
---|
| 245 | locat=config_file; exit |
---|
| 246 | fi |
---|
| 247 | |
---|
| 248 | [[ "$remote_hostname" = "" ]] && remote_hostname=$remote_ip |
---|
| 249 | |
---|
| 250 | # GET SOURCE AND DEPOSITORY PATH ON THE REMOTE MACHINE WITHOUT EVALUATING |
---|
| 251 | # THE $ |
---|
| 252 | # IF NOT GIVEN, USE THE LOCAL SOURCE AND DEPOSITORY PATH |
---|
| 253 | line=`grep %remote_source_path $config_file` |
---|
| 254 | if [[ "$line" != "" ]] |
---|
| 255 | then |
---|
| 256 | remote_source_path=`echo $line | cut -d" " -s -f2` |
---|
| 257 | else |
---|
| 258 | line=`grep %source_path $config_file` |
---|
| 259 | remote_source_path=`echo $line | cut -d" " -s -f2` |
---|
| 260 | fi |
---|
| 261 | |
---|
| 262 | line=`grep %remote_depository_path $config_file` |
---|
| 263 | if [[ "$line" != "" ]] |
---|
| 264 | then |
---|
| 265 | remote_depository_path=`echo $line | cut -d" " -s -f2` |
---|
| 266 | else |
---|
| 267 | line=`grep %depository_path $config_file` |
---|
| 268 | remote_depository_path=`echo $line | cut -d" " -s -f2` |
---|
| 269 | fi |
---|
| 270 | |
---|
| 271 | remote_make_depository=${remote_depository_path}/MAKE_DEPOSITORY_${host} |
---|
| 272 | |
---|
| 273 | else |
---|
| 274 | |
---|
| 275 | local_make_depository=${depository_path}/MAKE_DEPOSITORY_${host} |
---|
| 276 | |
---|
| 277 | fi |
---|
| 278 | |
---|
| 279 | # HEADER-OUTPUT (PART1: MESSAGES CONCERNING THE LOCAL HOST) |
---|
| 280 | calltime=$(date) |
---|
| 281 | printf "\n" |
---|
| 282 | printf "#------------------------------------------------------------------------# \n" |
---|
| 283 | printf "| %-40s%30s | \n" "$version" "$calltime" |
---|
| 284 | printf "| | \n" |
---|
| 285 | printf "| %-13s%-57s | \n" "called on:" "$local_hostname" |
---|
| 286 | column2=$(echo $config_file | cut -c1-57 ) |
---|
| 287 | printf "| %-13s%-57s | \n" "config file:" "$column2" |
---|
| 288 | line=$(echo "$config_file" | cut -c58-) |
---|
| 289 | while [[ "$line" != "" ]] |
---|
| 290 | do |
---|
| 291 | column1="" |
---|
| 292 | column2=$(echo $line | cut -c1-57 ) |
---|
| 293 | printf "| %-13s%-57s | \n" "$column1" "$column2" |
---|
| 294 | line=$(echo "$line" | cut -c58-) |
---|
| 295 | done |
---|
| 296 | column2=$(echo $makefile | cut -c1-57 ) |
---|
| 297 | printf "| %-13s%-57s | \n" "makefile:" "$column2" |
---|
| 298 | line=$(echo "$makefile" | cut -c58-) |
---|
| 299 | while [[ "$line" != "" ]] |
---|
| 300 | do |
---|
| 301 | column1="" |
---|
| 302 | column2=$(echo $line | cut -c1-57 ) |
---|
| 303 | printf "| %-13s%-57s | \n" "$column1" "$column2" |
---|
| 304 | line=$(echo "$line" | cut -c58-) |
---|
| 305 | done |
---|
| 306 | column2=$(echo $source_path | cut -c1-57 ) |
---|
| 307 | printf "| %-13s%-57s | \n" "source path:" "$column2" |
---|
| 308 | line=$(echo "$source_path" | cut -c58-) |
---|
| 309 | while [[ "$line" != "" ]] |
---|
| 310 | do |
---|
| 311 | column1="" |
---|
| 312 | column2=$(echo $line | cut -c1-57 ) |
---|
| 313 | printf "| %-13s%-57s | \n" "$column1" "$column2" |
---|
| 314 | line=$(echo "$line" | cut -c58-) |
---|
| 315 | done |
---|
| 316 | printf "#------------------------------------------------------------------------# \n" |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | # TAR THE SOURCES AND MAKEFILES |
---|
| 321 | # UTILITIES ARE TEMPORARILY COPIED TO THE SOURCE DIRECTORY IN ORDER TO TAR |
---|
| 322 | # THEM TOO |
---|
| 323 | cd $source_path |
---|
| 324 | printf "\n\n *** tar of makefile and source files in" |
---|
| 325 | printf "\n $source_path" |
---|
| 326 | cp -p ../UTIL/combine_plot_fields.f90 . |
---|
| 327 | cp -p ../UTIL/compare_palm_logs.f90 . |
---|
| 328 | cp -p ../UTIL/Makefile_utilities . |
---|
| 329 | tar -cf ${program_name}_sources.tar Makefile* *.$suf |
---|
| 330 | rm combine_plot_fields.f90 compare_palm_logs.f90 Makefile_utilities |
---|
| 331 | printf "\n" |
---|
| 332 | |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | # GET CONFIRMATION TO CONTINUE |
---|
| 336 | printf "\n *** update will be made for host \"$host\" " |
---|
| 337 | |
---|
| 338 | |
---|
| 339 | if [[ $silent = false ]] |
---|
| 340 | then |
---|
| 341 | answer=dummy |
---|
| 342 | printf "\n\n" |
---|
| 343 | while [[ "$answer" != y && "$answer" != Y && "$answer" != n && "$answer" != N ]] |
---|
| 344 | do |
---|
| 345 | printf " >>> continue (y/n) ? " |
---|
| 346 | read answer |
---|
| 347 | done |
---|
| 348 | if [[ $answer = n || $answer = N ]] |
---|
| 349 | then |
---|
| 350 | locat=user_abort; exit |
---|
| 351 | fi |
---|
| 352 | fi |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | printf "\n\n#------------------------------------------------------------------------# \n" |
---|
| 358 | |
---|
| 359 | if [[ "$remote_ip" != "" ]] |
---|
| 360 | then |
---|
| 361 | column2=$remote_hostname |
---|
| 362 | printf "| %-20s%-50s | \n" "remote host:" "$column2" |
---|
| 363 | printf "| | \n" |
---|
| 364 | column2=$(echo "$remote_make_depository" | cut -c1-50 ) |
---|
| 365 | printf "| %-20s%-50s | \n" "remote depository:" "$column2" |
---|
| 366 | line=$(echo "$remote_make_depository" | cut -c51-) |
---|
| 367 | while [[ "$line" != "" ]] |
---|
| 368 | do |
---|
| 369 | column1="" |
---|
| 370 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 371 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 372 | line=$(echo "$line" | cut -c51-) |
---|
| 373 | done |
---|
| 374 | else |
---|
| 375 | column2=$local_hostname |
---|
| 376 | printf "| %-20s%-50s | \n" "local host:" "$column2" |
---|
| 377 | printf "| | \n" |
---|
| 378 | column2=$(echo "$local_make_depository" | cut -c1-50 ) |
---|
| 379 | printf "| %-20s%-50s | \n" "local depository:" "$column2" |
---|
| 380 | line=$(echo "$local_make_depository" | cut -c51-) |
---|
| 381 | while [[ "$line" != "" ]] |
---|
| 382 | do |
---|
| 383 | column1="" |
---|
| 384 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 385 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 386 | line=$(echo "$line" | cut -c51-) |
---|
| 387 | done |
---|
| 388 | fi |
---|
| 389 | |
---|
| 390 | if [[ "$remote_ip" != "" ]] |
---|
| 391 | then |
---|
| 392 | printf "| %-20s%-50s | \n" "remote username:" "$remote_username" |
---|
| 393 | printf "| %-20s%-50s | \n" "remote address:" "$remote_ip" |
---|
| 394 | else |
---|
| 395 | printf "| %-20s%-50s | \n" "username:" "$local_username" |
---|
| 396 | printf "| %-20s%-50s | \n" "address:" "$local_ip" |
---|
| 397 | fi |
---|
| 398 | |
---|
| 399 | printf "| %-20s%-50s | \n" "compiler:" "$compiler_name" |
---|
| 400 | printf "| %-20s%-50s | \n" "serial compiler:" "$compiler_name_ser" |
---|
| 401 | |
---|
| 402 | if [[ "$make_options" != "" ]] |
---|
| 403 | then |
---|
| 404 | printf "| %-20s%-50s | \n" "make options:" "$make_options" |
---|
| 405 | fi |
---|
| 406 | column2=$(echo "$cpp_options" | cut -c1-50 ) |
---|
| 407 | printf "| %-20s%-50s | \n" "cpp options:" "$column2" |
---|
| 408 | line=$(echo "$cpp_options" | cut -c51-) |
---|
| 409 | while [[ "$line" != "" ]] |
---|
| 410 | do |
---|
| 411 | column1="" |
---|
| 412 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 413 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 414 | line=$(echo "$line" | cut -c51-) |
---|
| 415 | done |
---|
| 416 | column2=$(echo "$compiler_options" | cut -c1-50 ) |
---|
| 417 | printf "| %-20s%-50s | \n" "compiler options:" "$column2" |
---|
| 418 | line=$(echo "$compiler_options" | cut -c51-) |
---|
| 419 | while [[ "$line" != "" ]] |
---|
| 420 | do |
---|
| 421 | column1="" |
---|
| 422 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 423 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 424 | line=$(echo "$line" | cut -c51-) |
---|
| 425 | done |
---|
| 426 | column2=$(echo "$loader_options" | cut -c1-50 ) |
---|
| 427 | printf "| %-20s%-50s | \n" "loader options:" "$column2" |
---|
| 428 | line=$(echo "$loader_options" | cut -c51-) |
---|
| 429 | while [[ "$line" != "" ]] |
---|
| 430 | do |
---|
| 431 | column1="" |
---|
| 432 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 433 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 434 | line=$(echo "$line" | cut -c51-) |
---|
| 435 | done |
---|
| 436 | if [[ "$login_init_cmd" != "" ]] |
---|
| 437 | then |
---|
| 438 | column2=$(echo "$login_init_cmd" | cut -c1-50 ) |
---|
| 439 | printf "| %-20s%-50s | \n" "login init command:" "$column2" |
---|
| 440 | line=$(echo "$login_init_cmd" | cut -c51-) |
---|
| 441 | while [[ "$line" != "" ]] |
---|
| 442 | do |
---|
| 443 | column1="" |
---|
| 444 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 445 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 446 | line=$(echo "$line" | cut -c51-) |
---|
| 447 | done |
---|
| 448 | fi |
---|
| 449 | if [[ "$module_commands" != "" ]] |
---|
| 450 | then |
---|
| 451 | column2=$(echo "$module_commands" | cut -c1-50 ) |
---|
| 452 | printf "| %-20s%-50s | \n" "module command(s):" "$column2" |
---|
| 453 | line=$(echo "$module_commands" | cut -c51-) |
---|
| 454 | while [[ "$line" != "" ]] |
---|
| 455 | do |
---|
| 456 | column1="" |
---|
| 457 | column2=$(echo "$line" | cut -c1-50 ) |
---|
| 458 | printf "| %-20s%-50s | \n" "$column1" "$column2" |
---|
| 459 | line=$(echo "$line" | cut -c51-) |
---|
| 460 | done |
---|
| 461 | fi |
---|
| 462 | printf "#------------------------------------------------------------------------# \n" |
---|
| 463 | |
---|
| 464 | if [[ $silent = false ]] |
---|
| 465 | then |
---|
| 466 | answer=dummy |
---|
| 467 | printf "\n\n" |
---|
| 468 | while [[ "$answer" != y && "$answer" != Y && "$answer" != c && "$answer" != C && "$answer" != s && "$answer" != S && "$answer" != a && "$answer" != A ]] |
---|
| 469 | do |
---|
| 470 | printf " >>> continue (y(es)/c(ontinue)/a(bort)/s(skip)) ? " |
---|
| 471 | read answer |
---|
| 472 | done |
---|
| 473 | if [[ $answer = a || $answer = A ]] |
---|
| 474 | then |
---|
| 475 | locat=user_abort; exit |
---|
| 476 | fi |
---|
| 477 | if [[ $answer = c || $answer = C ]] |
---|
| 478 | then |
---|
| 479 | silent=true |
---|
| 480 | fi |
---|
| 481 | if [[ $answer = s || $answer = S ]] |
---|
| 482 | then |
---|
| 483 | continue |
---|
| 484 | fi |
---|
| 485 | fi |
---|
| 486 | |
---|
| 487 | |
---|
| 488 | # MAKE ON REMOTE HOST |
---|
| 489 | if [[ "$remote_ip" != "" ]] |
---|
| 490 | then |
---|
| 491 | |
---|
| 492 | # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_... |
---|
| 493 | if [[ "$fname" = "" ]] |
---|
| 494 | then |
---|
| 495 | |
---|
| 496 | # COPY CURRENT SOURCE CODE TO SOURCE-CODE DIRECTORY ON THE REMOTE HOST |
---|
| 497 | # CREATE THIS DIRECTORY, IF IT DOES NOT EXIST |
---|
| 498 | echo " *** copying \"${program_name}_sources.tar\" to \"${remote_ip}:${remote_make_depository}/\" " |
---|
| 499 | echo "[[ ! -d ${remote_make_depository} ]] && (echo \" *** ${remote_make_depository} will be created\"; mkdir -p ${remote_make_depository})" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 |
---|
| 500 | |
---|
| 501 | scp $ssh_key ${source_path}/${program_name}_sources.tar ${remote_username}@${remote_ip}:${remote_make_depository}/${program_name}_sources.tar |
---|
| 502 | |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | # UNTAR PREVIOUS UPDATE ON REMOTE HOST, IF EXISTING |
---|
| 506 | echo " *** untar previous update on remote host, if existing" |
---|
| 507 | echo "cd ${remote_make_depository}; [[ -f ${program_name}_current_version.tar ]] && tar -xf ${program_name}_current_version.tar" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 |
---|
| 508 | |
---|
| 509 | |
---|
| 510 | # UNTAR CURRENT SOURCES ON REMOTE HOST |
---|
| 511 | echo " *** untar current sources on remote host" |
---|
| 512 | echo "cd ${remote_make_depository}; tar -xf ${program_name}_sources.tar" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | # CREATE INIT AND MODULE COAMMNDS |
---|
| 516 | [[ "$login_init_cmd" != "" ]] && login_init_cmd=${login_init_cmd}";" |
---|
| 517 | [[ "$module_commands" != "" ]] && module_commands=${module_commands}";" |
---|
| 518 | |
---|
| 519 | |
---|
| 520 | # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES |
---|
| 521 | echo " " |
---|
| 522 | echo " *** creating utilities on remote host" |
---|
| 523 | make_call_string="make -f Makefile_utilities $make_options F90=$compiler_name F90_SER=$compiler_name_ser COPT=\"$cpp_options\" F90FLAGS=\"$compiler_options\" LDFLAGS=\"$loader_options\" " |
---|
| 524 | echo "$login_init_cmd $module_commands cd ${remote_make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 | tee ${remote_hostname}_last_make_protokoll |
---|
| 525 | |
---|
| 526 | if [[ $(grep -c MAKE_ERROR ${remote_hostname}_last_make_protokoll) != 0 ]] |
---|
| 527 | then |
---|
| 528 | printf "\a\n +++ error(s) occurred during compiling or linking of utilities" |
---|
| 529 | printf "\n on host \"$remote_hostname\" " |
---|
| 530 | if [[ $silent = false ]] |
---|
| 531 | then |
---|
| 532 | answer=dummy |
---|
| 533 | printf "\n" |
---|
| 534 | while [[ "$answer" != c && "$answer" != k ]] |
---|
| 535 | do |
---|
| 536 | printf " >>> continue / list errors / kill palmbuild (c/l/k) ? " |
---|
| 537 | read answer |
---|
| 538 | if [[ "$answer" = l ]] |
---|
| 539 | then |
---|
| 540 | more ${remote_hostname}_last_make_protokoll |
---|
| 541 | fi |
---|
| 542 | done |
---|
| 543 | if [[ $answer = k ]] |
---|
| 544 | then |
---|
| 545 | locat=user_abort; exit |
---|
| 546 | fi |
---|
| 547 | fi |
---|
| 548 | fi |
---|
| 549 | |
---|
| 550 | |
---|
| 551 | # NOW COMPILE THE PALM CODE |
---|
| 552 | # COMMANDS WILL BE COMMUNICATED TO SSH VIA PIPE, SINCE THIS WAY THE SYSTEM- AND |
---|
| 553 | # USER-PROFILES OF THE SHELL ARE COMPLETELY EXECUTED (OTHERWISE, MAKE |
---|
| 554 | # MAY E.G. MISS THE COMPILER-PATHS) |
---|
| 555 | echo " " |
---|
| 556 | echo " *** compile PALM sources on remote host" |
---|
| 557 | make_call_string="make $make_options PROG=$program_name F90=$compiler_name COPT=\"$cpp_options\" F90FLAGS=\"$compiler_options\" LDFLAGS=\"$loader_options\" " |
---|
| 558 | echo "$login_init_cmd $module_commands cd ${remote_make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 | tee ${remote_hostname}_last_make_protokoll |
---|
| 559 | |
---|
| 560 | if [[ $(grep -c MAKE_ERROR ${remote_hostname}_last_make_protokoll) != 0 ]] |
---|
| 561 | then |
---|
| 562 | printf "\a\n +++ error(s) occurred during compiling or linking on host \"$remote_hostname\" " |
---|
| 563 | if [[ $silent = false ]] |
---|
| 564 | then |
---|
| 565 | answer=dummy |
---|
| 566 | printf "\n" |
---|
| 567 | while [[ "$answer" != c && "$answer" != k ]] |
---|
| 568 | do |
---|
| 569 | printf " >>> continue / list errors / kill palmbuild (c/l/k) ? " |
---|
| 570 | read answer |
---|
| 571 | if [[ "$answer" = l ]] |
---|
| 572 | then |
---|
| 573 | more ${remote_hostname}_last_make_protokoll |
---|
| 574 | fi |
---|
| 575 | done |
---|
| 576 | if [[ $answer = k ]] |
---|
| 577 | then |
---|
| 578 | locat=user_abort; exit |
---|
| 579 | fi |
---|
| 580 | fi |
---|
| 581 | fi |
---|
| 582 | |
---|
| 583 | # TAR UPDATED VERSION ON THE REMOTE HOST |
---|
| 584 | printf "\n *** tar update on remote host ..." |
---|
| 585 | echo "cd ${remote_make_depository}; chmod u+w *; tar -cf ${program_name}_current_version.tar ${program_name} *.f90 *.o *.mod *.x" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 |
---|
| 586 | |
---|
| 587 | |
---|
| 588 | # NOW COMES THE BRANCH FOR CREATING THE EXECUTABLE FOR THE CURRENT RUN |
---|
| 589 | # INCLUDING E.G. USER-INTERFACE ROUTINES. ALSO ADD OTHER UTILITY EXECUTABLES. EVERYTHING IS |
---|
| 590 | # COLLECTED IN DIRECTORY SOURCES_FOR_RUN_... |
---|
| 591 | elif [[ "$fname" != "" ]] |
---|
| 592 | then |
---|
| 593 | |
---|
| 594 | # FIRST CHECK, IF A DEPOSITORY EXISTS ON THE REMOTE MACHINE |
---|
| 595 | echo "[[ ! -d ${remote_make_depository} ]] && echo depository not found" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 | tee ${remote_hostname}_last_make_protokoll |
---|
| 596 | |
---|
| 597 | |
---|
| 598 | # COPY MAKE DEPOSITORY ON REMOTE MACHINE TO SOURCES_FOR_RUN_... |
---|
| 599 | printf "\n *** copy MAKE_DEPOSITORY on remote host to SOURCES_FOR_RUN_$fname \n" |
---|
| 600 | echo "rm -rf $tmp_user_catalog/SOURCES_FOR_RUN_$fname; mkdir $tmp_user_catalog/SOURCES_FOR_RUN_$fname; cp ${remote_make_depository}/${program_name}_current_version.tar $tmp_user_catalog/SOURCES_FOR_RUN_$fname; cd $tmp_user_catalog/SOURCES_FOR_RUN_$fname; tar xf ${program_name}_current_version.tar" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 |
---|
| 601 | |
---|
| 602 | |
---|
| 603 | # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_... ON THE REMOTE MACHINE |
---|
| 604 | printf "\n *** copy $base_directory/SOURCES_FOR_RUN_$fname to SOURCES_FOR_RUN_$fname on remote host \n" |
---|
| 605 | scp -q $ssh_key $base_directory/SOURCES_FOR_RUN_$fname/{*,.[!.]*} ${remote_username}@${remote_ip}:${tmp_user_catalog}/SOURCES_FOR_RUN_$fname |
---|
| 606 | |
---|
| 607 | |
---|
| 608 | # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY |
---|
| 609 | if [[ $(ls -1 $base_directory/SOURCES_FOR_RUN_$fname/ | grep -c .$suf) != 0 ]] |
---|
| 610 | then |
---|
| 611 | |
---|
| 612 | make_call_string="make $make_options PROG=$program_name F90=$compiler_name COPT=\"$cpp_options\" F90FLAGS=\"$compiler_options\" LDFLAGS=\"$loader_options\" " |
---|
| 613 | [[ "$login_init_cmd" != "" ]] && login_init_cmd=${login_init_cmd}";" |
---|
| 614 | [[ "$module_commands" != "" ]] && module_commands=${module_commands}";" |
---|
| 615 | echo " *** execute \"make\" on remote host" |
---|
| 616 | echo "$login_init_cmd $module_commands cd ${tmp_user_catalog}/SOURCES_FOR_RUN_$fname; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh -q $ssh_key ${remote_username}@${remote_ip} 2>&1 | tee ${remote_hostname}_last_make_protokoll |
---|
| 617 | |
---|
| 618 | if [[ $(grep -c MAKE_ERROR ${remote_hostname}_last_make_protokoll) != 0 ]] |
---|
| 619 | then |
---|
| 620 | printf "\a\n +++ error(s) occurred during compiling or linking on host \"$remote_hostname\" " |
---|
| 621 | if [[ $silent = false ]] |
---|
| 622 | then |
---|
| 623 | answer=dummy |
---|
| 624 | printf "\n" |
---|
| 625 | while [[ "$answer" != c && "$answer" != k ]] |
---|
| 626 | do |
---|
| 627 | printf " >>> continue / list errors / kill palmbuild (c/l/k) ? " |
---|
| 628 | read answer |
---|
| 629 | if [[ "$answer" = l ]] |
---|
| 630 | then |
---|
| 631 | more ${remote_hostname}_last_make_protokoll |
---|
| 632 | fi |
---|
| 633 | done |
---|
| 634 | if [[ $answer = k ]] |
---|
| 635 | then |
---|
| 636 | locat=user_abort; exit |
---|
| 637 | fi |
---|
| 638 | fi |
---|
| 639 | fi |
---|
| 640 | |
---|
| 641 | else |
---|
| 642 | |
---|
| 643 | echo " *** nothing to compile for this run" |
---|
| 644 | |
---|
| 645 | fi |
---|
| 646 | |
---|
| 647 | fi |
---|
| 648 | |
---|
| 649 | rm -rf ${remote_hostname}_last_make_protokoll |
---|
| 650 | |
---|
| 651 | |
---|
| 652 | # MAKE ON LOCAL HOST |
---|
| 653 | else |
---|
| 654 | |
---|
| 655 | |
---|
| 656 | # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_... ON THE |
---|
| 657 | # LOCAL HOST |
---|
| 658 | if [[ "$fname" = "" ]] |
---|
| 659 | then |
---|
| 660 | |
---|
| 661 | # SET THE ENVIRONMENT (EXECUTE INIT AND MODULE COMMANDS) |
---|
| 662 | if [[ "$login_init_cmd" != "" ]] |
---|
| 663 | then |
---|
| 664 | $login_init_cmd |
---|
| 665 | fi |
---|
| 666 | |
---|
| 667 | if [[ "$module_commands" != "" ]] |
---|
| 668 | then |
---|
| 669 | $module_commands |
---|
| 670 | fi |
---|
| 671 | |
---|
| 672 | |
---|
| 673 | # CREATE MAKE-DEPOSITORY, IF IT DOES NOT EXIST |
---|
| 674 | eval local_make_depository=$local_make_depository |
---|
| 675 | if [[ ! -d $local_make_depository ]] |
---|
| 676 | then |
---|
| 677 | if mkdir $local_make_depository |
---|
| 678 | then |
---|
| 679 | printf "\n\n *** directory for local make depository:" |
---|
| 680 | printf "\n $local_make_depository" |
---|
| 681 | printf "\n was created\n" |
---|
| 682 | else |
---|
| 683 | printf "\n +++ directory for local make depository:" |
---|
| 684 | printf "\n $local_make_depository" |
---|
| 685 | printf "\n cannot be created" |
---|
| 686 | locat=local_depository_path; exit |
---|
| 687 | fi |
---|
| 688 | fi |
---|
| 689 | |
---|
| 690 | # COPY SOURCE-CODE FROM REPOSITORY TO MAKE-DEPOSITORY |
---|
| 691 | echo " " |
---|
| 692 | echo " *** untar current source sources on local host in" |
---|
| 693 | echo " $local_make_depository" |
---|
| 694 | cd $local_make_depository |
---|
| 695 | cp $source_path/${program_name}_sources.tar . |
---|
| 696 | tar xf ${program_name}_sources.tar |
---|
| 697 | |
---|
| 698 | |
---|
| 699 | # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES |
---|
| 700 | echo " " |
---|
| 701 | echo " *** creating utilities on local host" |
---|
| 702 | make -f Makefile_utilities $make_options F90=$compiler_name F90_SER=$compiler_name_ser COPT="$cpp_options" F90FLAGS="$compiler_options" LDFLAGS="$loader_options" |
---|
| 703 | |
---|
| 704 | |
---|
| 705 | # CALL MAKE ON LOCAL HOST USING THE OPTIONS DETERMINED FURTHER ABOVE |
---|
| 706 | echo " " |
---|
| 707 | echo " *** compile PALM sources on local host" |
---|
| 708 | |
---|
| 709 | make $make_options PROG=$program_name F90=$compiler_name COPT="$cpp_options" F90FLAGS="$compiler_options" LDFLAGS="$loader_options" 2>&1 | tee ${local_hostname}_last_make_protokoll |
---|
| 710 | |
---|
| 711 | if [[ $? != 0 ]] |
---|
| 712 | then |
---|
| 713 | printf "\a\n +++ error(s) occurred during compiling or linking on host \"$local_hostname\" " |
---|
| 714 | if [[ $silent = false ]] |
---|
| 715 | then |
---|
| 716 | answer=dummy |
---|
| 717 | printf "\n" |
---|
| 718 | while [[ "$answer" != c && "$answer" != k ]] |
---|
| 719 | do |
---|
| 720 | printf " >>> continue / list errors / kill palmbuild (c/l/k) ? " |
---|
| 721 | read answer |
---|
| 722 | if [[ "$answer" = l ]] |
---|
| 723 | then |
---|
| 724 | more ${local_hostname}_last_make_protokoll |
---|
| 725 | fi |
---|
| 726 | done |
---|
| 727 | if [[ $answer = k ]] |
---|
| 728 | then |
---|
| 729 | locat=user_abort; exit |
---|
| 730 | fi |
---|
| 731 | fi |
---|
| 732 | fi |
---|
| 733 | |
---|
| 734 | |
---|
| 735 | # TAR NEW VERSION ON LOCAL HOST |
---|
| 736 | printf "\n *** tar update on local host ..." |
---|
| 737 | tar -cf ${program_name}_current_version.tar ${program_name} *.$suf *.o *.mod *.x |
---|
| 738 | |
---|
| 739 | else |
---|
| 740 | |
---|
| 741 | # NOW COMES THE BRANCH FOR CREATING THE EXECUTABLE FOR THE CURRENT RUN |
---|
| 742 | # INCLUDING E.G. USER-INTERFACE ROUTINES. ALSO ADD OTHER UTILITY EXECUTABLES. EVERYTHING IS |
---|
| 743 | # COLLECTED IN DIRECTORY SOURCES_FOR_RUN_... |
---|
| 744 | |
---|
| 745 | # FIRST CHECK, IF A DEPOSITORY EXISTS ON THE LOCAL MACHINE |
---|
| 746 | if [[ ! -d ${local_make_depository} ]] |
---|
| 747 | then |
---|
| 748 | printf "\n +++ directory for local make depository:" |
---|
| 749 | printf "\n $local_make_depository" |
---|
| 750 | printf "\n not found. Please run \"palmbuild -h $host\" " |
---|
| 751 | locat=local_make_depository; exit |
---|
| 752 | fi |
---|
| 753 | |
---|
| 754 | |
---|
| 755 | # COPY MAKE DEPOSITORY ON LOCAL MACHINE TO SOURCES_FOR_RUN_... |
---|
| 756 | printf "\n *** copy MAKE_DEPOSITORY on local host to " |
---|
| 757 | printf "\n $tmp_user_catalog/SOURCES_FOR_RUN_$fname \n" |
---|
| 758 | rm -rf $tmp_user_catalog/SOURCES_FOR_RUN_$fname |
---|
| 759 | mkdir $tmp_user_catalog/SOURCES_FOR_RUN_$fname |
---|
| 760 | cp ${local_make_depository}/${program_name}_current_version.tar $tmp_user_catalog/SOURCES_FOR_RUN_$fname |
---|
| 761 | cd $tmp_user_catalog/SOURCES_FOR_RUN_$fname |
---|
| 762 | tar xf ${program_name}_current_version.tar |
---|
| 763 | |
---|
| 764 | |
---|
| 765 | # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_... |
---|
| 766 | # IN THE TMP_USER_CATALOG ON THE LOCAL MACHINE |
---|
| 767 | printf "\n *** copy $base_directory/SOURCES_FOR_RUN_$fname to" |
---|
| 768 | printf "\n $tmp_user_catalog/SOURCES_FOR_RUN_$fname on local host \n" |
---|
| 769 | cp $base_directory/SOURCES_FOR_RUN_$fname/{*,.[!.]*} ${tmp_user_catalog}/SOURCES_FOR_RUN_$fname |
---|
| 770 | |
---|
| 771 | |
---|
| 772 | # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY |
---|
| 773 | if [[ $(ls -1 $base_directory/SOURCES_FOR_RUN_$fname/ | grep -c .$suf) != 0 ]] |
---|
| 774 | then |
---|
| 775 | |
---|
| 776 | echo " *** execute \"make\" on local host" |
---|
| 777 | [[ "$login_init_cmd" != "" ]] && $login_init_cmd |
---|
| 778 | [[ "$module_commands" != "" ]] && $module_commands |
---|
| 779 | |
---|
| 780 | make $make_options PROG=$program_name F90=$compiler_name COPT="$cpp_options" F90FLAGS="$compiler_options" LDFLAGS="$loader_options" |
---|
| 781 | |
---|
| 782 | if [[ \$? != 0 ]] |
---|
| 783 | then |
---|
| 784 | |
---|
| 785 | printf "\a\n +++ error(s) occurred during compiling or linking on host \"$local_hostname\" " |
---|
| 786 | if [[ $silent = false ]] |
---|
| 787 | then |
---|
| 788 | answer=dummy |
---|
| 789 | printf "\n" |
---|
| 790 | while [[ "$answer" != c && "$answer" != k ]] |
---|
| 791 | do |
---|
| 792 | printf " >>> continue / list errors / kill palmbuild (c/k) ? " |
---|
| 793 | read answer |
---|
| 794 | done |
---|
| 795 | if [[ $answer = k ]] |
---|
| 796 | then |
---|
| 797 | locat=user_abort; exit |
---|
| 798 | fi |
---|
| 799 | fi |
---|
| 800 | fi |
---|
| 801 | |
---|
| 802 | else |
---|
| 803 | |
---|
| 804 | echo " *** nothing to compile for this run" |
---|
| 805 | |
---|
| 806 | fi |
---|
| 807 | |
---|
| 808 | fi |
---|
| 809 | fi |
---|