#! /bin/sh # ------------------------------------------------------------- # --- init # ------------------------------------------------------------- # leave on error set -e # set program name and filespec: script=$0 if [[ $0 != /* ]]; then script="`/bin/pwd`/${script}"; fi prog=`/bin/basename ${script}` bindir=`/usr/bin/dirname ${script}` # ------------------------------------------------------------- # --- help # ------------------------------------------------------------- DisplayUsage () { ${PAGER:-less} << EOF NAME $prog - General Storage System : ECMWF EcAccess gateway USAGE ${prog} ls [-l,--long] -l, --long : long listing including modes, times, sizes etc ${prog} get [-f,--force] [-m,--mkdir] ${prog} put [-f,--force] [-m,--mkdir] -f, --force : overwrite existing destination files if necessary -m, --mkdir : create destination directories if necessary FILE SPECIFICATION A file on ecfs is specified by a domain and standard unix file name: echome[nl5]:path/file ecscratch[nl5]:path/file ecfs[nl5]:path/file ectmp[nl5]:path/file GENERAL OPTIONS -v, --verbose : display info on progress EOF exit 0 } # err 'help text' err () { echo "$1" 1>&2 } # errit errit () { err "$prog - ERROR - Use '$prog --help' for more info." exit $1 } # ------------------------------------------------------------- # --- arguments # ------------------------------------------------------------- options='' task='' filespecs='' verbose='' # extract arguments for arg in "$@" ; do case ${arg} in -h | --help ) DisplayUsage ;; -v | --verbose ) verbose='T' ;; -* ) options="${options} ${arg}" ;; * ) # task or (one of the) file(s) if [ -z "${task}" ]; then task=${arg} else filespec=${arg} filespecs="${filespecs} ${filespec}" fi ;; esac done # not complete ? if [ -z "${task}" ]; then err "$prog - no arguments specified" errit 1 fi # ------------------------------------------------------------- # --- functions # ------------------------------------------------------------- # # EvalSpecials echome[ab1]:data/a.txt # filespec=${FS} # # Extract the leading domain part, set environment, # return last part in variable 'FS' . # EvalSpecials () { # split in domain and rest: ecdomain="`echo $1 | /usr/bin/cut -d ':' -f 1`" FS="`echo $1 | /usr/bin/cut -d ':' -f 2-`" # set domain export ECDOMAIN="${ecdomain}" } # ------------------------------------------------------------- # --- annote # ------------------------------------------------------------- # # Certificate expired: # # ecls # out : Certificate expired for getFileList # status : 1 # # eccert -expire # out : May 12 06:11:57 2005 GMT # status : 1 # # After 'eccert' a new certificate is installed: # # eccert -expire # out : May 19 06:11:57 2005 GMT # status : 0 # # ------------------------------------------------------------- # --- begin # ------------------------------------------------------------- test ${verbose} && echo "$prog - $prog $*" # test task: case ${task} in # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # list file or directory # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'list' ) # extract options eccommand='ecls' for option in ${options} ; do case ${option} in -l | --long ) eccommand="ecdir" ;; -* ) err "$prog - unknown option '${option}' for task '${task}'" errit 1 ;; esac done # extract source and destination filespec: filespec='' for spec in ${filespecs} ; do EvalSpecials ${spec} if [ -z "${filespec}" ]; then filespec=${FS} else err "$prog - ERROR - task '${task}' requires single file specification only." errit 1 fi done if [ -z "${filespec}" ]; then err "$prog - ERROR - tasks '${task}' requires file specification." errit 1 fi # list files: ${eccommand} ${filespec} ;; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # copy files # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'get' ) # extract options ecget_options='' do_mkdir='' for option in ${options} ; do case ${option} in -f | --force ) ecget_options="${ecget_options}" ;; -m | --mkdir ) do_mkdir='true' ;; -* ) err "$prog - unknown option '${option}' for task '${task}'" errit 1 ;; esac done # extract source and destination filespec: source_spec='' dest_spec='' for spec in ${filespecs} ; do if [ -z "${source_spec}" ]; then EvalSpecials ${spec} source_spec=${FS} elif [ -z "${dest_spec}" ]; then dest_spec=${spec} else err "$prog - ERROR - task '${task}' requires source and destination file specifications only." errit 1 fi done if [ -z "${dest_spec}" ]; then err "$prog - ERROR - task '${task}' requires source and destination file specifications." errit 1 fi # create destination directory ? # o destination is an existing file : not necessary # o destination is an existing directory : not necessary if [ ${do_mkdir} ] && [ ! -f ${dest_spec} ] && [ ! -d ${dest_spec} ]; then # destination is not an existing file or directory; # create the directory part of the destination: dest_dir=`/usr/bin/dirname ${dest_spec}` test "${dest_dir}" != "." && /bin/mkdir -p ${dest_dir} fi # copy file: ecget ${ecget_options} ${source_spec} ${dest_spec} ;; 'put' ) # extract options ecput_options='' do_mkdir='' for option in ${options} ; do case ${option} in -f | --force ) ecput_options="${ecput_options}" ;; -m | --mkdir ) do_mkdir='true' ;; -* ) err "$prog - unknown option '${option}' for task '${task}'" errit 1 ;; esac done # extract source and destination filespec: source_spec='' dest_spec='' for spec in ${filespecs} ; do EvalSpecials ${spec} if [ -z "${source_spec}" ]; then source_spec=${FS} elif [ -z "${dest_spec}" ]; then dest_spec=${FS} else err "$prog - ERROR - task '${task}' requires source and destination file specifications only." errit 1 fi done if [ -z "${dest_spec}" ]; then err "$prog - ERROR - task '${task}' requires source and destination file specifications." errit 1 fi # create destination directory ? if [ ${do_mkdir} ]; then # do not test if directory already exists, # this takes more time than just creation; # supress error messages about already existing directories ... dest_dir=`/usr/bin/dirname ${dest_spec}` if ! ( ecmkdir -p ec:${dest_dir} > /dev/null 2>&1 ); then test ${verbose} && echo "$prog - error status from ecmkdir; directory already exist ? ignored" fi fi # copy file: ecput ${ecput_options} ${source_spec} ${dest_spec} ;; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # task ??? # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ) err "$prog - ERROR - unsupported task '${task}'" errit 1 ;; esac # tasks # ------------------------------------------------------------- # --- end # -------------------------------------------------------------