Commit 89c998f1 authored by PENGUEN Julien's avatar PENGUEN Julien
Browse files

mise a jour version macos

parent 51aa3b59
......@@ -8,16 +8,392 @@ export LANG=C
#---------------------------#
#-------- functions --------#
#---------------------------#
fonction_get_rtrn()
function_message()
{
# fonction_get_rtrn: get return result part
# params:
# $1 - return result string
# $2 - number of part to be returned
# returns:
# return result part
# function_message: display message with input argument
# input error_message to display
type_message=$1
message=$2
if [ "$type_message" == "TYPE_VAL_ERROR" ]; then
echo ""
echo "------------------------------------"
echo ""
echo -e "\033[31m========================================================="
echo -e "WARNING => ${message}"
echo -e "=========================================================\033[0m"
elif [ "$type_message" == "TYPE_HELP" ]; then
echo ""
echo "------------------------------------"
echo ""
echo -e "\033[32m========"
echo -e "= HELP ="
echo -e "========\033[0m"
elif [ "$type_message" == "TYPE_UNKNOWN" ]; then
echo ""
echo -e "\033[31m==============================="
echo -e " error: unrecognized arguments "
echo -e "===============================\033[0m"
elif [ "$type_message" == "TYPE_EXIST_VERSION" ]; then
echo ''
echo -e "\033[31m===================================="
echo -e " WARNING"
echo -e "====================================\033[0m"
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 ''
echo -e "\033[31m===================================="
echo -e " WARNING"
echo -e "====================================\033[0m"
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 ''
echo -e "\033[31m===================================="
echo -e " WARNING"
echo -e "====================================\033[0m"
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"
echo "-b version, --build version build photos_montage_aladin image with selected version"
echo "--select version run photos_montage_aladin with selected version number"
echo "--force-all re-run all areas in input csv"
echo "--force area re-run for the area, the area must be in input csv"
echo "-u, --update update photos_montage_aladin image version"
echo "-rm version, --remove version remove photos_montage_aladin image with selected version"
echo "-h, --help show this help message and exit"
echo "-v, --version give photos_montage_aladin.sh current version number"
echo ""
echo ""
echo "OTHERS:"
echo ""
echo "--survey file run photos_montage_aladin with this survey file instead of "
echo "the default file define on .env file. the survey file must be on format '.dat'"
echo "--area file run photos_montage_aladin with this survey file instead of "
echo "the default file define on .env file. the area file must be on format '.csv'"
echo ""
echo "--angular run photos_montage_aladin with this angular dimension value instead of "
echo "the default angular value define on .env file. the angular value must be on second of arc"
echo "--resolution_col run photos_montage_aladin with this number of pixel by columns for the Image Magick montages"
echo "--resolution_line run photos_montage_aladin with this number of pixel by lines for the Image Magick montages"
echo ""
fi
}
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["--resolution_line"]="NUMBER";
ARRAY["--resolution_col"]="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;
ARGS_WEIGHT["--resolution_line"]=2;
ARGS_WEIGHT["--resolution_col"]=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
#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
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
echo `echo $1|cut --delimiter=, -f $2`
}
function_jar_updated_search()
......@@ -73,24 +449,11 @@ function_build_image()
list_jar=$(sort -r .tempo5 | awk '{print $1}')
rm .tempo*
present=$(echo $list_jar| grep $version)
present=$(echo $list_jar| grep "${version}")
if [ $? -eq 1 ]; then
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 ''
function_message "TYPE_EXIST_VERSION"
exit 0
......@@ -173,7 +536,7 @@ do
echo "#" >> ${outputfile}
echo "rm @1" >> ${outputfile}
echo "get HiPS("$survey")" ${ra_area} ${dec_area} "10'" >> ${outputfile}
echo "get HiPS("$survey")" ${ra_area} ${dec_area} ${ANGULAR}"'" >> ${outputfile}
echo "cm BB localcut" >> ${outputfile}
......@@ -200,8 +563,266 @@ done
#----------- main program ----------------#
#-----------------------------------------#
case $1 in
""|"--select"|"--force-all"|"--force")
#---------------------#
# management arguments
# call function_sort_tab
RESULTAT=`function_build_tab_hach $@`
tab_arg_keys=`echo $RESULTAT | cut --delimiter=, -f 1`
tab_arg_values=`echo $RESULTAT | cut --delimiter=, -f 2`
tab_arg_weight=`echo $RESULTAT | cut --delimiter=, -f 3`
val_error=`echo $RESULTAT | cut --delimiter=, -f 4`
#------------------------------------#
#check if val_error is TRUE
if [ $val_error == "TRUE" ]; then
error_message=`echo $RESULTAT | cut --delimiter=, -f 5`
function_message "TYPE_VAL_ERROR" "${error_message}"
exit 0
fi
#------------------------------------#
#check options presents
#to manage '--select' and '--no_select'
#options
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'
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
echo "${tempo_arg_keys[$p]}"
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'
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
;;
esac
#--------------------------#
# 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`