progress 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 [3]'
  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-index -I start the Run script in a screen {index-only}'
  27. echo ' --re-render -R start the Run script in a screen {re-render}'
  28. echo ' --copy -c run the copy process i.e. {Copy --to=8 -l <lang>}'
  29. echo ' --combine -k run the combine process'
  30. echo ' --get -G get the data files'
  31. echo ' --sim4 -4 install fonts, nls and run simulator'
  32. echo ' --new-session -N start a new screen session for run and copy to use'
  33. echo ' --fetch-log -f fetch log files'
  34. echo ' --xml-link -x link wiki .xml file to latest version'
  35. echo ' --high-compress -H enable compression for 4GB SD card (only for --language=en)'
  36. echo ' --abort -A abort remote PHP/Python/make'
  37. exit 1
  38. }
  39. # main program
  40. # ------------
  41. verbose=no
  42. language=en
  43. suffix=pedia
  44. list=''
  45. combine_host=8
  46. base_dir=samo
  47. compression=low
  48. getopt=/usr/local/bin/getopt
  49. [ -x "${getopt}" ] || getopt=getopt
  50. args=$(${getopt} -o hvb:swigp::t::aml:L:S:rRIckG4NfxHA --long=help,verbose,base:,stamps,work,image,git,process::,tail::,analyse,memory,list:,language:,suffix:,run,re-render,re-index,copy,combine,get,sim4,new-session,fetch-log,xml-link,high-compress,abort -- "$@") || exit 1
  51. # replace the arguments with the parsed values
  52. eval set -- "${args}"
  53. while :
  54. do
  55. case "$1" in
  56. -v|--verbose)
  57. verbose=yes
  58. shift
  59. ;;
  60. -b|--base)
  61. base_dir="$2"
  62. shift 2
  63. ;;
  64. -s|--stamps)
  65. 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'
  66. shift
  67. ;;
  68. -w|--work)
  69. RenderDo --yes ${list} --brief "cd '${base_dir}' && ls -l 'work/${language}${suffix}'"
  70. shift
  71. ;;
  72. -N|--new-session)
  73. for host in $(RenderDo --print-list)
  74. do
  75. StartScreen --cd="${base_dir}" "${host}"
  76. done
  77. shift
  78. ;;
  79. -r|--run)
  80. c="scripts/Run --compress='${compression}' --clear --language='${language}' --suffix='${suffix}'"
  81. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  82. shift
  83. ;;
  84. -R|--re-render)
  85. c="scripts/Run --compress='${compression}' --re-render --language='${language}' --suffix='${suffix}'"
  86. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  87. shift
  88. ;;
  89. -I|--re-index)
  90. c="scripts/Run --compress='${compression}' --index-only --language='${language}' --suffix='${suffix}'"
  91. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  92. shift
  93. ;;
  94. -c|--copy)
  95. c="scripts/Copy --base='${base_dir}' --to='${combine_host}' --language='${language}' --suffix='${suffix}'"
  96. RenderDo --yes ${list} --brief "byobu -X eval chdir 'chdir ${base_dir}' 'exec ${c}'"
  97. shift
  98. ;;
  99. -i|--image)
  100. RenderDo --yes ${list} --brief "cd '${base_dir}' && ls -l 'image/${language}${suffix}'"
  101. shift
  102. ;;
  103. -f|--fetch-log)
  104. for host in $(RenderDo --print-list)
  105. do
  106. lf="${host}-${language}.log"
  107. echo fetch log from: ${host} to: ${lf}
  108. RenderDo --yes --list="${host##*[^0-9]}" "cat '${base_dir}/${language}.log'" > "${lf}"
  109. done
  110. shift
  111. ;;
  112. -g|--git)
  113. RenderDo --yes ${list} --verbose "cd '${base_dir}' && git checkout . && git pull --rebase"
  114. shift
  115. ;;
  116. -p|--process)
  117. if [ -n "$2" ]
  118. then
  119. RenderDo --yes ${list} --brief --post="cut -b 1-$2" 'echo;ps -o pid,cmd -u wr --forest'
  120. else
  121. RenderDo --yes ${list} --brief 'echo;ps -o pid,cmd -u wr --forest'
  122. fi
  123. shift 2
  124. ;;
  125. -t|--tail)
  126. t=3
  127. [ -n "$2" ] && t="$2"
  128. RenderDo --yes ${list} --brief "tail -n '${t}' '${base_dir}'/${language}.log"
  129. shift 2
  130. ;;
  131. -a|--analyse)
  132. RenderDo --yes ${list} --brief "cd '${base_dir}' && ./scripts/AnalyseLog '${language}.log'"
  133. shift
  134. ;;
  135. -m|--memory)
  136. RenderDo --yes ${list} --brief 'echo Memory Status \(Megabytes\); free -m'
  137. shift
  138. ;;
  139. -k|--combine)
  140. RenderDo --yes --list="${combine_host}" --brief "cd '${base_dir}' && make VERBOSE='${verbose}' WORKDIR='work' DESTDIR='image' WIKI_FILE_PREFIX=wiki WIKI_LANGUAGE='${language}' combine"
  141. shift
  142. ;;
  143. -l|--list)
  144. list="--list=$2"
  145. shift 2
  146. ;;
  147. -L|--language)
  148. language="$2"
  149. shift 2
  150. ;;
  151. -S|--suffix)
  152. base_dir="$2"
  153. shift 2
  154. ;;
  155. -G|--get)
  156. rsync -cavHx --progress --exclude='*-tmp' "wr@render${combine_host}:${base_dir}/image/${language}${suffix}" image/
  157. shift
  158. ;;
  159. -4|--sim4)
  160. make DESTDIR="image" nls-install fonts-install sim4
  161. shift
  162. ;;
  163. -x|--xml-link)
  164. RenderDo --yes ${list} --brief "cd '${base_dir}' && rm -f '${language}wiki-pages-articles.xml' && ln -fs \$(ls -1 ../'${language}'wiki-*-pages-articles.xml |tail -n 1) '${language}wiki-pages-articles.xml' && ls -l '${language}'*.xml"
  165. shift
  166. ;;
  167. -H|--high-compress)
  168. compression=high
  169. shift
  170. break
  171. ;;
  172. -A|--abort)
  173. RenderDo --yes ${list} --brief 'killall php python make'
  174. shift
  175. ;;
  176. --)
  177. shift
  178. break
  179. ;;
  180. -h|--help)
  181. USAGE
  182. ;;
  183. *)
  184. USAGE invalid option: $1
  185. ;;
  186. esac
  187. done
  188. echo
  189. echo completed