source_params () { if [ ! -f "${MDS_PARAMS}" ]; then exit_error "Cannot find sumbission parameters file '${MDS_PARAMS}'. Use -genparams to create a new one." fi dos2unix ${MDS_PARAMS} >/dev/null 2>&1 source ${MDS_PARAMS} } list_units () { local upath=$1 for uf in $( ls -1 $upath/*.sh ); do eval $( cat $uf | sed -n '/^# DESCRIPTION/s/^# DESCRIPTION \([^ ]\+\) \(.*\)$/echo_y -ne \1; echo \\\t\2/p' ) done } list_modules () { local module=$1 case $module in software) list_units ${MDS_LIBEXEC_PATH}/software ;; infrastructure|infrastructures) list_units ${MDS_LIBEXEC_PATH}/grid/infrastructures ;; portal|portals) list_units ${MDS_LIBEXEC_PATH}/portals ;; *) exit_error "Wrong module type '$module' specified." ;; esac } source_module () { local moduletype=$1 local modulename=$2 case $moduletype in software) modulepath="${MDS_LIBEXEC_PATH}/software/${modulename}.sh" ;; infrastructure) modulepath="${MDS_LIBEXEC_PATH}/grid/infrastructures/${modulename}.sh" ;; portal) modulepath="${MDS_LIBEXEC_PATH}/portals/${modulename}.sh" ;; *) exit_error "Wrong module type '$moduletype' specified." ;; esac [ -f "$modulepath" ] && source $modulepath || exit_error "There is no $moduletype module '$modulename'" } infrasrtucture_gen_params_default () { [ -n "$(type -t jobdescription_gen_params)" ] && jobdescription_gen_params [ -n "$(type -t submission_gen_params)" ] && submission_gen_params [ -n "$(type -t proxy_gen_params)" ] && proxy_gen_params } generate_params () { [ -n "$(type -t software_gen_params)" ] && software_gen_params [ -n "$(type -t infrastructure_gen_params)" ] && infrasrtucture_gen_params || infrasrtucture_gen_params_default [ -n "$(type -t portal_gen_params)" ] && portal_gen_params } usage () { echo_g "MolDynSub CLI version $VERSION usage:" echo_r -e "\t${0##*/} [ OPTIONS ]" echo_g "MODULES OPTIONS:" echo_y -e "\t--list {software|infrastructures|portals}" echo -e "\t\tlist avaialable modules for specified type" echo_y -e "\t--software " echo -e "\t\tdefine software module to use (default is 'gromacs-md-mdrun')" echo_y -e "\t--infrastructure " echo -e "\t\tdefine infrastructure to use (default is 'arc')" echo_y -e "\t--portal {|none}" echo -e "\t\tdefine portal implementation to use (default is 'moldyngrid')" echo_g "GENERAL OPTIONS:" echo_y -e "\t--params " echo -e "\t\tredefine configured params file location ($MDS_PARAMS)" echo_y -e "\t--genparams" echo -e "\t\tfill params file with the default template for choosen software module" echo_y -e "\t--dryrun" echo -e "\t\tonly generate necessary files, but disable actual job submission" echo_y -e "\t--help" echo -e "\t\tprint this help message" [ -n "$(type -t software_usage)" ] && software_usage [ -n "$(type -t infrastructure_usage)" ] && infrastructure_usage [ -n "$(type -t portal_usage)" ] && portal_usage exit 0 } source_default_modules () { if [ -z "${MDS_SOFTWARE}" ]; then MDS_SOFTWARE=$MDS_DEFAULT_SOFTWARE source_module 'software' $MDS_SOFTWARE fi if [ -z "$MDS_INFRASTRUCTURE" ]; then MDS_INFRASTRUCTURE=$MDS_DEFAULT_INFRASTRUCTURE source_module 'infrastructure' $MDS_INFRASTRUCTURE fi if [ -z "$MDS_PORTAL" ]; then MDS_PORTAL=$MDS_DEFAULT_PORTAL source_module 'portal' $MDS_PORTAL fi } parse_cmd_options () { while [ $# -ne 0 ]; do case $1 in --list|-l) list_modules $2 exit 0 ;; --software|-s) MDS_SOFTWARE=$2 source_module 'software' $MDS_SOFTWARE shift 2 ;; --infrastructure|-i) MDS_INFRASTRUCTURE=$2 source_module 'infrastructure' $MDS_INFRASTRUCTURE shift 2 ;; --portal|-p) MDS_PORTAL=$2 [ "$MDS_PORTAL" = "none" ] && DISABLEPORTAL=1 || \ source_module 'portal' $MDS_PORTAL shift 2 ;; --params) MDS_PARAMS=$2 shift 2 ;; --genparams) GEN_PARAMS=1 shift ;; --dryrun) DRYRUN=1 shift ;; --help|-h) source_default_modules usage ;; *) source_default_modules [ -n "$(type -t software_parse_cmd_options)" ] && software_parse_cmd_options $@ [ -n "$(type -t infrastructure_parse_cmd_options)" ] && infrastructure_parse_cmd_options $@ [ -n "$(type -t portal_parse_cmd_options)" ] && portal_parse_cmd_options $@ [ -n "$PARSED_BY_MODULE" ] && shift $PARSED_BY_MODULE || usage ;; esac done source_default_modules if [ -n "$GEN_PARAMS" ]; then generate_params > "$MDS_PARAMS" exit 0 fi } next_idx_var () { local name_base=$1 local value_base=$2 local name_value=$3 local value_value=$4 local n_idx=0 name_var="${name_base}${n_idx}" while [ -n "${!name_var}" ]; do n_idx=$((n_idx+1)) name_var="${name_base}${n_idx}" done value_var="${value_base}${n_idx}" eval ${name_var}="${name_value}" eval ${value_var}="${value_value}" }