photos_montage_aladin.sh 48.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 19 20 21 22

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

    echo ""
    echo "------------------------------------"
    echo ""
23
    echo -e "${RED}========================================================="
24
    echo -e "WARNING => ${message}"
25
    echo -e "=========================================================${COLOR_OFF}"
26

27 28 29 30 31
  elif [ "$type_message" == "TYPE_FILE_ERROR" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
32
    echo -e "${RED}========================================================="
33 34 35
    echo -e "          ERROR with option '${option}' "
    echo -e ""
    echo -e "${message}"
36
    echo -e "=========================================================${COLOR_OFF}"
37 38 39
    echo ""
    echo "------------------------------------"

40 41 42 43 44
  elif [ "$type_message" == "TYPE_NOT_NUMBER" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
45
    echo -e "${RED}========================================================="
46 47 48
    echo -e "          ERROR with option '${option}' "
    echo -e ""
    echo -e "${message}"
49
    echo -e "=========================================================${COLOR_OFF}"
50 51 52
    echo ""
    echo "------------------------------------"

53 54 55 56 57
  elif [ "$type_message" == "TYPE_HELP" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
58
    echo -e "${GREEN}========"
59
    echo -e "= HELP ="
60
    echo -e "========${COLOR_OFF}"
61 62 63

  elif [ "$type_message" == "TYPE_UNKNOWN" ]; then
    echo ""
64
    echo -e "${RED}==============================="
65
    echo -e " error: unrecognized arguments "
66
    echo -e "===============================${COLOR_OFF}"
67 68 69 70

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

    echo ''
71
    echo -e "${RED}===================================="
72
    echo -e "             WARNING"
73
    echo -e "====================================${COLOR_OFF}"
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    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 ''
92
    echo -e "${RED}===================================="
93
    echo -e "             WARNING"
94
    echo -e "====================================${COLOR_OFF}"
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    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 ''
110
    echo -e "${RED}===================================="
111
    echo -e "             WARNING"
112
    echo -e "====================================${COLOR_OFF}"
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    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 ""
    echo "use : ./photos_montage_aladin.sh [options] [others]"
    echo ""
    echo ""
    echo "OPTIONS:"
    echo ""
    echo "-i, --infos                        give informations about versions available on aladin server"
    echo "                                   and about photos_montage_aladin image present on localhost"
161 162
    echo "-b version, --build VERSION        build photos_montage_aladin image with selected version"
    echo "--select VERSION                   run photos_montage_aladin with selected version number"
163
    echo "--force-all                        re-run all areas in input csv"
164
    echo "--force AREA                       re-run for the area, the area must be in input csv"
165
    echo "-u, --update                       update photos_montage_aladin image version"
166
    echo "-rm version, --remove VERSION      remove photos_montage_aladin image with selected version"
167 168 169 170
    echo "-h, --help                         show this help message and exit"
    echo "-v, --version                      give photos_montage_aladin.sh current version number"
    echo ""
    echo ""
171
    echo "OTHERS: (available only with no option OR with --select option)"
172
    echo ""
173
    echo "--survey FILE                      run photos_montage_aladin with this surveys file instead of "
174
    echo "the default file define on .env file. the survey file must be on format '.dat'"
175
    echo "--area FILE                        run photos_montage_aladin with this areas file instead of "
176 177
    echo "the default file define on .env file. the area file must be on format '.csv'"
    echo ""
178
    echo "--angular NUMBER                   run photos_montage_aladin with this angular dimension value instead of "
179
    echo "the default angular value define on .env file. the angular value must be on second of arc"
180 181 182 183 184
    echo "--resolution_col NUMBER            run photos_montage_aladin with this number of pixel by columns for the Image Magick montages"
    echo "--resolution_line NUMBER           run photos_montage_aladin with this number of pixel by lines for the Image Magick montages"
    echo "--nb_tile_col NUMBER               run photos_montage_aladin with this number of tiles by columns for the Image Magick montages"
    echo "--nb_tile_line NUMBER              run photos_montage_aladin with this number of tiles by lines for the Image Magick montages"
    echo "--mount PATH                       run photos_montage_aladin with a volume mounted on docker container repository /mnt"
185 186 187 188 189 190
    echo ""
  fi

}


191
function_build_tab_hach()
PENGUEN Julien's avatar
PENGUEN Julien committed
192
{
193 194 195 196 197 198 199
  # 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
200
  # - message: in case of error, error message
201 202 203 204 205 206 207 208 209 210

  # ---------------------- #
  # 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
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

  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";
231
  ARRAY["--angular"]="NUMBER";
232 233
  ARRAY["--resolution_line"]="NUMBER";
  ARRAY["--resolution_col"]="NUMBER";
234 235
  ARRAY["--nb_tile_line"]="NUMBER";
  ARRAY["--nb_tile_col"]="NUMBER";
236
  ARRAY["--mount"]="PATH VOLUME";
237

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
  # ---------------------- #
  # 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;
267
  ARGS_WEIGHT["--angular"]=2;
268 269
  ARGS_WEIGHT["--resolution_line"]=2;
  ARGS_WEIGHT["--resolution_col"]=2;
270 271
  ARGS_WEIGHT["--nb_tile_line"]=2;
  ARGS_WEIGHT["--nb_tile_col"]=2;
272
  ARGS_WEIGHT["--mount"]=2;
273

274 275 276 277 278 279
  # -------- #

  indice=0;

  for params in "$@"
  do
280 281
    tab_params[$indice]=$params
    ((indice++));
282 283 284 285
  done

  # -------- #
  val_error="FALSE"
286
  elements_ok=0
287 288 289 290 291 292 293 294 295 296

  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

297
        elements_ok=$(($elements_ok + 1))
298 299
        tab_keys[$indice]=$elem
        tab_values[$indice]="None"
300
        tab_weight[$indice]=${ARGS_WEIGHT[${elem}]}
301 302 303 304 305 306

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

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

307 308
          if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" && ${tab_params[$indice +1]} != -* ]]; then
            #case argument needed for the option is present on input argument
309
            tab_values[$indice]=${tab_params[$indice +1]}
310
            elements_ok=$(($elements_ok + 1))
311
          else
312
            #case argument needed for the option is missing on input argument
313
            message="Missing argument for the option "${elem}
314 315 316 317 318 319 320 321 322 323 324 325 326
            val_error="TRUE"
          fi

        fi

      fi

      ((indice++));

    done

  done

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

329 330 331 332 333 334 335 336 337 338
    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"
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394

}

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
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
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

}

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
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

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 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 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
}

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',
530
        #'--nb_tile_line','--nb_tile_col' '--mount'
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 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

        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',
