#!/bin/bash -e
#
# ./publish [-f]

. ../private/vars.sh
cd ~/Network/Abbey/

errs=0

if ! grep -HnEr --exclude facts $WILD_NET
then errs=$(( $errs + 1 )); fi
if ! grep -HnEr --exclude facts $PUBLIC_VPN_NET
then errs=$(( $errs + 1 )); fi
if ! grep -HnEr --exclude facts $CAMPUS_VPN_NET
then errs=$(( $errs + 1 )); fi

if ! grep -HnE '^[#*].*(TODO|\?\?\?)' Institute/README.org
then errs=$(( $errs + 1 )); fi
if ! grep -HnE '^[*#].*(TODO|\?\?\?)' README.org
then errs=$(( $errs + 1 )); fi

if [ $errs != 0 ]; then echo ""; fi

function silence {
  grep -vE "^($PUNT)\$"
}
PUNT="Indentation variables are now local\\."
PUNT="$PUNT|(Setting up indent|Indentation setup) for shell type bash"

EARGS="--no-init-file --batch --script publish.el"

if [ "$#" == 1 -a "$1" == "-f" ]
then
    emacs $EARGS -f pub-forced |& silence
elif [ "$#" == 0 ]
then
    emacs $EARGS -f pub |& silence
else
    echo "usage: ./publish [-f]"
    exit 1
fi
