#!/bin/bash

WIKID=/home/tomcato/www/solfege/nysolfege/wiki.d
UPLOADD=/home/tomcato/www/solfege/nysolfege/uploads/SolfegeDocsLily
TMP=xx
mkdir -p $TMP
scp tomcato@solfege.org:$WIKID/SolfegeDocsLily.* $TMP
rm $TMP/SolfegeDocsLily.RecentChanges
rm $TMP/SolfegeDocsLily.SolfegeDocsLily
python - <<EOF
import os
for n in os.listdir("$TMP"):
    print n
    os.system("wget http://www.solfege.org/%s?action=source -O $TMP/%s.ly" % (n, n))
EOF
(cd $TMP && lilypond --png --preview *.ly)
(cd $TMP && lilypond -m *.ly)
rm $TMP/*page1.png
python - <<EOF
import glob, os
for n in glob.glob("$TMP/*preview.png"):
    s = os.path.basename(n)[16:]
    s = "%s.png" % s[:-12]
    os.rename(n, os.path.join("$TMP", s))
for n in glob.glob("$TMP/*.midi"):
    s = os.path.basename(n)[16:]
    os.rename(n, os.path.join("$TMP", s))
EOF
exit
(cd $TMP && scp *.png tomcato@solfege.org:$UPLOADD)