605
      #'--nb_tile_line','--nb_tile_col', '--mount'
606 607 608 609 610 611 612 613 614 615 616 617 618 619

        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
620

621 622 623 624
    ;;
esac

  echo "${arg_keys[@]},${arg_values[@]},${arg_weight[@]}"
625 626 627 628


}

629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
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"

}
646

PENGUEN Julien's avatar
PENGUEN Julien committed
647 648 649 650 651 652
function_jar_updated_search()
{
  # function_jar_updated_search: get the last jar version
  # returns:
  #    return number_version

653
  version=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3)
PENGUEN Julien's avatar
PENGUEN Julien committed
654 655 656 657 658
  number_version=$(echo ${version:1})
  echo "$number_version"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
659 660 661 662 663 664 665
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 ..."
666

667 668
  old_id=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-$1)
  sudo docker rmi ${old_id} #remove old photos_montage_aladin image
669

PENGUEN Julien's avatar
PENGUEN Julien committed
670 671 672 673
  echo "=> Deleting the image_photos_montage_aladin-$1 docker image successfully"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
674 675 676 677 678 679
function_build_image()
{
  # function_build_image: build the photos_montage_aladin image

      version=$1

PENGUEN Julien's avatar
PENGUEN Julien committed
680
      #----------------------------------------#
681 682 683 684
      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
685

686
      present=$(echo $list_jar| grep "${version}")
PENGUEN Julien's avatar
PENGUEN Julien committed
687 688 689

      if [ $? -eq 1 ]; then

690
        function_message "TYPE_EXIST_VERSION"
PENGUEN Julien's avatar
PENGUEN Julien committed
691 692 693 694 695 696 697
        exit 0


      else

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

699
        id_image=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-${version})
PENGUEN Julien's avatar
PENGUEN Julien committed
700 701 702

        if [ ${id_image} ]; then

PENGUEN Julien's avatar
PENGUEN Julien committed
703
          echo "=> The image_photos_montage_aladin-${version} docker image already exist"
PENGUEN Julien's avatar
PENGUEN Julien committed
704 705 706
          echo ''

        else
PENGUEN Julien's avatar
PENGUEN Julien committed
707 708

          #----------------------------------------#
709
          tempo=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3)
710

PENGUEN Julien's avatar
PENGUEN Julien committed
711
          aladin_last_number_version=$(echo ${tempo:1})
712 713
          echo "${aladin_last_number_version}"
          echo "${version}"
PENGUEN Julien's avatar
PENGUEN Julien committed
714
          #----------------------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
715

