Copy 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/sh
  2. # script to aid copying all data and index-tmp files to one host\
  3. # for final combine and hash stages
  4. ERROR()
  5. {
  6. echo error: $*
  7. exit 1
  8. }
  9. USAGE()
  10. {
  11. [ -z "$1" ] || echo error: $*
  12. echo usage: $(basename "$0") '<options>'
  13. echo ' --help -h this message'
  14. echo ' --verbose -v more messages'
  15. echo ' --base=<dir> -b <dir> set the base directory [samo]'
  16. echo ' --to=<host> -t <host> where to rsync the files to {1 => <this_host_prefix>1}'
  17. echo ' --language=<xx> -l <xx> set language [en]'
  18. echo ' --suffix=<s> -s <s> set language suffix [pedia]'
  19. echo ' --work=<dir> -w <dir> workdir [work]'
  20. echo ' --dest=<dir> -d <dir> destdir [image]'
  21. exit 1
  22. }
  23. verbose=no
  24. base_dir=samo
  25. work=work
  26. dest=image
  27. debug=no
  28. language=en
  29. suffix=pedia
  30. to=
  31. getopt=/usr/local/bin/getopt
  32. [ -x "${getopt}" ] || getopt=getopt
  33. args=$(${getopt} -o hvb:t:l:s:w:d: --long=help,verbose,base:,to:,language:,suffix:,work:,dest:,debug -- "$@") ||exit 1
  34. # replace the arguments with the parsed values
  35. eval set -- "${args}"
  36. while :
  37. do
  38. case "$1" in
  39. -v|--verbose)
  40. verbose=yes
  41. shift
  42. ;;
  43. -b|--base)
  44. base_dir="$2"
  45. shift 2
  46. ;;
  47. -t|--to)
  48. to="$2"
  49. shift 2
  50. ;;
  51. -l|--language)
  52. language="$2"
  53. shift 2
  54. ;;
  55. -s|--suffix)
  56. suffix="$2"
  57. shift 2
  58. ;;
  59. -w|--work)
  60. work="$2"
  61. shift 2
  62. ;;
  63. -d|--dest)
  64. dest="$2"
  65. shift 2
  66. ;;
  67. --debug)
  68. debug=yes
  69. shift
  70. ;;
  71. --)
  72. shift
  73. break
  74. ;;
  75. -h|--help)
  76. USAGE
  77. ;;
  78. *)
  79. USAGE invalid option: $1
  80. ;;
  81. esac
  82. done
  83. [ -z "${language}" ] && USAGE language is not set
  84. [ -z "${to}" ] && USAGE to host is not set
  85. work="${work}/${language}${suffix}"
  86. dest="${dest}/${language}${suffix}"
  87. # extract numeric suffix from host name
  88. # expect that the rendering hosts are numbered from zero
  89. this_host=$(hostname --short)
  90. this_host_prefix=${this_host%%[0-9]}
  91. this_id=${this_host##*[^0-9]}
  92. [ -z "${this_id}" ] && this_id=0
  93. [ -z "${to%%[0-9]}" ] && to="${this_host_prefix}${to}"
  94. if [ X"${this_host}" != X"${to}" ]
  95. then
  96. d="${to}:${base_dir}/${dest}"
  97. case "${verbose}" in
  98. [yY][eE][sS])
  99. echo copying files to: ${d}
  100. ;;
  101. *)
  102. ;;
  103. esac
  104. rsync -cavHx --progress "${dest}"/*.dat "${dest}"/*.idx-tmp "${d}/"
  105. else
  106. echo warning: transfer to self ignored
  107. fi