#!/bin/sh . ./.env #---------------------------# #-------- functions --------# #---------------------------# function_build_tab_hach() { # 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 # - message: in case of error, error message # ---------------------- # # 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 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"; ARRAY["--angular"]="NUMBER"; # ---------------------- # # 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; ARGS_WEIGHT["--angular"]=2; # -------- # indice=0; for params in "$@" do tab_params[$indice]=$params ((indice++)); done # -------- # val_error="FALSE" elements_ok=0 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 elements_ok=$(($elements_ok + 1)) tab_keys[$indice]=$elem tab_values[$indice]="None" tab_weight[$indice]=${ARGS_WEIGHT[${elem}]} if [ "${ARRAY[${elem}]}" != "None" ]; then #case argument needed for the option FOUND=$(echo ${!ARRAY[*]} | grep -- "${tab_params[$indice +1]}") if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" && ${tab_params[$indice +1]} != -* ]]; then #if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" ]]; then #case argument needed for the option is present on input argument tab_values[$indice]=${tab_params[$indice +1]} elements_ok=$(($elements_ok + 1)) else #case argument needed for the option is missing on input argument #val_element=${elem} message="Missing argument for the option "${elem} val_error="TRUE" fi fi fi ((indice++)); done done # echo "elements_ok="$elements_ok # echo "total ${#@}" if [ "$val_error" == "FALSE" ]; then # echo "val_error false" if [ "$elements_ok" -ne "${#@}" ]; then # echo "val_error true" val_error="TRUE" message="Option not found" else val_error="FALSE" fi fi echo "${tab_keys[@]},${tab_values[@]},${tab_weight[@]},$val_error,$message" } 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[@]}" } 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 } function_jar_updated_search() { # function_jar_updated_search: get the last jar version # returns: # return number_version version=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3) number_version=$(echo ${version:1}) echo "$number_version" } 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 ..." old_id=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-$1) sudo docker rmi ${old_id} #remove old photos_montage_aladin image echo "=> Deleting the image_photos_montage_aladin-$1 docker image successfully" } function_build_image() { # function_build_image: build the photos_montage_aladin image version=$1 #----------------------------------------# 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 '/