The ren­der­ing of the lgm posters is split into two asyn­cro­nous parts, because the actual poster gen­er­a­tor involves some stuff that no admin­is­tra­tor wants to have run­ning on a sta­ble web server. Part 1 is a sim­ple input inter­face, that does noth­ing more than writ­ing plain text files entered via a html textarea. This runs on the lgm server. Part 2 syn­chro­nizes with the online part, gen­er­ates posters and uploads new files. This runs on a machine in the our stu­dio.

The script starts by defin­ing some gen­eral vari­ables and stor­ing infor­ma­tion about the current/local voice files.

  TMPDIR=tmp
  PDFDIR=o/__
  VOICEDIR=o/free/voice
 
REMOTELIST=http://libregraphicsmeeting.org/2013/r+w/list.php

The cur­rent, local num­ber of voice files is stored (VNUMLOCALE=`ls $VOICEDIR/*.txt | wc -l`) and I start a list with 40 ran­dom voice files, that will be used together with new files down­loaded from the server.

  VNUMLOCALE=`ls $VOICEDIR/*.txt | wc -l`
 
ls -t $VOICEDIR/*.txt | \ rev | cut -d "/" -f 1 | rev | \ shuf -n 40 > q+a.list

To be able to dif­fer­en­ti­ate new from old voice files I do the fol­low­ing: ls $VOICEDIR/*.txt | rev | cut -d "/" -f 1 | rev | sed ':a;N;$!ba;s/\n/|/g' lists all cur­rent voice files sep­a­rated by new­lines (:a;N;$!ba;s/\n) and replaces the new­lines with a |. This string that is used later on by egrep as a fil­ter (e.g. egrep -v "foo.txt|bar.txt|montana.txt).

  XGREP=`ls $VOICEDIR/*.txt | \
         rev | cut -d "/" -f 1 | rev | \
         sed ':a;N;$!ba;s/\n/|/g'`

For down­load­ing new voice files from the server I use wget. Because direc­tory list­ing is dis­abled on the lgm server we use a php file that lists all txt files in the voice direc­tory. I down­load this list (wget -O $LIST $REMOTELIST) to use it in the next step as input file for wget (wget -r -np -nH --no-directories -N -S -i $LIST).

# -------------------------------------------------------------------------------------- #
# UPDATE QUESTIONS & ANSWERS
# -------------------------------------------------------------------------------------- #
 
REMOTEDIR=http://www.forkable.eu/generators/r+w/i/free/voice/ LOCALEDIR=$VOICEDIR
 
cd $LOCALEDIR
 
LIST=voices.list wget -O $LIST $REMOTELIST
 
wget -r -np -nH --no-directories -N -S -i $LIST
 
cd -
 
rm $LOCALEDIR/$LIST

After down­load­ing I can cal­cu­late the num­ber of remote voice files (which are now local): VNUMREMOTE=`ls $VOICEDIR/*.txt | wc -l`. By fil­ter­ing out all voice files which have been there before the syn­chro­ni­sa­tion (ls -t o/free/voice/*.txt | rev | cut -d "/" -f 1 | rev | egrep -v "$XGREP") I get a list of all new voice files, which are added to the pre­vi­ously started list. I use this com­bi­na­tion of old and new voice files, because I decided to gen­er­ate also posters from already exist­ing voice files on each syn­chro­ni­sa­tion run (NUM2GENERATE=`expr $VNUMREMOTE - $VNUMLOCALE + 1`).

# -------------------------------------------------------------------------------------- #
 
VNUMREMOTE=`ls $VOICEDIR/*.txt | wc -l`
 
ls -t o/free/voice/*.txt | rev | cut -d "/" -f 1 | rev | \ egrep -v "$XGREP" >> q+a.list
 
# -------------------------------------------------------------------------------------- #
 
NUM2GENERATE=`expr $VNUMREMOTE - $VNUMLOCALE + 1`
 
if [ $VNUMREMOTE -gt $VNUMLOCALE ] then # -------------------------------------------------------------------------------------- #
 
# -------------------------------------------------------------------------------------- # # CREATE NEW POSTERS # # -------------------------------------------------------------------------------------- #
 
CNT=1 ; while [ $CNT -le $NUM2GENERATE ]; do
 
SELECTID=`tac q+a.list | \ rev | cut -d "_" -f 2 | cut -d "/" -f 1 | rev | \ awk ' !x[$0]++' | head -n $CNT | tail -1` SELECTQ=`ls -t i/free/voice/*_Q.txt | grep $SELECTID | head -n 1`
 
./do.sh $SELECTQ CNT=`expr $CNT + 1`
 
done

Finally I upload the gen­er­ated stuff on the web­server using ftp.

# -------------------------------------------------------------------------------------- #
# UPLOAD NEW FILES
# -------------------------------------------------------------------------------------- #
 
# GENERATE FTP COMMANDS ---------------------------------------------------------------- #
 
ACCESS=`cat ~/.forkable/ftp.input`
 
echo $ACCESS > ftp.tmp
 
for PDF in `ls -t ${PDFDIR}/*.pdf | head -n $NUM2UPLOAD` do echo "put $PDF "`basename $PDF` >> ftp.tmp done
 
for GIF in `ls -t ${PDFDIR}/*.gif | head -n $NUM2UPLOAD` do echo "put $GIF "`basename $GIF` >> ftp.tmp done
 
echo "put $ALLHTML "`basename $ALLHTML` >> ftp.tmp echo "bye" >> ftp.tmp
 
mv ftp.tmp ftp.input
 
# UPLOAD VIA FTP ----------------------------------------------------------------------- #
 
ftp -n forkable.eu < ftp.input rm ftp.input
 
# -------------------------------------------------------------------------------------- #
 
else echo "-> NOTHING NEW" fi rm q+a.list
 
exit 0;

The voice files are saved and ver­sion­ized in a git repos­i­tory, because some spelling cor­rec­tion and spam dele­tion had to be done. Thanks to Ale Rimoldi for tak­ing care for the setup on the lgm server and the github syn­chro­niza­tion.