#!/bin/bash # Copyright (c) Rik Snel 2007, license GPL v3 or any later version PROGNAME=`basename $0` || exit 1 QUIET=0 DEBUG=0 PUBLISH=0 function debug { if [ "$DEBUG" = "1" ]; then echo "${PROGNAME}:debug:$1" 1>&2; fi } function warning { if [ "$QUIET" = "0" ]; then echo "${PROGNAME}:warning:$1" 1>&2; fi } function usage { echo "Usage: ${PROGNAME} DEVICE" exit } while [ "$1" != "" ]; do case $1 in -D | --debug ) shift DEBUG=1 ;; -q | --quiet ) shift QUIET=1 ;; -h | --help ) shift usage ;; -p | --publish ) shift PUBLISH=1 ;; * ) break; ;; esac done TMPDIR= function cleanup { debug "cleanup called, arg=$1" trap - EXIT HUP INT TERM ERR #if [ "$TMPDIR" != "" -a -d "$TMPDIR" ]; then #debug "removing $TMPDIR" #rm -f -r $TMPDIR #fi exit $1 } function fatal { echo "${PROGNAME}:${1:-"unknown error"}" 1>&2 cleanup 1 } function sig_handler_HUPINTTERM { fatal "cought HUP, INT or TERM signal, exiting" } function sig_handler_ERR { cleanup 1 } function sig_handler_EXIT { cleanup 0 } trap sig_handler_HUPINTTERM HUP INT TERM trap sig_handler_ERR ERR trap sig_handler_EXIT EXIT TMPDIR=`mktemp -d -p /tmp .$PROGNAME.XXXXXX` BASE=${1%.} BASE=${BASE%.tex} if [ "$BASE" = "" ]; then fatal "no argument given" fi if [ ! -e $BASE.tex ]; then fatal "$BASE.tex does not exist" fi if [ ! -f $BASE.tex ]; then fatal "$BASE.tex is not a regular file" fi DIR=`dirname $BASE.tex` if [ "$DIR" = "." ]; then DIR=`pwd` fi COMPONENTS=( `echo $DIR | tr '/' '\n' | tail -n 5 | tac` ) if [ "${COMPONENTS[0]}" = "toetsen" ]; then NAME=$BASE elif [ "${COMPONENTS[1]}" = "toetsen" ]; then NAME=${COMPONENTS[0]}.$BASE elif [ "${COMPONENTS[2]}" = "toetsen" ]; then NAME=${COMPONENTS[1]}.${COMPONENTS[0]}-$BASE elif [ "${COMPONENTS[3]}" = "toetsen" ]; then NAME=${COMPONENTS[2]}.${COMPONENTS[1]}-${COMPONENTS[0]}.$BASE elif [ "${COMPONENTS[4]}" = "toetsen" ]; then NAME=${COMPONENTS[3]}.${COMPONENTS[2]}-${COMPONENTS[1]}.${COMPONENTS[0]}.$BASE else fatal "base directory not toetsen or too deep??!?!!?" fi echo $NAME cp $BASE.tex $TMPDIR/$NAME.tex if [ -f $BASE.antw.pdf ]; then cp $BASE.antw.pdf $HOME/tmp/$NAME.antw.pdf fi if [ `ls $BASE.*.eps 2> /dev/null | wc -l` -gt 0 ]; then cp -f $BASE.*.eps $TMPDIR/ fi cd $TMPDIR etex $NAME.tex etex $NAME.tex etex $NAME.tex dvips -t a4 -o $NAME.ps $NAME.dvi ps2pdf -dALLOWPSTRANSPARENCY $NAME.ps UNAME=snelr URL=https://snel.it:443/tb/ovc/makers/$UNAME cp $NAME.pdf $HOME/tmp cp $NAME.tex $HOME/tmp unix2dos $HOME/tmp/$NAME.tex if [ "$PUBLISH" = "1" ]; then curl --insecure -4 -u $UNAME -T $NAME.pdf $URL/$NAME.pdf -T $NAME.tex $URL/$NAME.source.tex else if [ "$DISPLAY" != "" ]; then zathura $NAME.pdf else curl -4 --insecure -u $UNAME -T $NAME.pdf $URL/draft.pdf fi fi