Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 181 lines (150 sloc) 3.866 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
#!/bin/bash

xml="xml-file-samples/license.xml xml-file-samples/terms.xml enwiki-pages-articles.xml"
LogFile=log

ERROR()
{
  echo error: $*
  exit 1
}

USAGE()
{
  [ -z "$1" ] || echo error: $*
  echo usage: $(basename "$0") '<options>' command
echo ' --help -h this message'
  echo ' --verbose -v more messages'
  echo ' --get-index=n -g <n> where to rsync the pickles from [1 => render1]'
  echo ' --host=name -o <name> name of the host [render]'
  echo ' --index-only -i only do the index'
  echo ' --no-run -n do not run final make'
  echo ' --sequential -s run rensering in series'
  echo ' --clear -c clear work and dest dirs'
  echo ' --re-parse -r clear parse and render stamps'
  echo ' --work=dir -w <dir> workdir [work]'
  echo ' --dest=dir -d <dir> destdir [image]'
  exit 1
}


verbose=no
host=render
index=
clear=no
work=work
dest=image
run=yes
seq=no
IndexOnly=no
debug=

getopt=/usr/local/bin/getopt
[ -x "${getopt}" ] || getopt=getopt
args=$(${getopt} -o hvg:o:p:inscrw:d: --long=help,verbose,get-index:,host:,index-only,no-run,sequential,clear,re-parse,work:,dest:,debug -- "$@") ||exit 1
# replace the arguments with the parsed values
eval set -- "${args}"

while :
do
case "$1" in
    -v|--verbose)
      verbose=yes
      shift
      ;;

    -g|--get-index)
      index=$2
      shift 2
      ;;

    -o|--host)
      host=$2
      shift 2
      ;;

    -i|--index-only)
      IndexOnly=yes
      shift
      ;;

    -n|--no-run)
      run=no
      shift
      ;;

    -s|--sequential)
      seq=yes
      shift
      ;;

    -c|--clear)
      clear=yes
      shift
      ;;

    -r|--re-parse)
      rm -f stamp-r-parse*
      rm -f stamp-r-render*
      clear=no
      shift
      ;;

    -w|--work)
      work=$2
      shift 2
      ;;

    -d|--dest)
      dest=$2
      shift 2
      ;;

    --debug)
      debug=echo
shift
      ;;

    --)
      shift
break
      ;;

    -h|--help)
      USAGE
      ;;

    *)
      USAGE invalid option: $1
      ;;
  esac
done

this_host=$(hostname --short)
this_id=${this_host##${host}}
[ X"${this_id}" = X"${this_host}" ] && this_id=0

farm="farm${this_id}"

rm -f "${LogFile}"

# clean up
case "${clear}" in
  [yY]|[yY][eE][sS])
    eval ${debug} "time make clean-index DESTDIR='${dest}' WORKDIR='${work}' XML_FILES='${xml}'"
    eval ${debug} "time make '${farm}-clean' DESTDIR='${dest}' WORKDIR='${work}' XML_FILES='${xml}'"
    eval ${debug} "rm -rf '${work}' '${dest}'"
    ;;
esac

# create directories
eval ${debug} "mkdir -p '${work}'"
eval ${debug} "mkdir -p '${dest}'"

# update
git pull --rebase

# copy the index from another machine
if [ -n "${index}" ]
then
list='articles.db offsets.db counts.text'
  items=
  for i in ${list}
  do
items="${items} ${host}${index}:samo/${work}/${i}"
  done
eval ${debug} "rsync -avHx --progress ${items} '${work}'/"
  eval ${debug} "touch stamp-r-index"
fi

# run the build
case "${run}" in
  [yY]|[yY][eE][sS])

    eval ${debug} "time make 'stamp-r-index' DESTDIR='${dest}' WORKDIR='${work}' XML_FILES='${xml}'" 2>&1 | tee -a "${LogFile}"

    case "${IndexOnly}" in
      [yY]|[yY][eE][sS])
        ;;
      *)
        case "${seq}" in
          [yY]|[yY][eE][sS])
            eval ${debug} "time make -j3 '${farm}-parse' DESTDIR='${dest}' WORKDIR='${work}' XML_FILES='${xml}'" 2>&1 | tee -a "${LogFile}"
            eval ${debug} "time make '${farm}-render' DESTDIR='${dest}' WORKDIR='${work}' XML_FILES='${xml}'" 2>&1 | tee -a "${LogFile}"
            ;;
          *)
            eval ${debug} "time make -j3 '${farm}' DESTDIR='${dest}' WORKDIR='${work}' XML_FILES='${xml}'" 2>&1 | tee -a "${LogFile}"
            ;;
        esac
esac
esac
Something went wrong with that request. Please try again.