PENGUEN Julien's avatar
PENGUEN Julien committed
716
          if [ ${aladin_last_number_version} == ${version} ]; then
717
            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin.jar --no-check-certificate
718
            mv conf-montage/Aladin.jar conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
719
          else
720 721

            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin${version}.jar --no-check-certificate
PENGUEN Julien's avatar
PENGUEN Julien committed
722
            mv conf-montage/Aladin${version}.jar conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
723 724 725 726 727 728 729

          fi

          #-----------------#
          #build
          echo "- Creating the photos_montage_aladin-${version} docker image in progress ..."
          echo '------------------------------------------------------------------'
730 731 732

          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
733 734 735 736 737
          echo "=> creating the photos_montage_aladin-${version} docker image successfully"
          echo '------------------------------------------------------------------'
          echo ''
          #-----------------#

738
          rm conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
          rm .logfile

        fi
      fi

}



function_create_ajs_file()
{
  # function_create_ajs_file : create ajs surveys file

inputfile=$1
outputfile=$2
754 755
area=$3
ra_area=$4
PENGUEN Julien's avatar
PENGUEN Julien committed
756 757
dec_area=$5
outputfolder=$6
PENGUEN Julien's avatar
PENGUEN Julien committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772


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}
773
    echo -e "get HiPS("$survey")" ${ra_area} ${dec_area} ${ANGULAR}"'" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
774 775 776 777
    echo -e "cm BB localcut" >> ${outputfile}


    for val in `echo $survey | tr "/" " "`;
778
    do
PENGUEN Julien's avatar
PENGUEN Julien committed
779 780 781 782
     ((i++));
     tab[$i]=${val}
    done

783 784 785 786 787 788
    if [ $number -lt '10' ]; then
      chaine="0${number}_${area}-${tab[$i-1]}_${tab[$i]}.jpg"
    else
      chaine="${number}_${area}-${tab[$i-1]}_${tab[$i]}.jpg"
    fi
    echo -e "save 200x200 ${outputfolder}/$chaine" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
789 790 791 792 793 794 795 796 797 798 799


done



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

800 801
#---------------------#
# management arguments
802
# call function_sort_tab
803 804 805 806 807

RESULTAT=`function_build_tab_hach $@`

tab_arg_keys=`echo $RESULTAT | cut --delimiter=, -f 1`
tab_arg_values=`echo $RESULTAT | cut --delimiter=, -f 2`
808 809
tab_arg_weight=`echo $RESULTAT | cut --delimiter=, -f 3`
val_error=`echo $RESULTAT | cut --delimiter=, -f 4`
810

811
#------------------------------------#
812
#check if val_error is TRUE
813 814

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

817
  function_message "TYPE_VAL_ERROR" "${error_message}"
818 819 820
  exit 0
fi

821 822 823
#----------------------------------------------------#
# check to manage '--select' and '--no_select options
# call function_check_select_option
824

825
RESULT_CHECK_SELECT=`function_check_select_option "${tab_arg_keys[*]}" "${tab_arg_values[*]}" "${tab_arg_weight[*]}"`
826

827 828 829
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`
830

831 832 833
arg_keys=( ${array_arg_keys// / } )
arg_values=( ${array_arg_values// / } )
arg_weight=( ${array_arg_weight// / } )
834

835
#--------------------------#
836 837 838 839 840 841 842 843 844 845 846 847 848
# 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// / } )

849 850 851 852 853
#------------------------------#
#check volume_mount input args

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

854
if [ $VOLUME_MOUNT != "NONE" ];then
855
  if [[ ! -d $VOLUME_MOUNT ]]; then
856 857 858
    function_message "TYPE_FILE_ERROR" "$VOLUME_MOUNT not found" "--mount"
      exit 0
  fi
859 860
fi

861
#------------------------------#
862
#check survey input args
863

864
INPUT_FILE_SURVEYS=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--survey" $INPUT_FILE_SURVEYS`
865

866
if [ ! -f $INPUT_FILE_SURVEYS ]; then
867 868 869 870
  function_message "TYPE_FILE_ERROR" "$INPUT_FILE_SURVEYS not found" "--survey"
    exit 0
fi

871 872 873 874
#------------------------------#
#check area input args

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

876
if [ ! -f $INPUT_FILE_AREAS ]; then
877 878 879 880
  function_message "TYPE_FILE_ERROR" "$INPUT_FILE_AREAS not found" "--area"
    exit 0
fi

881 882 883
#-------------------------------------#
#check angular input arg

884
ANGULAR=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--angular" $ANGULAR`
885

886 887 888 889 890 891 892 893 894
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

895 896 897
#-------------------------------------#
#check resolution line input args

