#!/bin/sh

# script by Eric Stein http://cons.truct.org

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details. 

TXT=$1
PDF=$2

H=markdown
PS=html2ps
PD=ps2pdf

if [ ! -f "$TXT" ]
then
	exit "$TXT does not exist"
	exit 1
fi

touch "$PDF"

if [ ! -f "$PDF" ]
then
	exit "$PDF could not be created"
	exit 1
fi

which $H>/dev/null
if [ $? -gt 0 ]
then
	echo "$H is not a program."
	exit 1
fi
which $PD>/dev/null
if [ $? -gt 0 ]
then
	echo "$PD is not a program."
	exit 1
fi
which $PS>/dev/null
if [ $? -gt 0 ]
then
	echo "$PS is not a program."
	exit 1
fi

$H "$TXT"|$PS|$PD - "$PDF"
if [ $? -gt 0 ]
then
	echo "Failed to process."
	exit 1
fi
