photos_montage_aladin.sh 59.4 KB
Newer Older
PENGUEN Julien's avatar
PENGUEN Julien committed
1 2 3 4 5 6 7
#!/bin/sh

. ./.env

#---------------------------#
#-------- functions --------#
#---------------------------#
8

9 10 11 12 13 14 15
function_message()
{
  # function_message: display message with input argument
  # input error_message to display

  type_message=$1
  message=$2
16
  option=$3
17 18
  color=$4
  status=$5
19 20 21 22 23 24

  if [ "$type_message" == "TYPE_VAL_ERROR" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
25
    echo -e "${RED}========================================================="
26
    echo -e "WARNING => ${message}"
27
    echo -e "=========================================================${COLOR_OFF}"
28

29 30 31 32 33
  elif [ "$type_message" == "TYPE_MOUNT_ERROR" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
34
    echo -e "${RED}==================================================================="
35 36
    echo -e "${message}"
    echo -e "on volume mounted : ${option}"
37 38 39 40 41 42 43 44 45 46 47 48 49 50
    echo -e "===================================================================${COLOR_OFF}"

  elif [ "$type_message" == "TYPE_MOUNT_INFOS" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
    echo -e "${color}========================================================================="
    echo -e "                                 ${status}"
    echo -e ""
    echo -e "Volume mounted : ${option}"
    echo -e "${message}"
    echo ""
    echo -e "=========================================================================${COLOR_OFF}"
51

52 53 54 55 56
  elif [ "$type_message" == "TYPE_FILE_ERROR" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
57
    echo -e "${RED}========================================================="
58 59 60
    echo -e "          ERROR with option '${option}' "
    echo -e ""
    echo -e "${message}"
61
    echo -e "=========================================================${COLOR_OFF}"
62 63 64
    echo ""
    echo "------------------------------------"

65 66 67 68 69
  elif [ "$type_message" == "TYPE_NOT_NUMBER" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
70
    echo -e "${RED}========================================================="
71 72 73
    echo -e "          ERROR with option '${option}' "
    echo -e ""
    echo -e "${message}"
74
    echo -e "=========================================================${COLOR_OFF}"
75 76 77
    echo ""
    echo "------------------------------------"

78 79 80 81 82
  elif [ "$type_message" == "TYPE_HELP" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
83
    echo -e "${GREEN}========"
84
    echo -e "= HELP ="
85
    echo -e "========${COLOR_OFF}"
86 87 88

  elif [ "$type_message" == "TYPE_UNKNOWN" ]; then
    echo ""
89
    echo -e "${RED}==============================="
90
    echo -e " error: unrecognized arguments "
91
    echo -e "===============================${COLOR_OFF}"
92 93 94 95

  elif [ "$type_message" == "TYPE_EXIST_VERSION" ]; then

    echo ''
96
    echo -e "${RED}===================================="
97
    echo -e "             WARNING"
98
    echo -e "====================================${COLOR_OFF}"
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    echo ''
    echo '------------------------------------'
    echo ''
    echo "You must select an existing version"
    echo "            available on   "
    echo "   https://aladin.u-strasbg.fr   "
    echo ''
    echo 'To see the available version(s):'
    echo ''
    echo "Please make ./photos_montage_aladin.sh -i OR --infos"
    echo ''
    echo '------------------------------------'
    echo ''


  elif [ "$type_message" == "TYPE_FORCE_WARNING" ]; then

    echo ''
117
    echo -e "${RED}===================================="
118
    echo -e "             WARNING"
119
    echo -e "====================================${COLOR_OFF}"
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    echo ''
    echo '------------------------------------'
    echo ''
    echo "With option --force you must select an existing area"
    echo ''
    echo 'Please see the available area(s) on:'
    echo ''
    echo "${message}"
    echo ''
    echo '------------------------------------'
    echo ''

  elif [ "$type_message" == "TYPE_DELETE_EXIST_VERSION" ]; then

    echo ''
135
    echo -e "${RED}===================================="
136
    echo -e "             WARNING"
137
    echo -e "====================================${COLOR_OFF}"
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    echo ''
    echo '------------------------------------'
    echo ''
    echo "You must delete an existing version"
    echo "    available on the localhost     "
    echo ''
    echo 'To see the available version(s):'
    echo ''
    echo "Please make ./photos_montage_aladin.sh -i OR --infos"
    echo ''
    echo '------------------------------------'
    echo ''

  elif [ "$type_message" == "TYPE_UPDATE" ]; then

    echo ''
    echo '========================================'
    echo '     YOU ARE NOT USING THE LAST         '
    echo '            ALADIN VERSION              '
    echo '========================================'
    echo ''
    echo '=> A new ALADIN version is available:' ${message}
    echo ''
    echo 'COMMAND TO UPDATE ALADIN VERSION:'
    echo ''
    echo '=> ./photos_montage_aladin.sh -u OR --update'
    echo '------------------------------------'
    echo ''
    echo ''

  else

    echo "BLA BLA"

  fi

  if [[ "$type_message" == "TYPE_VAL_ERROR" || "$type_message" == "TYPE_HELP" || "$type_message" == "TYPE_UNKNOWN" ]]; then

    echo ""
    echo "------------------------------------"
    echo ""
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    echo -e "use : ${BOLD_BEGIN}./photos_montage_aladin.sh${BOLD_END} [${ITALIC_BEGIN}OPTIONS${ITALIC_END}] [${ITALIC_BEGIN}OTHERS${ITALIC_END}]"
    echo -e ""
    echo -e ""
    echo -e "[${ITALIC_BEGIN}OPTIONS${ITALIC_END}]:"
    echo -e ""
    echo -e "${BOLD_BEGIN}-i${BOLD_END}, ${BOLD_BEGIN}--infos${BOLD_END}                        give informations about versions available on aladin server, "
    echo -e "                                   about photos_montage_aladin image present on localhost and about "
    echo -e "                                   Options by default define on .env file"
    echo -e ""
    echo -e "${BOLD_BEGIN}-b${BOLD_END} ${ITALIC_BEGIN}VERSION${ITALIC_END}, ${BOLD_BEGIN}--build${BOLD_END} ${ITALIC_BEGIN}VERSION${ITALIC_END}        build photos_montage_aladin image with selected ${ITALIC_BEGIN}VERSION${ITALIC_END}"
    echo -e ""
    echo -e "${BOLD_BEGIN}--select${BOLD_END} ${ITALIC_BEGIN}VERSION${ITALIC_END}                   run photos_montage_aladin with selected ${ITALIC_BEGIN}VERSION${ITALIC_END}"
    echo -e ""
    echo -e "${BOLD_BEGIN}--force-all ${BOLD_END}                       re-run all areas in input csv"
    echo -e ""
    echo -e "${BOLD_BEGIN}--force${BOLD_END} ${ITALIC_BEGIN}AREA${ITALIC_END}                       re-run for the ${ITALIC_BEGIN}AREA${ITALIC_END}, the ${ITALIC_BEGIN}AREA${ITALIC_END} must be in input csv"
    echo -e ""
    echo -e "${BOLD_BEGIN}-u${BOLD_END}, ${BOLD_BEGIN}--update ${BOLD_END}                      update photos_montage_aladin image version"
    echo -e ""
    echo -e "${BOLD_BEGIN}-rm${BOLD_END} ${ITALIC_BEGIN}VERSION${ITALIC_END}, ${BOLD_BEGIN}--remove${BOLD_END} ${ITALIC_BEGIN}VERSION${ITALIC_END}      remove photos_montage_aladin image with selected ${ITALIC_BEGIN}VERSION${ITALIC_END}"
    echo -e ""
    echo -e "${BOLD_BEGIN}-h, ${BOLD_BEGIN}--help${BOLD_END}                         show this help message and exit"
    echo -e ""
    echo -e "${BOLD_BEGIN}-v, ${BOLD_BEGIN}--version${BOLD_END}                      give photos_montage_aladin.sh current version number"
    echo -e ""
    echo -e ""
    echo -e "[${ITALIC_BEGIN}OTHERS${ITALIC_END}]: (available only with ${BOLD_BEGIN}no option${BOLD_END} OR with ${BOLD_BEGIN}--select option${BOLD_END})"
    echo -e ""
    echo -e "${BOLD_BEGIN}--survey${BOLD_END} ${ITALIC_BEGIN}FILE${ITALIC_END}                      run photos_montage_aladin with this surveys ${ITALIC_BEGIN}FILE${ITALIC_END} instead of "
    echo -e "                                   the default file define on .env file. The survey ${ITALIC_BEGIN}FILE${ITALIC_END}"
    echo -e "                                   must be on format '.dat'"
    echo -e ""
    echo -e "${BOLD_BEGIN}--area${BOLD_END} ${ITALIC_BEGIN}FILE${ITALIC_END}                        run photos_montage_aladin with this areas ${ITALIC_BEGIN}FILE${ITALIC_END} instead of "
    echo -e "                                   the default file define on .env file. the area ${ITALIC_BEGIN}FILE${ITALIC_END}"
    echo -e "                                   must be on format '.csv'"
    echo -e ""
215 216 217 218
    echo -e "${BOLD_BEGIN}--output_folder${BOLD_END} ${ITALIC_BEGIN}FOLDER${ITALIC_END}             run photos_montage_aladin with this output folder ${ITALIC_BEGIN}FOLDER${ITALIC_END} instead of "
    echo -e "                                   the default folder define on .env file. the user must have"
    echo -e "                                   the rights to write on the output folder ${ITALIC_BEGIN}FOLDER${ITALIC_END}"
    echo -e ""
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
    echo -e "${BOLD_BEGIN}--angular${BOLD_END} ${ITALIC_BEGIN}NUMBER${ITALIC_END}                   run photos_montage_aladin with this angular dimension value (${ITALIC_BEGIN}NUMBER${ITALIC_END}) "
    echo -e "                                   instead of the default angular value define on .env file."
    echo -e "                                   the angular value (${ITALIC_BEGIN}NUMBER${ITALIC_END}) must be on second of arc"
    echo -e ""
    echo -e "${BOLD_BEGIN}--resolution_col${BOLD_END} ${ITALIC_BEGIN}NUMBER${ITALIC_END}            run photos_montage_aladin with this ${ITALIC_BEGIN}NUMBER${ITALIC_END} of pixel by columns "
    echo -e "                                   for the Image Magick montages"
    echo -e ""
    echo -e "${BOLD_BEGIN}--resolution_line${BOLD_END} ${ITALIC_BEGIN}NUMBER${ITALIC_END}           run photos_montage_aladin with this ${ITALIC_BEGIN}NUMBER${ITALIC_END} of pixel by lines "
    echo -e "                                   for the Image Magick montages"
    echo -e ""
    echo -e "${BOLD_BEGIN}--nb_tile_col${BOLD_END} ${ITALIC_BEGIN}NUMBER${ITALIC_END}               run photos_montage_aladin with this ${ITALIC_BEGIN}NUMBER${ITALIC_END} of tiles by columns "
    echo -e "                                   for the Image Magick montages"
    echo -e ""
    echo -e "${BOLD_BEGIN}--nb_tile_line${BOLD_END} ${ITALIC_BEGIN}NUMBER${ITALIC_END}              run photos_montage_aladin with this ${ITALIC_BEGIN}NUMBER${ITALIC_END} of tiles by lines "
    echo -e "                                   for the Image Magick montages"
    echo -e ""
    echo -e "${BOLD_BEGIN}--mount${BOLD_END} ${ITALIC_BEGIN}PATH${ITALIC_END}                       run photos_montage_aladin with a volume mounted (${ITALIC_BEGIN}PATH${ITALIC_END}) "
    echo -e "                                   on docker container repository /mnt "
    echo -e ""
238 239 240 241 242
  fi

}


243
function_build_tab_hach()
PENGUEN Julien's avatar
PENGUEN Julien committed
244
{
245 246 247 248 249 250 251
  # function_build_tab_hach: retrieve and organize $@
  # on differents arrays
  # return:
  # - tab_keys: array of options present on $@
  # - tab_values: array of argument need for each option present on $@
  # - tab_weight: array of weight need for each option present on $@
  # - val_error: TRUE or FALSE depending on error
252
  # - message: in case of error, error message
253 254 255 256 257 258 259 260 261 262

  # ---------------------- #
  # ARRAY[key]=value
  #declaration of the ARRAY
  #containing the options
  #allowed by the program
  #and if there is an argument With
  #the option
  # => key : option
  # => value : None or argument
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282

  declare -A ARRAY

  ARRAY["-i"]="None";
  ARRAY["--infos"]="None";
  ARRAY["-b"]="VERSION";
  ARRAY["--build"]="VERSION";
  ARRAY["--select"]="VERSION";
  ARRAY["--force-all"]="None";
  ARRAY["--force"]="AREA";
  ARRAY["-u"]="None";
  ARRAY["--update"]="None";
  ARRAY["-rm"]="VERSION";
  ARRAY["--remove"]="VERSION";
  ARRAY["-h"]="None";
  ARRAY["--help"]="None";
  ARRAY["-v"]="None";
  ARRAY["--version"]="None";
  ARRAY["--survey"]="PATH FILE SURVEYS";
  ARRAY["--area"]="PATH FILE AREAS";
283
  ARRAY["--output_folder"]="PATH OUTPUT FOLDER";
284
  ARRAY["--angular"]="NUMBER";
285 286
  ARRAY["--resolution_line"]="NUMBER";
  ARRAY["--resolution_col"]="NUMBER";
287 288
  ARRAY["--nb_tile_line"]="NUMBER";
  ARRAY["--nb_tile_col"]="NUMBER";
289
  ARRAY["--mount"]="PATH VOLUME";
290

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
  # ---------------------- #
  # ARRAY_WEIGHT[key]=value
  #declaration of the ARRAY_WEIGHT
  #containing the options
  #allowed by the program
  #and the weight of each option
  # => key : option
  # => value : weight

  declare -A ARGS_WEIGHT

  ARGS_WEIGHT["--select"]=0;
  ARGS_WEIGHT["--no_select"]=0;
  ARGS_WEIGHT["--force-all"]=1;
  ARGS_WEIGHT["--force"]=1;
  ARGS_WEIGHT["--update"]=1;
  ARGS_WEIGHT["-u"]=1;
  ARGS_WEIGHT["-i"]=1;
  ARGS_WEIGHT["--infos"]=1;
  ARGS_WEIGHT["-b"]=1;
  ARGS_WEIGHT["--build"]=1;
  ARGS_WEIGHT["-rm"]=1;
  ARGS_WEIGHT["--remove"]=1;
  ARGS_WEIGHT["-h"]=1;
  ARGS_WEIGHT["--help"]=1;
  ARGS_WEIGHT["-v"]=1;
  ARGS_WEIGHT["--version"]=1;
  ARGS_WEIGHT["--survey"]=2;
  ARGS_WEIGHT["--area"]=2;
320
  ARGS_WEIGHT["--output_folder"]=2;
321
  ARGS_WEIGHT["--angular"]=2;
322 323
  ARGS_WEIGHT["--resolution_line"]=2;
  ARGS_WEIGHT["--resolution_col"]=2;
324 325
  ARGS_WEIGHT["--nb_tile_line"]=2;
  ARGS_WEIGHT["--nb_tile_col"]=2;
326
  ARGS_WEIGHT["--mount"]=2;
327

328 329 330 331 332 333
  # -------- #

  indice=0;

  for params in "$@"
  do
334 335
    tab_params[$indice]=$params
    ((indice++));
336 337 338 339
  done

  # -------- #
  val_error="FALSE"
340
  elements_ok=0
341 342 343 344 345 346 347 348 349 350

  for elem in ${!ARRAY[*]} ; do

    indice=0;

    for param in "$@" #loop on input args
    do
      if [ "${elem}" == $param ]; then
        #if option of ARRAY is find among input argument

351
        elements_ok=$(($elements_ok + 1))
352 353
        tab_keys[$indice]=$elem
        tab_values[$indice]="None"
354
        tab_weight[$indice]=${ARGS_WEIGHT[${elem}]}
355 356 357 358 359 360

        if [ "${ARRAY[${elem}]}" != "None" ]; then
          #case argument needed for the option

          FOUND=$(echo ${!ARRAY[*]} | grep -- "${tab_params[$indice +1]}")

361 362
          if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" && ${tab_params[$indice +1]} != -* ]]; then
            #case argument needed for the option is present on input argument
363
            tab_values[$indice]=${tab_params[$indice +1]}
364
            elements_ok=$(($elements_ok + 1))
365
          else
366
            #case argument needed for the option is missing on input argument
367
            message="Missing argument for the option "${elem}
368 369 370 371 372 373 374 375 376 377 378 379 380
            val_error="TRUE"
          fi

        fi

      fi

      ((indice++));

    done

  done

381
  if [ "$val_error" == "FALSE" ]; then
PENGUEN Julien's avatar
PENGUEN Julien committed
382

383 384 385 386 387 388 389 390 391 392
    if [ "$elements_ok" -ne "${#@}" ]; then

      val_error="TRUE"
      message="Option not found"
    else
      val_error="FALSE"
    fi
  fi

  echo "${tab_keys[@]},${tab_values[@]},${tab_weight[@]},$val_error,$message"
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448

}

function_sort_tab()
{
  # function_sort_tab: sort input arrays depending on weight
  # inputs:
  # - tab_keys: array of options present on $@
  # - tab_values: array of argument need for each option present on $@
  # - tab_weight: array of weight need for each option present on $@
  # return:
  # - sort_arg_keys: array 'tab_keys' sorted by weight
  # - sort_arg_values: array 'tab_values' sorted by weight
  # - sort_arg_weight: array 'tab_weight' sorted by weight

  #--------------------------#
  # retrieving input arrays
  tab_arg_keys=$1
  tab_arg_values=$2
  tab_arg_weight=$3

  arg_keys=( ${tab_arg_keys// / } )
  arg_values=( ${tab_arg_values// / } )
  arg_weight=( ${tab_arg_weight// / } )

  #--------------------------#
  indice=0
  indice_weight=0
  l=0

  #--------------------------#
  # sorts input arrays

  while [ $indice -ne ${#arg_weight[@]} ];
   do
    if [ ${arg_weight[$l]} -eq $indice_weight ]; then
      sort_arg_keys[$indice]=${arg_keys[$l]}
      sort_arg_values[$indice]=${arg_values[$l]}
      sort_arg_weight[$indice]=${arg_weight[$l]}
      indice=$(($indice + 1))
      l=$(($l + 1))
    else
      l=$(($l + 1))
    fi

    if [ $l -eq ${#arg_weight[@]} ]; then
      l=0
      indice_weight=$(($indice_weight + 1))
    fi

   done

  #--------------------------#
  #return arrays sorted

  echo "${sort_arg_keys[@]},${sort_arg_values[@]},${sort_arg_weight[@]}"
PENGUEN Julien's avatar
PENGUEN Julien committed
449 450 451

}

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
function_return_indice_arg()
{
  # function_return_indice_arg: get the indice in input array of the element we want
  # input:
  # -tab: array of options present on $@
  # -find_arg: option we want find
  # return:
  # -indice of the option we want find

  #---------------#
  #input arguments
  tab=$1
  find_arg=$2
  #---------------#

  tempo_tab=( ${tab// / } )
  val="None"

  #------------------------------------#
  #loop to find indice of option we want
  for k in ${!tempo_tab[*]}
  do
    if [ "${tempo_tab[$k]}" == "$find_arg" ]; then
      val=$k
    fi
  done
  #------------------------------------#

  echo $val

}

484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
function_check_and_replace()
{
# function_check_and_replace: check if input args is in tab and replace val
#
# inputs:
# -tab_keys: keys array of options present on $@
# -tab_keys: values array of options present on $@
# -find_arg: option we want find
# -val_arg: option value by default

tab_keys=$1
tab_values=$2
find_arg=$3
val_arg=$4

tempo_tab_keys=( ${tab_keys// / } )
tempo_tab_values=( ${tab_values// / } )

if [[ "${tempo_tab_keys[@]}" =~ $find_arg ]]; then
  indice=`function_return_indice_arg "${tempo_tab_keys[*]}" $find_arg`
  echo "${sort_arg_values[$indice]}"

else
  echo ${val_arg}
fi

510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
}

function function_check_select_option()
{


#------------------------------------#
#check options presents
#to manage '--select' and '--no_select'
#options

tab_arg_keys=$1
tab_arg_values=$2
tab_arg_weight=$3
#------------------------------------#

tempo_arg_weight=( ${tab_arg_weight// / } )
tempo_arg_keys=( ${tab_arg_keys// / } )
taille=${#tempo_arg_weight[@]}

case $taille in
  "0")
    #---------------------#
    #case 0 input argument
    #---------------------#
    tab_arg_keys[0]="--no_select"
    tab_arg_values[0]="$ALADIN_VERSION"
    tab_arg_weight[0]=0
    arg_keys=( ${tab_arg_keys[@]// / } )
    arg_values=( ${tab_arg_values[@]// / } )
    arg_weight=( ${tab_arg_weight[@]// / } )

    ;;
  "1")
    #---------------------#
    #case 1 input argument
    #---------------------#
    if [ "${tempo_arg_weight[0]}" -eq 0 ]; then
      # case option with weight=0 ('--select')

      arg_keys=( ${tab_arg_keys// / } )
      arg_values=( ${tab_arg_values// / } )
      arg_weight=( ${tab_arg_weight// / } )


    elif [ "${tempo_arg_weight[0]}" -eq 1 ]; then
      #case option with weight=1

      if [[ "${tempo_arg_keys[0]}" == '--force-all' || "${tempo_arg_keys[0]}" == '--force' ]]; then
        #case '--force_all', '--force'

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )

      else
        #case '-i','--infos','-u','--update','-h','-v','--version'

        arg_keys=( ${tab_arg_keys// / } )
        arg_values=( ${tab_arg_values// / } )
        arg_weight=( ${tab_arg_weight// / } )

      fi


    elif [ "${tempo_arg_weight[0]}" -eq 2 ]; then
        #case '--survey', '--area' ,'--angular'
        #'--resolution_line', '--resolution_col',
584
        #'--nb_tile_line','--nb_tile_col' '--mount'
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )


    else

      echo '=> No case possible for the moment'

    fi

    ;;
  *)
    #-----------------------------#
    #case 2 or more input arguments
    #-----------------------------#
    for p in ${!tempo_arg_keys[*]}
    do

      if [ ${tempo_arg_weight[$p]} -eq 0 ]; then
        tempo_weight_0="TRUE"
      elif [ ${tempo_arg_weight[$p]} -eq 1 ]; then
        tempo_weight_1="TRUE"
        indice_tempo_weight_1=$p
      elif [ ${tempo_arg_weight[$p]} -eq 2 ]; then
        tempo_weight_2="TRUE"
      fi

    done

    if [[ "$tempo_weight_0" == 'TRUE' && "$tempo_weight_2" == 'FALSE' ]]; then
      #case '--select'
      arg_keys=( ${tab_arg_keys// / } )
      arg_values=( ${tab_arg_values// / } )
      arg_weight=( ${tab_arg_weight// / } )
    fi

    if [ "$tempo_weight_1" == 'TRUE' ]; then

      if [ "${tempo_arg_keys[$indice_tempo_weight_1]}" == '--force-all' ]; then
        #case '--force_all'

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )

      else
        #case '-i','--infos','-u','--update','-h','-v','--version'

        arg_keys=( ${tab_arg_keys// / } )
        arg_values=( ${tab_arg_values// / } )
        arg_weight=( ${tab_arg_weight// / } )

      fi


    fi

    if [ "$tempo_weight_2" == 'TRUE' ]; then
      #case '--survey', '--area' ,'--angular'
      #'--resolution_line', '--resolution_col',
659
      #'--nb_tile_line','--nb_tile_col', '--mount'
660 661 662 663 664 665 666 667 668 669 670 671 672 673

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )



    fi
674

675 676 677 678
    ;;
esac

  echo "${arg_keys[@]},${arg_values[@]},${arg_weight[@]}"
679 680 681 682


}

683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
function_check_number()
{
  # function_check_number: return 'TRUE' if input arg is a
  # number, if not "FALSE"

  var=$1

  if [[ $var = +([0-9]) ]] ; then
    reponse="TRUE"

  else
    reponse="FALSE"
  fi

  echo "$reponse"

}
700

701 702 703 704 705 706 707 708 709
function_check_permission_volume()
{
  # function_check_permission_volume: check if user have read and write
  # permissions for the input volume.
  # input: volume
  # returns:
  #    return TRUE if permission OK else FALSE
  volume=$1

710 711
  # volume_permissions=$(namei -l $volume | tail -n 1 | awk -F" " '{print $1}')
  volume_permissions=$(ls -ld $volume | tail -n 1 | awk -F" " '{print $1}')
712 713 714 715
  volume_type=${volume_permissions:0:1}
  volume_owner_permissions=${volume_permissions:1:3}
  volume_group_permissions=${volume_permissions:4:3}
  volume_others_permissions=${volume_permissions:7:3}
716 717
  volume_owner=$(ls -ld $volume | tail -n 1 | awk -F" " '{print $3}')
  volume_group_owner=$(ls -ld $volume | tail -n 1 | awk -F" " '{print $4}')
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829

  user_name=$(whoami)
  user_groups=$(id | awk -F " " '{print $3}' | sed 's/^groupes//g' | sed 's/[0-9()=]//g')
  tab_user_groups=( ${user_groups//,/ } )

  if [[ $user_name == $volume_owner ]]; then
  # -----------------------------------------#
  #       case user is volume owner
  # -----------------------------------------#

    if [[ $volume_owner_permissions == "rwx" || $volume_owner_permissions == "rw-" ]]; then
    #case user could read and write on volume

      AUTHORIZATION="TRUE"

    else
    #case user could not read and write on volume
    #we check group authorization

      if [[ "${tab_user_groups[@]}" =~ "$volume_group_owner" ]]; then
      #case group volume is in user group list

        if [[ $volume_group_permissions == "rwx" || $volume_group_permissions == "rw-" ]]; then
        #case group volume allow user to read and write
          AUTHORIZATION="TRUE"

        else
        #case group volume not allow user to read and write
        #we check other volume permissions

          if [[ $volume_others_permissions == "rwx" || $volume_others_permissions == "rw-" ]]; then
          #case other permissions volume allow user to read and write
            AUTHORIZATION="TRUE"

          else
          #case other permissions volume not allow user to read and write
            AUTHORIZATION="FALSE"

          fi

        fi

      else
        #case group volume is not in user group list
        #we check other volume permissions

        if [[ $volume_others_permissions == "rwx" || $volume_others_permissions == "rw-" ]]; then
        #case other permissions volume allow user to read and write
          AUTHORIZATION="TRUE"

        else
        #case other permissions volume not allow user to read and write
          AUTHORIZATION="FALSE"

        fi

      fi

    fi

  else
  # -----------------------------------------#
  #     case user is not  volume owner
  # -----------------------------------------#

      if [[ "${tab_user_groups[@]}" =~ "$volume_group_owner" ]]; then
      #case group volume is in user group list

        if [[ $volume_group_permissions == "rwx" || $volume_group_permissions == "rw-" ]]; then
        #case group volume allow user to read and write
          AUTHORIZATION="TRUE"

        else
        #case group volume not allow user to read and write
        #we check other volume permissions

          if [[ $volume_others_permissions == "rwx" || $volume_others_permissions == "rw-" ]]; then
          #case other permissions volume allow user to read and write
            AUTHORIZATION="TRUE"

          else
          #case other permissions volume not allow user to read and write
            AUTHORIZATION="FALSE"

          fi

        fi

      else
        #case group volume is not in user group list
        #we check other volume permissions

        if [[ $volume_others_permissions == "rwx" || $volume_others_permissions == "rw-" ]]; then
        #case other permissions volume allow user to read and write
          AUTHORIZATION="TRUE"

        else
        #case other permissions volume not allow user to read and write
          AUTHORIZATION="FALSE"

        fi

      fi


  fi


      echo "$AUTHORIZATION"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
830 831 832 833 834 835
function_jar_updated_search()
{
  # function_jar_updated_search: get the last jar version
  # returns:
  #    return number_version

836
  version=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3)
PENGUEN Julien's avatar
PENGUEN Julien committed
837 838 839 840 841
  number_version=$(echo ${version:1})
  echo "$number_version"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
842 843 844 845 846 847 848
function_delete_image()
{
  # function_delete_image: delete the image
  # params:
  #    $1 - photos_montage_aladin version image to delete

  echo "- Deleting the photos_montage_aladin-$1 docker image ..."
849

850 851
  old_id=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-$1)
  sudo docker rmi ${old_id} #remove old photos_montage_aladin image
852

PENGUEN Julien's avatar
PENGUEN Julien committed
853 854 855 856
  echo "=> Deleting the image_photos_montage_aladin-$1 docker image successfully"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
857 858 859 860 861 862
function_build_image()
{
  # function_build_image: build the photos_montage_aladin image

      version=$1

PENGUEN Julien's avatar
PENGUEN Julien committed
863
      #----------------------------------------#
864 865 866 867
      curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3 | sed 's/v//' > .temp
      curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/<!--/d'| sed '/last/!d' | cut -d">" -f3 | cut -d"<" -f1 | sed 's/\.jar//' | sed 's/Aladin//' >> .temp
      list_jar=$(sort -r .temp | awk '{print $1}')
      rm .temp
868

869
      present=$(echo $list_jar| grep "${version}")
PENGUEN Julien's avatar
PENGUEN Julien committed
870 871 872

      if [ $? -eq 1 ]; then

873
        function_message "TYPE_EXIST_VERSION"
PENGUEN Julien's avatar
PENGUEN Julien committed
874 875 876 877 878 879 880
        exit 0


      else

        echo ''
        echo "- Searching for the current photos_montage_aladin-${version} docker image ..."
881

882
        id_image=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-${version})
PENGUEN Julien's avatar
PENGUEN Julien committed
883 884 885

        if [ ${id_image} ]; then

PENGUEN Julien's avatar
PENGUEN Julien committed
886
          echo "=> The image_photos_montage_aladin-${version} docker image already exist"
PENGUEN Julien's avatar
PENGUEN Julien committed
887 888 889
          echo ''

        else
PENGUEN Julien's avatar
PENGUEN Julien committed
890 891

          #----------------------------------------#
892
          tempo=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3)
Julien Penguen's avatar
Julien Penguen committed
893

PENGUEN Julien's avatar
PENGUEN Julien committed
894
          aladin_last_number_version=$(echo ${tempo:1})
PENGUEN Julien's avatar
PENGUEN Julien committed
895
          #----------------------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
896

PENGUEN Julien's avatar
PENGUEN Julien committed
897
          if [ ${aladin_last_number_version} == ${version} ]; then
Julien Penguen's avatar
Julien Penguen committed
898
            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin.jar --no-check-certificate
899
            mv conf-montage/Aladin.jar conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
900
          else
Julien Penguen's avatar
Julien Penguen committed
901 902

            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin${version}.jar --no-check-certificate
PENGUEN Julien's avatar
PENGUEN Julien committed
903
            mv conf-montage/Aladin${version}.jar conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
904 905 906 907 908 909 910

          fi

          #-----------------#
          #build
          echo "- Creating the photos_montage_aladin-${version} docker image in progress ..."
          echo '------------------------------------------------------------------'
911 912 913

          sudo docker build --build-arg username=$USER --build-arg uidval=$UID --build-arg home=$HOME --build-arg aladin_version=${version} -t image_photos_montage_aladin-${version} conf-montage

PENGUEN Julien's avatar
PENGUEN Julien committed
914 915 916 917 918
          echo "=> creating the photos_montage_aladin-${version} docker image successfully"
          echo '------------------------------------------------------------------'
          echo ''
          #-----------------#

919
          rm conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
          rm .logfile

        fi
      fi

}



function_create_ajs_file()
{
  # function_create_ajs_file : create ajs surveys file

inputfile=$1
outputfile=$2
935 936
area=$3
ra_area=$4
PENGUEN Julien's avatar
PENGUEN Julien committed
937 938
dec_area=$5
outputfolder=$6
PENGUEN Julien's avatar
PENGUEN Julien committed
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953


list_survey=$(awk '{print $1}' $inputfile)

echo -e "reset" > ${outputfile}

number=0;

for survey in ${list_survey}
do
    i=0;
    ((number++));

    echo -e "#" >> ${outputfile}
    echo -e "rm @1" >> ${outputfile}
954
    echo -e "get HiPS("$survey", FITS)" ${ra_area} ${dec_area} ${ANGULAR}"'" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
955 956 957 958
    echo -e "cm BB localcut" >> ${outputfile}


    for val in `echo $survey | tr "/" " "`;
959
    do
PENGUEN Julien's avatar
PENGUEN Julien committed
960 961 962 963
     ((i++));
     tab[$i]=${val}
    done

PENGUEN Julien's avatar
PENGUEN Julien committed
964
    if [ $number -lt '10' ]; then
965
      chaine="0${number}_${area}-${tab[$i-1]}_${tab[$i]}.${FORMAT_IMAGES}"
PENGUEN Julien's avatar
PENGUEN Julien committed
966
    else
967
      chaine="${number}_${area}-${tab[$i-1]}_${tab[$i]}.${FORMAT_IMAGES}"
PENGUEN Julien's avatar
PENGUEN Julien committed
968 969
    fi
    echo -e "save 200x200 ${outputfolder}/$chaine" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
970 971 972 973 974 975 976 977 978 979 980


done



}
#-----------------------------------------#
#----------- main program ----------------#
#-----------------------------------------#

981 982
#---------------------#
# management arguments
983
# call function_sort_tab
984 985 986 987 988

RESULTAT=`function_build_tab_hach $@`

tab_arg_keys=`echo $RESULTAT | cut --delimiter=, -f 1`
tab_arg_values=`echo $RESULTAT | cut --delimiter=, -f 2`
989 990
tab_arg_weight=`echo $RESULTAT | cut --delimiter=, -f 3`
val_error=`echo $RESULTAT | cut --delimiter=, -f 4`
991

992
#------------------------------------#
993
#check if val_error is TRUE
994 995

if [ $val_error == "TRUE" ]; then
996
  error_message=`echo $RESULTAT | cut --delimiter=, -f 5`
997

998
  function_message "TYPE_VAL_ERROR" "${error_message}"
999 1000 1001
  exit 0
fi

1002 1003 1004
#----------------------------------------------------#
# check to manage '--select' and '--no_select options
# call function_check_select_option
1005

1006
RESULT_CHECK_SELECT=`function_check_select_option "${tab_arg_keys[*]}" "${tab_arg_values[*]}" "${tab_arg_weight[*]}"`
1007

1008 1009 1010
array_arg_keys=`echo $RESULT_CHECK_SELECT | cut --delimiter=, -f 1`
array_arg_values=`echo $RESULT_CHECK_SELECT | cut --delimiter=, -f 2`
array_arg_weight=`echo $RESULT_CHECK_SELECT | cut --delimiter=, -f 3`
1011

1012 1013 1014
arg_keys=( ${array_arg_keys// / } )
arg_values=( ${array_arg_values// / } )
arg_weight=( ${array_arg_weight// / } )
1015

1016
#--------------------------#
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
# sort the arrays arguments
# call function_sort_tab

RESULT_SORT=`function_sort_tab "${arg_keys[*]}" "${arg_values[*]}" "${arg_weight[*]}"`

tab_sort_arg_keys=`echo $RESULT_SORT | cut --delimiter=, -f 1`
tab_sort_arg_values=`echo $RESULT_SORT | cut --delimiter=, -f 2`
tab_sort_arg_weight=`echo $RESULT_SORT | cut --delimiter=, -f 3`

sort_arg_keys=( ${tab_sort_arg_keys// / } )
sort_arg_values=( ${tab_sort_arg_values// / } )
sort_arg_weight=( ${tab_sort_arg_weight// / } )

1030 1031 1032 1033 1034
#------------------------------#
#check volume_mount input args

VOLUME_MOUNT=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--mount" $VOLUME_MOUNT`

1035
if [ $VOLUME_MOUNT != "NONE" ];then
1036
  if [[ ! -d $VOLUME_MOUNT ]]; then
1037 1038 1039
    function_message "TYPE_FILE_ERROR" "$VOLUME_MOUNT not found" "--mount"
      exit 0
  fi
1040 1041
fi

1042
#------------------------------#
1043
#check survey input args
1044

1045
INPUT_FILE_SURVEYS=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--survey" $INPUT_FILE_SURVEYS`
1046

1047
if [ ! -f $INPUT_FILE_SURVEYS ]; then
1048 1049 1050 1051
  function_message "TYPE_FILE_ERROR" "$INPUT_FILE_SURVEYS not found" "--survey"
    exit 0
fi

1052 1053 1054 1055
#------------------------------#
#check area input args

INPUT_FILE_AREAS=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--area" $INPUT_FILE_AREAS`
1056

1057
if [ ! -f $INPUT_FILE_AREAS ]; then
1058 1059 1060 1061
  function_message "TYPE_FILE_ERROR" "$INPUT_FILE_AREAS not found" "--area"
    exit 0
fi

1062 1063 1064 1065 1066 1067 1068 1069
#------------------------------#
#check output_folder args

OUTPUT_FOLDER_ON_VOLUME_MOUNT="FALSE"
OLD_OUTPUT_FOLDER_LINUX=$OUTPUT_FOLDER_LINUX

OUTPUT_FOLDER_LINUX=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--output_folder" $OUTPUT_FOLDER_LINUX`

1070 1071
result_check_permission="TRUE"

1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
#----------------------------------------#
#check if OUTPUT_FOLDER is on VOLUME_MOUNT

if [[ $OUTPUT_FOLDER_LINUX != $OLD_OUTPUT_FOLDER_LINUX && $VOLUME_MOUNT != "NONE" ]]; then

  CHAINE=$(echo $OUTPUT_FOLDER_LINUX | grep "^$VOLUME_MOUNT")

  if [ "$CHAINE" != "" ]; then
    OUTPUT_FOLDER_ON_VOLUME_MOUNT="TRUE"

1082 1083
    result_check_permission=`function_check_permission_volume $VOLUME_MOUNT`

1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
  fi

fi
#----------------------------------------#


if [ ! -d $OUTPUT_FOLDER_LINUX ]; then
  function_message "TYPE_FILE_ERROR" "$OUTPUT_FOLDER_LINUX not found" "--output_folder"
    exit 0
fi


1096 1097 1098
#-------------------------------------#
#check angular input arg

1099
ANGULAR=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--angular" $ANGULAR`
1100

1101 1102 1103 1104 1105 1106 1107 1108 1109
ANGULAR_IS_NUMBER=`function_check_number "$ANGULAR"`

if [ $ANGULAR_IS_NUMBER != 'TRUE' ]; then

  function_message "TYPE_NOT_NUMBER" "ANGULAR must be an integer" "--angular"
  exit 0

fi

1110 1111 1112
#-------------------------------------#
#check resolution line input args

1113
RESOLUTION_BY_LINE=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--resolution_line" $RESOLUTION_BY_LINE`
1114

1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
RESOLUTION_BY_LINE_IS_NUMBER=`function_check_number "$RESOLUTION_BY_LINE"`

if [ $RESOLUTION_BY_LINE_IS_NUMBER != 'TRUE' ]; then

  function_message "TYPE_NOT_NUMBER" "RESOLUTION_BY_LINE must be an integer" "--resolution_line"
  exit 0


fi

1125 1126 1127
#-------------------------------------#
#check resolution col input args

1128
RESOLUTION_BY_COL=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--resolution_col" $RESOLUTION_BY_COL`
1129

1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
RESOLUTION_BY_COL_IS_NUMBER=`function_check_number "$RESOLUTION_BY_COL"`

if [ $RESOLUTION_BY_COL_IS_NUMBER != 'TRUE' ]; then

  function_message "TYPE_NOT_NUMBER" "RESOLUTION_BY_COL must be an integer" "--resolution_col"
  exit 0


fi

1140 1141 1142
#-------------------------------------#
#check number of tile by line input args

1143
NB_TILE_BY_LINE=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--nb_tile_line" $NB_TILE_BY_LINE`
1144

1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
NB_TILE_BY_LINE_IS_NUMBER=`function_check_number "$NB_TILE_BY_LINE"`

if [ $NB_TILE_BY_LINE_IS_NUMBER != 'TRUE' ]; then

  function_message "TYPE_NOT_NUMBER" "NB_TILE_BY_LINE must be an integer" "--nb_tile_line"
  exit 0


fi

1155 1156 1157
#-------------------------------------#
#check number of tile by col input args

1158
NB_TILE_BY_COL=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--nb_tile_col" $NB_TILE_BY_COL`
1159

1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
NB_TILE_BY_COL_IS_NUMBER=`function_check_number "$NB_TILE_BY_COL"`

if [ $NB_TILE_BY_COL_IS_NUMBER != 'TRUE' ]; then

  function_message "TYPE_NOT_NUMBER" "NB_TILE_BY_COL must be an integer" "--nb_tile_col"
  exit 0


fi

1170 1171
#---------------------#
# --no_select management
1172

1173 1174 1175 1176 1177
if [ "${sort_arg_keys[0]}" == "--no_select" ]; then
  sort_arg_keys[0]=""
  sort_arg_values[0]=""
  sort_arg_weight[0]=0
fi
1178

1179 1180
#---------------------#

1181 1182 1183
#=============================================================#
#=============================================================#
#=============================================================#
1184

1185 1186
case ${sort_arg_keys[0]} in
    ""|"--select")
1187 1188 1189 1190 1191
      ####################################################
      #      use: ./photos_montage_aladin.sh             #
      #                      or                          #
      # use: ./photos_montage_aladin.sh --select version #
      ####################################################
1192

PENGUEN Julien's avatar
PENGUEN Julien committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
      version_init=$(cat .env | grep ALADIN_VERSION)

      if [ ${version_init} == "ALADIN_VERSION=?" ]; then

        init='TRUE'

        echo "INITIALISATION VERSION"

        #------------------------------------------#
        #call function function_jar_updated_search

        aladin_last_number_version=`function_jar_updated_search`
        #----------------------------------------#
1206
        sed -i "s/ALADIN_VERSION=?/ALADIN_VERSION=${aladin_last_number_version}/" .env
PENGUEN Julien's avatar
PENGUEN Julien committed
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219

      else

        init='FALSE'

      fi
      # ---------------------------------------- #

      if [ ${init} == TRUE ]; then

        version=${aladin_last_number_version}

      else
1220
        if [ "${sort_arg_keys[0]}" == "--select" ]; then
PENGUEN Julien's avatar
PENGUEN Julien committed
1221 1222 1223 1224 1225 1226

          # --------------- #
          curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3 | sed 's/v//' > .temp
          curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/<!--/d'| sed '/last/!d' | cut -d">" -f3 | cut -d"<" -f1 | sed 's/\.jar//' | sed 's/Aladin//' >> .temp
          list_jar=$(sort -r .temp | awk '{print $1}')
          rm .temp
1227
          present=$(echo $list_jar| grep "${sort_arg_values[0]}")
PENGUEN Julien's avatar
PENGUEN Julien committed
1228 1229 1230

          if [ $? -eq 1 ]; then

1231 1232
          function_message "TYPE_EXIST_VERSION"
          exit 0
PENGUEN Julien's avatar
PENGUEN Julien committed
1233 1234 1235

          else

1236
            version=${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248

          fi
          # --------------- #

        else

          version=${ALADIN_VERSION}

        fi

      fi

1249 1250 1251 1252 1253
      echo -e "${BOLD_BEGIN}"
      echo -e "------------------------------------"
      echo -e "        Photos Montage Aladin       "
      echo -e ""
      echo -e "- aladin version: ${version}${BOLD_END}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1254 1255

      #----------------------------------------#
1256 1257 1258 1259 1260 1261 1262 1263 1264
      #check result_check_permission

      if [ $result_check_permission != 'TRUE' ]; then

        function_message "TYPE_MOUNT_ERROR" "you do not have permission to write and / or read" $VOLUME_MOUNT
        exit 0

      else

1265 1266
        if [ $VOLUME_MOUNT == "NONE" ]; then
          volume_used="/home/$USER"
1267
        else
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
          volume_used=$VOLUME_MOUNT
        fi

        info_volume_total=$(df -h ${volume_used} | tail -n 1 | awk -F " " '{print $2}')
        info_volume_free=$(df -h ${volume_used} | tail -n 1 | awk -F " " '{print $4}')
        info_percentage=$(df -h ${volume_used} | tail -n 1 | awk -F " " '{print $5}')
        info_percentage_number=$(df -h ${volume_used} | tail -n 1 | awk -F " " '{print $5}'| sed 's/%//')

        if [ $(( $info_percentage_number )) -lt ${WARNING_LEVEL_DISK_SPACE_PERCENTAGE} ]; then
          function_message "TYPE_MOUNT_INFOS" "Disk Space: $info_volume_total, Disk Space Free: $info_volume_free, Space disk pourcentage used: $info_percentage" $volume_used $GREEN "INFOS"

        elif [[ $(( $info_percentage_number )) -gt ${WARNING_LEVEL_DISK_SPACE_PERCENTAGE} && $(( $info_percentage_number )) -lt ${CRITICAL_LEVEL_DISK_SPACE_PERCENTAGE} ]]; then
          function_message "TYPE_MOUNT_INFOS" "Disk Space: $info_volume_total, Disk Space Free: $info_volume_free, Space disk pourcentage used: $info_percentage" $volume_used $YELLOW "WARNING"
1281
          sleep 5
1282 1283 1284
        else
          function_message "TYPE_MOUNT_INFOS" "Disk Space: $info_volume_total, Disk Space Free: $info_volume_free, Space disk pourcentage used: $info_percentage" $volume_used $RED "WARNING CRITICAL"
          exit 0
1285 1286 1287 1288 1289
        fi

      fi

      #----------------------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
1290 1291 1292 1293 1294 1295 1296 1297
      #call function function_jar_updated_search

      aladin_last_number_version=`function_jar_updated_search`

      #----------------------------------------#

      if [ ${aladin_last_number_version} != ${version} ]; then

1298
        function_message "TYPE_UPDATE" "${aladin_last_number_version}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1299 1300 1301 1302 1303
        sleep 5

      else
        #case no update

1304 1305 1306
        echo -e "${BOLD_BEGIN}"
        echo -e "------------------------------------"
        echo -e "${BOLD_END}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319

      fi

      #----------------------------------------#
      #call function function_build_image

      if [ ${version} == ${ALADIN_VERSION} ]; then
        function_build_image ${ALADIN_VERSION}
      else
        function_build_image $version
      fi

      #------------------------#
1320
      #creation of main_folder
PENGUEN Julien's avatar
PENGUEN Julien committed
1321

1322
      main_folder=${OUTPUT_FOLDER_LINUX}"/datas_photos_montage_aladin"
1323

PENGUEN Julien's avatar
PENGUEN Julien committed
1324
      if [ -d ${main_folder} ]; then
1325 1326
        echo "=> ${main_folder} exist"
        echo " "
PENGUEN Julien's avatar
PENGUEN Julien committed
1327 1328
      else
        mkdir ${main_folder}
1329 1330
        echo "=> creation of " ${main_folder}
        echo " "
1331

PENGUEN Julien's avatar
PENGUEN Julien committed
1332
      fi
1333

1334
      #------------------------#
1335 1336
      #------------------------#

1337
      indice=0
1338

1339
      while read enreg
1340
      do
1341 1342
        if [ $enreg != "id,name,la,ld,ra,dec" ]; then
          list_zone[$indice]=`echo $enreg | awk -F"," '{print $2}'`
1343
          list_zone[$indice]=${list_zone[$indice]}"_ANG"${ANGULAR}
1344 1345 1346 1347
          list_ra[$indice]=`echo $enreg | awk -F"," '{print $5}'`
          list_dec[$indice]=`echo $enreg | awk -F"," '{print $6}'`
          ((indice++));
        fi
1348
      done < ${INPUT_FILE_AREAS}
1349

1350
      #------------------------#
1351 1352 1353 1354 1355 1356 1357 1358
      nb_lines_survey=`wc -l $INPUT_FILE_SURVEYS | awk '{print $1}'`

      tempo_tile=`expr $NB_TILE_BY_LINE \* $NB_TILE_BY_COL `
      tempo2_tile=`expr ${nb_lines_survey}/${tempo_tile}`
      nb_tile=$((${tempo2_tile%.*}+1))



1359 1360
      #------------------------#
      #loop on areas
1361

1362 1363
      for k in ${!list_zone[*]}
      do
1364 1365

      echo "============================="
1366
      echo -e "${BOLD_BEGIN}${list_zone[$k]}${BOLD_END}"
1367 1368 1369
      echo "============================="

      #------------------------#
1370
        if [ "${sort_arg_keys[1]}" == "--force-all" ]; then
1371
          force='TRUE'
1372
          force_all='TRUE'
1373 1374
          force_warning='FALSE'
        elif [[ "${sort_arg_keys[1]}" == "--force" && "${sort_arg_values[1]}" == ${list_zone[$k]} ]]; then
1375
          force='TRUE'
1376
          force_all='FALSE'
1377 1378 1379 1380 1381
          force_warning='FALSE'
        elif [[ "${sort_arg_keys[1]}" == "--force" && "${sort_arg_values[1]}" != ${list_zone[$k]} ]]; then
          force='FALSE'
          force_all='FALSE'
          force_warning='TRUE'
1382 1383 1384 1385
        else
          force='FALSE'
        fi

1386 1387 1388 1389 1390 1391 1392 1393 1394
        #------------------------#
        #check OUTPUT_FOLDER_ON_VOLUME_MOUNT

        if [ $OUTPUT_FOLDER_ON_VOLUME_MOUNT == "TRUE" ]; then
          container_mount="/mnt/"
        else
          container_mount=""
        fi

1395
        #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
1396
        area_folder[$k]=${main_folder}"/"${list_zone[$k]}
1397 1398
        tempo_folder[$k]=${area_folder[$k]}
        images_folder[$k]=${area_folder[$k]}"/images"
1399
        montages_folder[$k]=${area_folder[$k]}"/montages"
1400
        area_ajs[$k]=${tempo_folder[$k]}"/area_"${list_zone[$k]}".ajs"
1401 1402
        log_aladin_file[$k]=${area_folder[$k]}"/"${list_zone[$k]}".log"
        infos_file[$k]=${area_folder[$k]}"/infos_"${list_zone[$k]}".txt"
PENGUEN Julien's avatar
PENGUEN Julien committed
1403

1404
        #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
1405
        if [ -d ${area_folder[$k]} ]; then
1406 1407
          if [ $force == 'TRUE' ]; then
            rm -rf ${area_folder[$k]} #case --force
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418

            if [ $force_all == 'TRUE' ]; then
              echo ""
              echo "* USE OF --force-all"
              echo ""
            else
              echo ""
              echo "* USE OF --force ${list_zone[$k]}"
              echo ""
            fi

1419 1420 1421 1422 1423 1424
            echo "=> remove of " ${area_folder[$k]}
            mkdir ${area_folder[$k]}
            echo "=> creation of " ${area_folder[$k]}
          else
            echo "=> ${area_folder[$k]} exist"
          fi
PENGUEN Julien's avatar
PENGUEN Julien committed
1425 1426
        else
          mkdir ${area_folder[$k]}
1427
          echo "=> creation of " ${area_folder[$k]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1428
        fi
1429 1430
        #-----------------------------#
        #call function_create_ajs_file
1431

1432 1433
        if [ -f ${area_ajs[$k]} ]; then
          echo "=> ${area_ajs[$k]} exist"
1434
        else
1435
          echo -e "=> ${RED}WARNING${COLOR_OFF} : ${area_ajs[$k]} not found"
1436
          echo "=> construction of ${area_ajs[$k]} in progress ..."
1437 1438 1439

          function_create_ajs_file ${INPUT_FILE_SURVEYS} ${area_ajs[$k]} ${list_zone[$k]} ${list_ra[k]} ${list_dec[k]} ${container_mount}${images_folder[$k]}

1440
          echo "=> construction of ${area_ajs[$k]} OK"
1441

1442 1443
          rm -rf ${images_folder[$k]}
          rm -rf ${montages_folder[$k]}
1444 1445 1446 1447 1448 1449 1450 1451

          if [ -f ${infos_file[$k]} ]; then
            rm ${infos_file[$k]}
          fi

          if [ -f ${log_aladin_file[$k]} ]; then
            rm ${infos_file[$k]}
          fi
1452

1453 1454
        fi

1455
        #---------------------------#
1456
        #tests on images and montages
1457 1458 1459
        #folders

        #--------#
1460
        if [ -d ${images_folder[$k]} ]; then
1461
          echo "=> ${images_folder[$k]} exist"
1462 1463
        else
          mkdir ${images_folder[$k]}
1464 1465 1466
          echo "=> creation of " ${images_folder[$k]}
        fi
        #--------#
1467 1468
        if [ -d ${montages_folder[$k]} ]; then
          echo "=> ${montages_folder[$k]} exist"
1469
        else
1470 1471
          mkdir ${montages_folder[$k]}
          echo "=> creation of " ${montages_folder[$k]}
1472
        fi
1473
        #--------#
1474

1475
        test_images_folder=$([ "$(ls -A ${images_folder[$k]})" ] && echo "Non vide" || echo "Vide")
1476
        test_montages_folder=$([ "$(ls -A ${montages_folder[$k]})" ] && echo "Non vide" || echo "Vide")
1477

1478
        if [[ ${test_images_folder} == "Non vide" && ${test_montages_folder} == "Non vide" ]]; then
1479
          nb_images[$k]=$(find ${images_folder[$k]} -type f | wc -l)
1480
          nb_montages[$k]=$(find ${montages_folder[$k]} -type f | wc -l)
1481

1482
          if [[ ${nb_images[$k]} == $nb_lines_survey && ${nb_montages[$k]} == $nb_tile ]]; then
1483 1484 1485 1486 1487
            state="FINISH"
            echo "=> All image(s) and montage(s) present(s) for " ${list_zone[$k]}

          else
            rm -rf ${images_folder[$k]}
1488
            rm -rf ${montages_folder[$k]}
1489 1490

            mkdir ${images_folder[$k]}
1491
            mkdir ${montages_folder[$k]}
1492 1493 1494 1495 1496 1497

            rm ${area_ajs[$k]}
            rm ${infos_file[$k]}
            rm ${log_aladin_file[$k]}

            echo "=> construction of ${area_ajs[$k]} in progress ..."
1498
            function_create_ajs_file ${INPUT_FILE_SURVEYS} ${area_ajs[$k]} ${list_zone[$k]} ${list_ra[k]} ${list_dec[k]} ${container_mount}${images_folder[$k]}
1499 1500 1501
            echo "=> construction of ${area_ajs[$k]} OK"


1502
            state="RUN"
1503 1504

            if [ $force == 'FALSE' ]; then
1505
              echo -e "=> ${RED}WARNING${COLOR_OFF} : Missing one or more images or montages"
1506
            fi
1507
          fi
1508 1509

        else
1510
          rm -rf ${images_folder[$k]}
1511
          rm -rf ${montages_folder[$k]}
1512 1513

          mkdir ${images_folder[$k]}
1514
          mkdir ${montages_folder[$k]}
1515

1516
          state="RUN"
1517 1518
        fi

1519 1520
        #------------------------#

1521
        if [ $state == "RUN" ]; then
1522

1523 1524
          #----------------------------------------#
          #construction of docker script and montage