898
RESOLUTION_BY_LINE=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--resolution_line" $RESOLUTION_BY_LINE`
899

900 901 902 903 904 905 906 907 908 909
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

910 911 912
#-------------------------------------#
#check resolution col input args

913
RESOLUTION_BY_COL=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--resolution_col" $RESOLUTION_BY_COL`
914

915 916 917 918 919 920 921 922 923 924
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

925 926 927
#-------------------------------------#
#check number of tile by line input args

928
NB_TILE_BY_LINE=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--nb_tile_line" $NB_TILE_BY_LINE`
929

930 931 932 933 934 935 936 937 938 939
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

940 941 942
#-------------------------------------#
#check number of tile by col input args

943
NB_TILE_BY_COL=`function_check_and_replace "${sort_arg_keys[*]}" "${sort_arg_values[*]}" "--nb_tile_col" $NB_TILE_BY_COL`
944

945 946 947 948 949 950 951 952 953 954
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

955 956
#---------------------#
# --no_select management
957

958 959 960 961 962
if [ "${sort_arg_keys[0]}" == "--no_select" ]; then
  sort_arg_keys[0]=""
  sort_arg_values[0]=""
  sort_arg_weight[0]=0
fi
963

964 965
#---------------------#

966 967 968
#=============================================================#
#=============================================================#
#=============================================================#
969

970 971
case ${sort_arg_keys[0]} in
    ""|"--select")
972 973 974 975 976
      ####################################################
      #      use: ./photos_montage_aladin.sh             #
      #                      or                          #
      # use: ./photos_montage_aladin.sh --select version #
      ####################################################
977

