#! /usr/bin/env bash

# http://fabien.benetou.fr/Wiki/ToDo#Maintenance
# TODO
#	add incremental option to use with batch
#	generalize for other URLs
#	RSS output to better handle notification with required actions

if [ $# -lt 1 ]
then
  echo "Check page per page against dead links for PmWiki"
  echo "usage: $0 PmWiki_path"
  exit
fi
PATH=$1
NOW_EPOCH=$(date +"%s")
URL=http://fabien.benetou.fr/

# get the last link checked
# if last or none start from link 1

for PAGE in $(ls $1/wiki.d/* | grep -v PmWiki. | grep -v Site | sed "s/.*wiki\.d\///" | tr "." "/")
do
 checklink -s $URL/$PAGE > $PATH/pub/checking/$(echo $PAGE|tr "/" ".").check
 # using the Perl W3C-checklink 
 ## should fail if not installed and suggest the CPAN command
done;