progress 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/bin/sh
  2. # show the status of stamp files and run programs on the rendering servers
  3. ERROR()
  4. {
  5. echo error: $*
  6. exit 1
  7. }
  8. USAGE()
  9. {
  10. [ -z "$1" ] || echo error: $*
  11. echo usage: $(basename "$0") '<options>'
  12. echo ' --help -h this message'
  13. echo ' --work -w show work directory files'
  14. echo ' --image -i show image directory files'
  15. echo ' --stamps -s show status of stamps'
  16. echo ' --analyse -a analyse the log file'
  17. echo ' --git -g run git pull --rebase'
  18. echo ' --process=<n> -p<n> show python/php processes cut line 1..n [unlimited]'
  19. echo ' --base=<dir> -b <dir> set the base directory [samo]'
  20. echo ' --tail=<n> -t<n> show last line of <base_dir>/log [1]'
  21. echo ' --memory -m show memory status'
  22. echo ' --list=<n-m> -l <n-m> restrict to certain machines [1-9]'
  23. echo ' --language=<xx> -L <xx> process for language [en]'
  24. echo ' --suffix=<s> -S <s> set the language suffix [pedia]'
  25. echo ' --run -r start the Run script in a screen {index, parse, render}'
  26. echo ' --re-render -R start the Run script in a screen {re-render}'
  27. echo ' --copy -c run the copy process i.e. {Copy --to=8 -l <lang>}'
  28. echo ' --combine -k run the combine process'
  29. echo ' --get -G get the data files'
  30. echo ' --sim4 -4 rename files, install fonts and run simulator'
  31. echo ' --new-session -N start a new screen session for run and copy to use'
  32. echo ' --fetch-log -f fetch log files'
  33. exit 1
  34. }
  35. # main program
  36. # ------------
  37. verbose=no
  38. language=en
  39. suffix=pedia
  40. list=''
  41. combine_host=8
  42. base_dir=samo
  43. getopt=/usr/local/bin/getopt
  44. [ -x "${getopt}" ] || getopt=getopt
  45. args=$(${getopt} -o hvb:swigp::t::aml:L:S:rRckG4Nf --long=help,verbose,base:,stamps,work,image,git,process::,tail::,analyse,memory,list:,language:,suffix:,run,re-render,copy,combine,get,sim4,new-session,fetch-log -- "$@") || exit 1
  46. # replace the arguments with the parsed values
  47. eval set -- "${args}"
  48. while :
  49. do
  50. case "$1" in
  51. -v|--verbose)
  52. verbose=yes
  53. shift
  54. ;;
  55. -b|--base)
  56. base_dir="$2"
  57. shift 2
  58. ;;
  59. -s|--stamps)
  60. RenderDo --yes ${list} --brief --post='sed s/stamp-//g' "cd '${base_dir}/work/${language}${suffix}'"' && printf "\33[34;1m%s\33[0;m " stamp* && echo'
  61. shift
  62. ;;
  63. -w|--work)
  64. RenderDo --yes ${list} --brief "cd '${base_dir}' && ls -l 'work/${language}${suffix}'"
  65. shift
  66. ;;
  67. -N|--new-session)
  68. for host in $(RenderDo --print-list)
  69. do
  70. StartScreen --cd="${base_dir}" "${host}"
  71. done
  72. shift
  73. ;;
  74. -r|--run)
  75. c="scripts/Run --clear --language='${language}' --suffix='${suffix}'"
  76. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  77. shift
  78. ;;
  79. -R|--re-render)
  80. c="scripts/Run --re-render --language='${language}' --suffix='${suffix}'"
  81. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  82. shift
  83. ;;
  84. -c|--copy)
  85. c="scripts/Copy --base='${base_dir}' --to='${combine_host}' --language='${language}' --suffix='${suffix}'"
  86. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  87. shift
  88. ;;
  89. -i|--image)
  90. RenderDo --yes ${list} --brief "cd '${base_dir}' && ls -l 'image/${language}${suffix}'"
  91. shift
  92. ;;
  93. -f|--fetch-log)
  94. for host in $(RenderDo --print-list)
  95. do
  96. lf="${host}-${language}.log"
  97. echo fetch log from: ${host} to: ${lf}
  98. RenderDo --yes --list="${host##*[^0-9]}" "cat '${base_dir}/${language}.log'" > "${lf}"
  99. done
  100. shift
  101. ;;
  102. -g|--git)
  103. RenderDo --yes ${list} --verbose "cd '${base_dir}' && git pull --rebase"
  104. shift
  105. ;;
  106. -p|--process)
  107. if [ -n "$2" ]
  108. then
  109. RenderDo --yes ${list} --brief --post="cut -b 1-$2" 'echo;ps -o pid,cmd -u wr --forest'
  110. else
  111. RenderDo --yes ${list} --brief 'echo;ps -o pid,cmd -u wr --forest'
  112. fi
  113. shift 2
  114. ;;
  115. -t|--tail)
  116. t=1
  117. [ -n "$2" ] && t="$2"
  118. RenderDo --yes ${list} --brief "tail -n '${t}' '${base_dir}'/${language}.log"
  119. shift 2
  120. ;;
  121. -a|--analyse)
  122. RenderDo --yes ${list} --brief "cd '${base_dir}' && ./scripts/AnalyseLog '${language}.log'"
  123. shift
  124. ;;
  125. -m|--memory)
  126. RenderDo --yes ${list} --brief 'echo Memory Status \(Megabytes\); free -m'
  127. shift
  128. ;;
  129. -k|--combine)
  130. RenderDo --yes --list="${combine_host}" --brief "cd '${base_dir}' && make VERBOSE='${verbose}' WORKDIR='work' DESTDIR='image' WIKI_FILE_PREFIX=wiki WIKI_LANGUAGE='${language}' combine hash"
  131. shift
  132. ;;
  133. -l|--list)
  134. list="--list=$2"
  135. shift 2
  136. ;;
  137. -L|--language)
  138. language="$2"
  139. shift 2
  140. ;;
  141. -S|--suffix)
  142. base_dir="$2"
  143. shift 2
  144. ;;
  145. -G|--get)
  146. rsync -avHx --progress --exclude='*-tmp' "wr@render${combine_host}:${base_dir}/image/${language}${suffix}" image/
  147. shift
  148. ;;
  149. -4|--sim4)
  150. make DESTDIR="image" fonts-install sim4
  151. shift
  152. ;;
  153. --)
  154. shift
  155. break
  156. ;;
  157. -h|--help)
  158. USAGE
  159. ;;
  160. *)
  161. USAGE invalid option: $1
  162. ;;
  163. esac
  164. done
  165. echo
  166. echo completed