PENGUEN Julien's avatar
PENGUEN Julien committed
978 979 980 981 982 983 984 985 986 987 988 989 990
      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`
        #----------------------------------------#
991
        sed -i "s/ALADIN_VERSION=?/ALADIN_VERSION=${aladin_last_number_version}/" .env
PENGUEN Julien's avatar
PENGUEN Julien committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004

      else

        init='FALSE'

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

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

        version=${aladin_last_number_version}

      else
1005
        if [ "${sort_arg_keys[0]}" == "--select" ]; then
PENGUEN Julien's avatar
PENGUEN Julien committed
1006 1007 1008 1009 1010 1011

          # --------------- #
          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
1012
          present=$(echo $list_jar| grep "${sort_arg_values[0]}")
PENGUEN Julien's avatar
PENGUEN Julien committed
1013 1014 1015

          if [ $? -eq 1 ]; then

1016 1017
          function_message "TYPE_EXIST_VERSION"
          exit 0
PENGUEN Julien's avatar
PENGUEN Julien committed
1018 1019 1020

          else

1021
            version=${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048

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

        else

          version=${ALADIN_VERSION}

        fi

      fi

      echo ''
      echo '------------------------------------'
      echo '        Photos Montage Aladin       '
      echo ''
      echo '- aladin version: ' ${version}

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

      aladin_last_number_version=`function_jar_updated_search`

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

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

1049
        function_message "TYPE_UPDATE" "${aladin_last_number_version}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
        sleep 5

      else
        #case no update

        echo ''
        echo '------------------------------------'
        echo ''

      fi

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

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

      #------------------------#
1071
      #creation of main_folder
PENGUEN Julien's avatar
PENGUEN Julien committed
1072

1073
      main_folder=$HOME"/.photos_montage_aladin"
1074

PENGUEN Julien's avatar
PENGUEN Julien committed
1075
      if [ -d ${main_folder} ]; then
1076 1077
        echo "=> ${main_folder} exist"
        echo " "
PENGUEN Julien's avatar
PENGUEN Julien committed
1078 1079
      else
        mkdir ${main_folder}
1080 1081
        echo "=> creation of " ${main_folder}
        echo " "
1082

PENGUEN Julien's avatar
PENGUEN Julien committed
1083
      fi
1084

1085
      #------------------------#
1086 1087
      #------------------------#

1088
      indice=0
1089

1090
      while read enreg
1091
      do
1092 1093 1094 1095 1096 1097
        if [ $enreg != "id,name,la,ld,ra,dec" ]; then
          list_zone[$indice]=`echo $enreg | awk -F"," '{print $2}'`
          list_ra[$indice]=`echo $enreg | awk -F"," '{print $5}'`
          list_dec[$indice]=`echo $enreg | awk -F"," '{print $6}'`
          ((indice++));
        fi
1098
      done < ${INPUT_FILE_AREAS}
1099

1100
      #------------------------#
1101 1102 1103 1104 1105 1106 1107 1108
      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))



1109 1110
      #------------------------#
      #loop on areas
1111

1112 1113
      for k in ${!list_zone[*]}
      do
1114 1115 1116 1117 1118 1119

      echo "============================="
      echo "${list_zone[$k]}"
      echo "============================="

      #------------------------#
1120
        if [ "${sort_arg_keys[1]}" == "--force-all" ]; then
1121
          force='TRUE'
1122
          force_all='TRUE'
1123 1124
          force_warning='FALSE'
        elif [[ "${sort_arg_keys[1]}" == "--force" && "${sort_arg_values[1]}" == ${list_zone[$k]} ]]; then
1125
          force='TRUE'
1126
          force_all='FALSE'
1127 1128 1129 1130 1131
          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'
1132 1133 1134 1135 1136
        else
          force='FALSE'
        fi

        #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
1137
        area_folder[$k]=${main_folder}"/"${list_zone[$k]}
1138 1139
        tempo_folder[$k]=${area_folder[$k]}
        images_folder[$k]=${area_folder[$k]}"/images"
1140
        montages_folder[$k]=${area_folder[$k]}"/montages"
1141
        area_ajs[$k]=${tempo_folder[$k]}"/area_"${list_zone[$k]}".ajs"
1142 1143
        log_aladin_file[$k]=${area_folder[$k]}"/"${list_zone[$k]}".log"
        infos_file[$k]=${area_folder[$k]}"/infos_"${list_zone[$k]}".txt"
1144

1145
        #------------------------#
1146
        if [ -d ${area_folder[$k]} ]; then
1147 1148
          if [ $force == 'TRUE' ]; then
            rm -rf ${area_folder[$k]} #case --force
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

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

1160 1161 1162 1163 1164 1165
            echo "=> remove of " ${area_folder[$k]}
            mkdir ${area_folder[$k]}
            echo "=> creation of " ${area_folder[$k]}
          else
            echo "=> ${area_folder[$k]} exist"
          fi
1166 1167
        else
          mkdir ${area_folder[$k]}
1168
          echo "=> creation of " ${area_folder[$k]}
1169
        fi
1170 1171
        #-----------------------------#
        #call function_create_ajs_file
1172

1173 1174
        if [ -f ${area_ajs[$k]} ]; then
          echo "=> ${area_ajs[$k]} exist"
1175
        else
1176
          echo -e "=> ${RED}WARNING${COLOR_OFF} : ${area_ajs[$k]} not found"
1177
          echo "=> construction of ${area_ajs[$k]} in progress ..."
1178
          function_create_ajs_file ${INPUT_FILE_SURVEYS} ${area_ajs[$k]} ${list_zone[$k]} ${list_ra[k]} ${list_dec[k]} ${images_folder[$k]}
1179 1180 1181
          echo "=> construction of ${area_ajs[$k]} OK"
          rm -rf ${images_folder[$k]}
          rm -rf ${montages_folder[$k]}
1182 1183 1184
          rm ${infos_file[$k]}
          rm ${log_aladin_file[$k]}

1185 1186
        fi

1187
        #---------------------------#
1188
        #tests on images and montages
1189 1190 1191
        #folders

        #--------#
1192
        if [ -d ${images_folder[$k]} ]; then
1193
          echo "=> ${images_folder[$k]} exist"
1194 1195
        else
          mkdir ${images_folder[$k]}
1196 1197 1198
          echo "=> creation of " ${images_folder[$k]}
        fi
        #--------#
1199 1200
        if [ -d ${montages_folder[$k]} ]; then
          echo "=> ${montages_folder[$k]} exist"
1201
        else
1202 1203
          mkdir ${montages_folder[$k]}
          echo "=> creation of " ${montages_folder[$k]}
1204
        fi
1205
        #--------#
1206

1207
        test_images_folder=$([ "$(ls -A ${images_folder[$k]})" ] && echo "Non vide" || echo "Vide")
1208
        test_montages_folder=$([ "$(ls -A ${montages_folder[$k]})" ] && echo "Non vide" || echo "Vide")
1209

1210
        if [[ ${test_images_folder} == "Non vide" && ${test_montages_folder} == "Non vide" ]]; then
1211
          nb_images[$k]=$(find ${images_folder[$k]} -type f | wc -l)
1212
          nb_montages[$k]=$(find ${montages_folder[$k]} -type f | wc -l)
1213

1214
          if [[ ${nb_images[$k]} == $nb_lines_survey && ${nb_montages[$k]} == $nb_tile ]]; then
1215 1216 1217 1218 1219
            state="FINISH"
            echo "=> All image(s) and montage(s) present(s) for " ${list_zone[$k]}

          else
            rm -rf ${images_folder[$k]}
1220
            rm -rf ${montages_folder[$k]}
1221 1222

            mkdir ${images_folder[$k]}
1223
            mkdir ${montages_folder[$k]}
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233

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

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


1234
            state="RUN"
1235 1236

            if [ $force == 'FALSE' ]; then
1237
              echo -e "=> ${RED}WARNING${COLOR_OFF} : Missing one or more images or montages"
1238
            fi
1239
          fi
1240 1241

        else
1242
          rm -rf ${images_folder[$k]}
1243
          rm -rf ${montages_folder[$k]}
1244 1245

          mkdir ${images_folder[$k]}
1246
          mkdir ${montages_folder[$k]}
1247

1248
          state="RUN"
1249 1250
        fi

1251 1252
        #------------------------#

1253
        if [ $state == "RUN" ]; then
1254

1255 1256
          #----------------------------------------#
          #construction of docker script and montage
1257
          echo "=> Construction in progress ..."
1258

1259
          script_images[$k]="macro "${area_ajs[$k]}
1260
          script_montages[$k]="montage -geometry ${RESOLUTION_BY_LINE}x${RESOLUTION_BY_COL} -tile ${NB_TILE_BY_LINE}x${NB_TILE_BY_COL} ${images_folder[$k]}/*jpg ${montages_folder[$k]}/${list_zone[$k]}.png"
1261

1262
          if [[ "${sort_arg_keys[@]}" =~ "--mount" && $VOLUME_MOUNT != "NONE" ]]; then
1263 1264 1265 1266 1267 1268

            sudo docker run --name photos_montage_aladin --rm -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME:$HOME -v ${VOLUME_MOUNT}:"/mnt/${VOLUME_MOUNT}" --network host -e DISPLAY=$DISPLAY -e USER=$USER -e HOME=$HOME image_photos_montage_aladin-${version} /bin/bash -c "java -jar /var/aladin/Aladin-${version}.jar -nogui -trace -script=${script_images[$k]};${script_montages[$k]} " > ${log_aladin_file[$k]} 2>&1

          else
            sudo docker run --name photos_montage_aladin --rm -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME:$HOME --network host -e DISPLAY=$DISPLAY -e USER=$USER -e HOME=$HOME image_photos_montage_aladin-${version} /bin/bash -c "java -jar /var/aladin/Aladin-${version}.jar -nogui -trace -script=${script_images[$k]};${script_montages[$k]} " > ${log_aladin_file[$k]} 2>&1
          fi
1269

1270
          echo "=> Construction OK"
1271
          #----------------------------------------#
1272 1273
          echo ""
          echo "=> For more informations about the construction please see:"
1274
          echo ${log_aladin_file[$k]}
1275
          echo ""
1276

1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
          #----------------------------------------#
          #construction of infos_file[$k]
          echo "===============================================" > ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "Infos construction of ${list_zone[$k]}          " >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "           $(date +'%Y-%m-%d %H-%M-%S')        " >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "===============================================" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "--------------------" >> ${infos_file[$k]}
          echo "--- Aladin infos ---" >> ${infos_file[$k]}
          echo "--------------------" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "Aladin version: $ALADIN_VERSION" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1293 1294
          echo "AJS file: ${area_ajs[$k]}" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1295
          echo "Angular dimension value in second of Arc: ${ANGULAR}" >> ${infos_file[$k]}
1296
          echo "" >> ${infos_file[$k]}
1297 1298 1299 1300 1301 1302
          echo "--------------------------" >> ${infos_file[$k]}
          echo "--- Image magick infos ---" >> ${infos_file[$k]}
          echo "--------------------------" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "Tile dimension: $NB_TILE_BY_LINE x $NB_TILE_BY_COL" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1303 1304
          echo "Resolution: ${RESOLUTION_BY_LINE}x${RESOLUTION_BY_COL}" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1305 1306 1307 1308 1309 1310
          echo "-----------------------------------" >> ${infos_file[$k]}
          echo "--- photos_montage_aladin infos ---" >> ${infos_file[$k]}
          echo "-----------------------------------" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "OPTIONS: $@" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1311 1312 1313 1314 1315 1316 1317 1318

          if [ $VOLUME_MOUNT != "NONE" ];then
          echo "VOLUME MOUNTED: $VOLUME_MOUNT" >> ${infos_file[$k]}
          else
          echo "VOLUME MOUNTED: NO VOLUME" >> ${infos_file[$k]}
          fi
          echo "" >> ${infos_file[$k]}

1319 1320
          echo "Input surveys file: $INPUT_FILE_SURVEYS" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1321 1322
          echo "number of surveys: $nb_lines_survey" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1323 1324
          echo "Input areas file: $INPUT_FILE_AREAS" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1325 1326
          echo "Number of areas: ${#list_zone[@]}" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1327 1328
          echo "Images folder: ${images_folder[$k]}" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1329 1330
          echo "Number of images: $(find ${images_folder[$k]} -type f | wc -l)" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1331 1332
          echo "Montages folder: ${montages_folder[$k]}" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
1333
          echo "Number of montages: $(find ${montages_folder[$k]} -type f | wc -l)" >> ${infos_file[$k]}
1334 1335 1336 1337 1338 1339 1340 1341
          echo "" >> ${infos_file[$k]}
          echo "log aladin file: ${log_aladin_file[$k]}" >> ${infos_file[$k]}
          echo "" >> ${infos_file[$k]}
          echo "===============================================" >> ${infos_file[$k]}

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


1342 1343
        else

1344
          echo -e "=> ${GREEN}INFOS${COLOR_OFF} : Nothing to do for ${area_folder[$k]} all files are present"
1345 1346 1347 1348 1349
          echo " "
        fi

      done
      #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
1350
      #------------------------#
1351 1352
      if [ "${force_warning}" == 'TRUE' ]; then

1353 1354
        function_message "TYPE_FORCE_WARNING" "${INPUT_FILE_AREAS}"
        exit 0
1355

1356 1357 1358 1359
      fi


      #------------------------#
1360 1361 1362
      echo ""
      echo "======================================="
      echo ""
PENGUEN Julien's avatar
PENGUEN Julien committed
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
      echo "=> End of photos_montage_aladin program"
      echo ""



      ;;

    "-b"|"--build")
      #################################
      # use: ./photos_montage_aladin.sh -b OR --build #
      #################################

1375
      version=${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1376 1377 1378 1379 1380 1381
      #---------------------------------#

      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
1382
      present=$(echo $list_jar| grep "${version}")
PENGUEN Julien's avatar
PENGUEN Julien committed
1383 1384

      if [ $? -eq 1 ]; then
1385 1386

        function_message "TYPE_EXIST_VERSION"
PENGUEN Julien's avatar
PENGUEN Julien committed
1387
        exit 0
1388

PENGUEN Julien's avatar
PENGUEN Julien committed
1389 1390 1391 1392
      fi


      #---------------------------------#
1393
      list_jar=$(sudo docker images | awk '/^image_photos_montage_aladin-/{print $1}')
PENGUEN Julien's avatar
PENGUEN Julien committed
1394

1395
      present=$(echo $list_jar| grep "${version}")
PENGUEN Julien's avatar
PENGUEN Julien committed
1396 1397 1398 1399 1400 1401

      if [ $? -eq 1 ]; then

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

1402
        function_build_image ${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1403 1404 1405 1406 1407 1408 1409 1410 1411

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


      else

        #------------------------------------#
        #call function function_delete_image

1412
        function_delete_image ${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1413 1414 1415 1416

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

1417
        function_build_image ${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
1418 1419 1420 1421 1422 1423

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

      fi


PENGUEN Julien's avatar
PENGUEN Julien committed
1424 1425
      ;;
    "-u"|"--update")
PENGUEN Julien's avatar
PENGUEN Julien committed
1426
      ##################################################
PENGUEN Julien's avatar
PENGUEN Julien committed
1427
      # use: ./photos_montage_aladin.sh -u OR --update #
PENGUEN Julien's avatar
PENGUEN Julien committed
1428
      ##################################################
PENGUEN Julien's avatar
PENGUEN Julien committed
1429

PENGUEN Julien's avatar
PENGUEN Julien committed
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
      #------------------------------------------#
      #call function function_jar_updated_search

      new_aladin_version=`function_jar_updated_search`
      old_aladin_version=${ALADIN_VERSION}

      if [ ${new_aladin_version} != ${old_aladin_version} ]; then
        #case update available
        wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin.jar
        mv conf-montage/Aladin.jar conf-montage/Aladin-${new_aladin_version}.jar

        sed -i "s/${old_aladin_version}/${new_aladin_version}/" .env

        echo "=> An update is available"
        echo "- new update version:" ${new_aladin_version}

        #-----------------------------------#
        #call function function_delete_image

        function_delete_image ${old_aladin_version}

        #-----------------------------------#
        #build

        echo "- Creating the photos_montage_aladin-${new_aladin_version} docker image in progress ..."
        echo '------------------------------------------------------------------'
1456

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

PENGUEN Julien's avatar
PENGUEN Julien committed
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
        echo "=> creating the photos_montage_aladin-${new_aladin_version} docker image successfully"
        echo '------------------------------------------------------------------'
        echo ''

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

          rm conf-montage/Aladin-${new_aladin_version}.jar
          rm .logfile

      else
        #case no update

        echo '-----------------------------------------------------------'
        echo ''
        echo "- photos_montage_aladin use already the last aladin version"
        echo '- aladin version: ' ${ALADIN_VERSION}
        echo ''
        echo '-----------------------------------------------------------'

      fi


PENGUEN Julien's avatar
PENGUEN Julien committed
1481 1482
      ;;
    "-i"|"--infos")
PENGUEN Julien's avatar
PENGUEN Julien committed
1483
      #################################################
PENGUEN Julien's avatar
PENGUEN Julien committed
1484
      # use: ./photos_montage_aladin.sh -i OR --infos #
PENGUEN Julien's avatar
PENGUEN Julien committed
1485 1486
      #################################################

1487

PENGUEN Julien's avatar
PENGUEN Julien committed
1488 1489 1490 1491 1492
      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 -n -r .temp | awk '{print $1}')
      rm .temp

1493
      id_image=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-${ALADIN_VERSION})
PENGUEN Julien's avatar
PENGUEN Julien committed
1494 1495 1496 1497 1498

      echo ""
      echo "-------------------------------------------------------------------"
      echo "       aladin stable versions available on :"
      echo ""
1499 1500
      echo -e "${RED}- Aladin server : ${ALADIN_URL}${RED}"
      echo -e "${GREEN}- Localhost${COLOR_OFF}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1501 1502 1503 1504 1505 1506

      echo "-------------------------------------------------------------------"
      echo ""

      for number_version in ${list_jar}
      do
1507
        if [ -z $id_image ]; then
1508
          echo -e "   ${RED}   ${number_version}${COLOR_OFF}"
1509
        else
PENGUEN Julien's avatar
PENGUEN Julien committed
1510
          if [ ${number_version} == ${ALADIN_VERSION} ]; then
1511
            echo -e "   ${GREEN} *${COLOR_OFF} ${RED}${number_version}${COLOR_OFF}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1512
          else
1513
            echo -e "   ${RED}   ${number_version}${COLOR_OFF}"
PENGUEN Julien's avatar
PENGUEN Julien committed
1514
          fi
1515
        fi
PENGUEN Julien's avatar
PENGUEN Julien committed
1516 1517
      done

1518

1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
      echo ""
      echo "-------------------------------------------------------------------"
      echo ""

      echo "        Options by default define on .env file:"
      echo ""
      echo "- INPUT_FILE_SURVEYS: ${INPUT_FILE_SURVEYS}"
      echo "- INPUT_FILE_AREAS: ${INPUT_FILE_AREAS}"
      echo "- ANGULAR: ${ANGULAR}"
      echo "- NB_TILE_BY_LINE: ${NB_TILE_BY_LINE}"
      echo "- NB_TILE_BY_COL: ${NB_TILE_BY_COL}"
      echo "- RESOLUTION_BY_LINE: ${RESOLUTION_BY_LINE}"
      echo "- RESOLUTION_BY_COL: ${RESOLUTION_BY_COL}"
      echo ""


PENGUEN Julien's avatar
PENGUEN Julien committed
1535 1536 1537 1538
      echo "-------------------------------------------------------------------"
      echo ""


PENGUEN Julien's avatar
PENGUEN Julien committed
1539 1540 1541
      ;;

    "-v"|"--version")
1542
      ###################################################
PENGUEN Julien's avatar
PENGUEN Julien committed
1543
      # use: ./photos_montage_aladin.sh -v OR --version #
1544
      ###################################################
PENGUEN Julien's avatar
PENGUEN Julien committed
1545 1546 1547 1548 1549 1550

      echo '- photos_montage_aladin.sh version: ' ${SCRIPT_VERSION}

      #---------------------------------#
      ;;

1551
    "-rm"|"--remove")
1552
      ###################################################
PENGUEN Julien's avatar
PENGUEN Julien committed
1553
      # use: ./photos_montage_aladin.sh -rm OR --remove #
1554 1555
      ###################################################

1556
      version=${sort_arg_values[0]}
1557

1558
      list_image_version=$(sudo docker images | awk '/^image_photos_montage_aladin-/{print $1}')
1559

1560
      present=$(echo $list_image_version| grep "${version}")
1561 1562 1563

      if [ $? -eq 1 ]; then

1564
        function_message "TYPE_DELETE_EXIST_VERSION"
1565 1566 1567 1568 1569 1570 1571 1572
        exit 0

      else

        function_delete_image $version

      fi
      #---------------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
1573 1574
      ;;
    "-h"|"--help")