#!/bin/ksh

# TODO:
#       - make the script runable from any directory (GOPHERBLOG variable?)
#       - if no text file, fetch it from stdin
#       - check for 1st, 2nd and 3rd of the month and adjust the date prefix
#       - add a full interactive mode?

if [[ -z $1 ]] || [[ -z $2 ]]; then
        echo "USAGE: mkgopherentry title textfile"
        exit 1
fi

intro=`cat $2 | awk 'BEGIN { N = 0} /^$/ {N = 1} {if (N == 0) print;}'`

# Create an entry.
cat >>gophermap.tmp<<EOF
--$1--
    `date "+%d/%m/%Y"`
$intro
0Sigue...	$2

EOF

# Add the old ones to its tail.
if [[ -f gophermap ]]; then
        cat gophermap >> gophermap.tmp
fi
mv gophermap.tmp gophermap
chmod 644 gophermap $2
