#!/bin/bash # This shell script copies the final LaTeX document locally, processes it into HTML, then reuploads it to the server. # It won't be useful to anyone else verbatim, but might give you some ideas about how things fit together, and how to write a shell script. # get_ip: checks if the server is on the local network or remote network. get_ip() { LANDOMAIN=intra.bostoncoop.net WANDOMAIN=extra.bostoncoop.net NOT_ONLINE_ERR=1 if ( /sbin/ifconfig | grep 192.168 > /dev/null ) then HOST=$LANDOMAIN elif ( /sbin/ifconfig | grep eth0 > /dev/null ) then HOST=$WANDOMAIN else echo Not online! exit $NOT_ONLINE_ERR fi } # fetch_files: get tex file from server (along with other versions, rtf and pdf, for good measure) fetch_files() { cd ~/sandbox/final/full scp $HOST:/home/wiki/lcd/pub/final.\* . } # process_files: reformat tex file into HTML # 1. remove DOS-style CR # 2. Remove inline PDF figures, replace with code that will later become hypertext references # 3. process through latex2html # 4. Add in references to stylesheets and background images # 5. Replace PDF figure with hypertext references # 6. Copy new files over old process_files() { cat final.tex | sed -e "s/ /|/g" -e 's/.*emancipation_chart.*/EMCHART/' -e 's/.*mature_minor.*/MMCHART/' | tr "|" "\n" > tempfinal mv tempfinal final.tex latex2html -address "LCD Law Office #2" -index "../index.html" -no_subdir -no_footnode final.tex mkdir temp cd temp for x in ../*.html; do cat $x | sed -e 's/^Click here for the chart comparison of emancipation laws across the 50 states.<\/A>/g' -e 's/.*MMCHART.*/Click here for the chart comparison of mature minor laws across the 50 states.<\/A>/g' | grep -v "^=$\|^\[0\]$" > `basename $x`; done; mv * .. cd .. rm -r temp cd ~/sandbox } # put_files: use rsync to upload files back to server put_files() { rsync -Caz final $HOST:/home/wiki/lcd } # main script get_ip fetch_files process_files put_files exit 0