gss_ec 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #! /bin/sh
  2. # -------------------------------------------------------------
  3. # --- init
  4. # -------------------------------------------------------------
  5. # leave on error
  6. set -e
  7. # set program name and filespec:
  8. script=$0
  9. if [[ $0 != /* ]]; then script="`/bin/pwd`/${script}"; fi
  10. prog=`/bin/basename ${script}`
  11. bindir=`/usr/bin/dirname ${script}`
  12. # -------------------------------------------------------------
  13. # --- help
  14. # -------------------------------------------------------------
  15. DisplayUsage ()
  16. {
  17. ${PAGER:-less} << EOF
  18. NAME
  19. $prog - General Storage System : ECMWF EcAccess gateway
  20. USAGE
  21. ${prog} ls [-l,--long] <ecfsfilespec>
  22. -l, --long : long listing including modes, times, sizes etc
  23. ${prog} get [-f,--force] [-m,--mkdir] <source-ecfsfilespec> <dest-filespec>
  24. ${prog} put [-f,--force] [-m,--mkdir] <source-ecfsfilespec> <dest-filespec>
  25. -f, --force : overwrite existing destination files if necessary
  26. -m, --mkdir : create destination directories if necessary
  27. FILE SPECIFICATION
  28. A file on ecfs is specified by a domain and standard unix file name:
  29. echome[nl5]:path/file
  30. ecscratch[nl5]:path/file
  31. ecfs[nl5]:path/file
  32. ectmp[nl5]:path/file
  33. GENERAL OPTIONS
  34. -v, --verbose : display info on progress
  35. EOF
  36. exit 0
  37. }
  38. # err 'help text'
  39. err ()
  40. {
  41. echo "$1" 1>&2
  42. }
  43. # errit <exit-status>
  44. errit ()
  45. {
  46. err "$prog - ERROR - Use '$prog --help' for more info."
  47. exit $1
  48. }
  49. # -------------------------------------------------------------
  50. # --- arguments
  51. # -------------------------------------------------------------
  52. options=''
  53. task=''
  54. filespecs=''
  55. verbose=''
  56. # extract arguments
  57. for arg in "$@" ; do
  58. case ${arg} in
  59. -h | --help ) DisplayUsage ;;
  60. -v | --verbose ) verbose='T' ;;
  61. -* ) options="${options} ${arg}" ;;
  62. * ) # task or (one of the) file(s)
  63. if [ -z "${task}" ]; then
  64. task=${arg}
  65. else
  66. filespec=${arg}
  67. filespecs="${filespecs} ${filespec}"
  68. fi
  69. ;;
  70. esac
  71. done
  72. # not complete ?
  73. if [ -z "${task}" ]; then
  74. err "$prog - no arguments specified"
  75. errit 1
  76. fi
  77. # -------------------------------------------------------------
  78. # --- functions
  79. # -------------------------------------------------------------
  80. #
  81. # EvalSpecials echome[ab1]:data/a.txt
  82. # filespec=${FS}
  83. #
  84. # Extract the leading domain part, set environment,
  85. # return last part in variable 'FS' .
  86. #
  87. EvalSpecials ()
  88. {
  89. # split in domain and rest:
  90. ecdomain="`echo $1 | /usr/bin/cut -d ':' -f 1`"
  91. FS="`echo $1 | /usr/bin/cut -d ':' -f 2-`"
  92. # set domain
  93. export ECDOMAIN="${ecdomain}"
  94. }
  95. # -------------------------------------------------------------
  96. # --- annote
  97. # -------------------------------------------------------------
  98. #
  99. # Certificate expired:
  100. #
  101. # ecls
  102. # out : Certificate expired for getFileList
  103. # status : 1
  104. #
  105. # eccert -expire
  106. # out : May 12 06:11:57 2005 GMT
  107. # status : 1
  108. #
  109. # After 'eccert' a new certificate is installed:
  110. #
  111. # eccert -expire
  112. # out : May 19 06:11:57 2005 GMT
  113. # status : 0
  114. #
  115. # -------------------------------------------------------------
  116. # --- begin
  117. # -------------------------------------------------------------
  118. test ${verbose} && echo "$prog - $prog $*"
  119. # test task:
  120. case ${task} in
  121. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122. # list file or directory
  123. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. 'list' )
  125. # extract options
  126. eccommand='ecls'
  127. for option in ${options} ; do
  128. case ${option} in
  129. -l | --long ) eccommand="ecdir" ;;
  130. -* )
  131. err "$prog - unknown option '${option}' for task '${task}'"
  132. errit 1
  133. ;;
  134. esac
  135. done
  136. # extract source and destination filespec:
  137. filespec=''
  138. for spec in ${filespecs} ; do
  139. EvalSpecials ${spec}
  140. if [ -z "${filespec}" ]; then
  141. filespec=${FS}
  142. else
  143. err "$prog - ERROR - task '${task}' requires single file specification only."
  144. errit 1
  145. fi
  146. done
  147. if [ -z "${filespec}" ]; then
  148. err "$prog - ERROR - tasks '${task}' requires file specification."
  149. errit 1
  150. fi
  151. # list files:
  152. ${eccommand} ${filespec}
  153. ;;
  154. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155. # copy files
  156. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157. 'get' )
  158. # extract options
  159. ecget_options=''
  160. do_mkdir=''
  161. for option in ${options} ; do
  162. case ${option} in
  163. -f | --force ) ecget_options="${ecget_options}" ;;
  164. -m | --mkdir ) do_mkdir='true' ;;
  165. -* )
  166. err "$prog - unknown option '${option}' for task '${task}'"
  167. errit 1
  168. ;;
  169. esac
  170. done
  171. # extract source and destination filespec:
  172. source_spec=''
  173. dest_spec=''
  174. for spec in ${filespecs} ; do
  175. if [ -z "${source_spec}" ]; then
  176. EvalSpecials ${spec}
  177. source_spec=${FS}
  178. elif [ -z "${dest_spec}" ]; then
  179. dest_spec=${spec}
  180. else
  181. err "$prog - ERROR - task '${task}' requires source and destination file specifications only."
  182. errit 1
  183. fi
  184. done
  185. if [ -z "${dest_spec}" ]; then
  186. err "$prog - ERROR - task '${task}' requires source and destination file specifications."
  187. errit 1
  188. fi
  189. # create destination directory ?
  190. # o destination is an existing file : not necessary
  191. # o destination is an existing directory : not necessary
  192. if [ ${do_mkdir} ] && [ ! -f ${dest_spec} ] && [ ! -d ${dest_spec} ]; then
  193. # destination is not an existing file or directory;
  194. # create the directory part of the destination:
  195. dest_dir=`/usr/bin/dirname ${dest_spec}`
  196. test "${dest_dir}" != "." && /bin/mkdir -p ${dest_dir}
  197. fi
  198. # copy file:
  199. ecget ${ecget_options} ${source_spec} ${dest_spec}
  200. ;;
  201. 'put' )
  202. # extract options
  203. ecput_options=''
  204. do_mkdir=''
  205. for option in ${options} ; do
  206. case ${option} in
  207. -f | --force ) ecput_options="${ecput_options}" ;;
  208. -m | --mkdir ) do_mkdir='true' ;;
  209. -* )
  210. err "$prog - unknown option '${option}' for task '${task}'"
  211. errit 1
  212. ;;
  213. esac
  214. done
  215. # extract source and destination filespec:
  216. source_spec=''
  217. dest_spec=''
  218. for spec in ${filespecs} ; do
  219. EvalSpecials ${spec}
  220. if [ -z "${source_spec}" ]; then
  221. source_spec=${FS}
  222. elif [ -z "${dest_spec}" ]; then
  223. dest_spec=${FS}
  224. else
  225. err "$prog - ERROR - task '${task}' requires source and destination file specifications only."
  226. errit 1
  227. fi
  228. done
  229. if [ -z "${dest_spec}" ]; then
  230. err "$prog - ERROR - task '${task}' requires source and destination file specifications."
  231. errit 1
  232. fi
  233. # create destination directory ?
  234. if [ ${do_mkdir} ]; then
  235. # do not test if directory already exists,
  236. # this takes more time than just creation;
  237. # supress error messages about already existing directories ...
  238. dest_dir=`/usr/bin/dirname ${dest_spec}`
  239. if ! ( ecmkdir -p ec:${dest_dir} > /dev/null 2>&1 ); then
  240. test ${verbose} && echo "$prog - error status from ecmkdir; directory already exist ? ignored"
  241. fi
  242. fi
  243. # copy file:
  244. ecput ${ecput_options} ${source_spec} ${dest_spec}
  245. ;;
  246. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  247. # task ???
  248. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249. * )
  250. err "$prog - ERROR - unsupported task '${task}'"
  251. errit 1
  252. ;;
  253. esac # tasks
  254. # -------------------------------------------------------------
  255. # --- end
  256. # -------------------------------------------------------------