source: trunk/linkchecker.sh @ 110

Last change on this file since 110 was 109, checked in by pinsard, 14 years ago

usage of program directive

  • Property svn:keywords set to Id
File size: 4.3 KB
RevLine 
[55]1#! /bin/sh
[75]2#+
[80]3#
[109]4# .. program:: linkchecker.sh
[103]5#
[95]6# ==============
7# linkchecker.sh
8# ==============
[2]9#
[95]10# ---------------------------------------
11# check links of a given directory or url
12# ---------------------------------------
[75]13#
[93]14# SYNOPSIS
[75]15# ========
16#
17# ::
18#
19#  $ linkchecker.sh -d dircheck -u url
20#
21#
22# DESCRIPTION
23# ===========
24#
[108]25# .. option:: -d <dircheck>
26# .. option:: -u <url>
27#
[50]28# check links of a given directory or url
[2]29# cf. install.sh
30#
[75]31# EXAMPLES
32# ========
33#
[95]34# TODO
35# ====
[75]36#
[26]37# ++ linkchecker ne voit pas les erreurs !!
[75]38#
[26]39# ++ dirpublish forme fplod@cerbere.locean-ipsl.upmc.fr:./WWW/ par example
40# donc pas http
[2]41#
[83]42# + ajouter la possibilite de faire une carte du site avec graphviz
[75]43#
44# exemple syntaxe
45#
46# ::
47#
48#  $ linkchecker -odot -v http://www.lodyc.jussieu.fr/NEMO/general/biblio_new/   | dot -Tps > sitemap.ps
49#
50#
[27]51# remove "set -u" because I don't know how to test if there is at least
52# one directory AND one url to be checked without this option
[75]53#
[27]54# !! ++ must be restore ASAP
[75]55#
[95]56# EVOLUTIONS
57# ==========
58#
[33]59# $Id$
[26]60#
[83]61# - fplod 2008-12-19T10:05:59Z aedon.locean-ipsl.upmc.fr (Darwin)
62#
63#   * bug fix for relative directory (thanks to Sébastien Masson)
64#
[75]65# - fplod 2008-09-16T15:28:34Z aedon.locean-ipsl.upmc.fr (Darwin)
66#
67#   * comment in ReStructured Text
68#
69# - fplod 2007-10-12T07:32:08Z aedon.locean-ipsl.upmc.fr (Darwin)
70#
71#   * add -u pour url
72#   * add multiple -d and suppression of interactivity
73#   * replace -w by -d (more generic)
74#   * use rather checklink than linkchecker because the first one exist either
75#     on Mac and Unix, and because the second one exists only on Mac and
76#     does'nt seem to detect every problem
77#
78# - fplod 2007-10-11T15:31:25Z aedon.locean-ipsl.upmc.fr (Darwin)
79#
80#   * parametrization
81#   * merge with checklink.sh ++ choisir entre les deux
82#
83# - fplod 2007-06-19T09:26:04Z aedon.locean-ipsl.upmc.fr (Darwin)
84#
85#   * création
[80]86#
[75]87#-
88system=$(uname)
89case "${system}" in
[100]90   AIX|IRIX64)
91      echo " www : no specific posix checking"
92   ;;
93   *)
94      set -o posix
95   ;;
[75]96esac
[100]97unset system
[80]98command=$(basename ${0})
[93]99log_date=$(date -u +"%Y%m%dT%H%M%SZ")
[80]100log=/tmp/$(basename ${command} .sh).log.${log_date}
[2]101#
[26]102usage=" Usage : ${command} -d dircheck -u url"
[2]103#
[26]104minargcount=2
105#echo " narg ${#}"
106if [ ${#} -lt ${minargcount} ]
[2]107then
[100]108   echo "eee : not enought arguments"
109   echo "${usage}"
110   exit 1
[2]111fi
[100]112unset minargcount
[2]113#
[26]114idircheck=0
115iurl=0
[102]116set +u
[26]117while [ ! -z "${1}" ]
118do
[100]119   case ${1} in
120      -d)
121         idircheck=$(( ${idircheck} + 1 ))
122         dircheck[${idircheck}]=$(cd ${2};pwd)
123         shift
124      ;;
125      -u)
126         iurlcheck=$(( ${iurlcheck} + 1 ))
127         urlcheck[${iurlcheck}]=${2}
128         shift
129      ;;
130   esac
[101]131   # next flag
132   shift
[26]133done
[2]134#
[55]135# +++ remove temporarily
[27]136# +++ set -u
[2]137#
[26]138# ++ check directories or URL
139#
140# choose the command to be used
141#
142commandcheck=checklink
143#
144if [ ${commandcheck} = "linkchecker" ]
145then
146   # test if linkchecker is available
147   type ${commandcheck} 1> /dev/null 2>&1
148   status=${?}
149   if [ ${status} -ne 0 ]
150   then
[101]151      echo "${command} : eee : ${commandcheck} unavailable"
152      exit 1
[26]153   fi
154   optcheck="--anchors --recursion-level=-1"
155fi
156#
157if [ ${commandcheck} = "checklink" ]
158then
159   # test if checklink is available
160   type ${commandcheck} 1> /dev/null 2>&1
161   status=${?}
162   if [ ${status} -ne 0 ]
163   then
164      echo "${command} : eee : ${commandcheck} unavailable"
165      exit 1
166   fi
167#
168   optcheck="--summary --recursive"
169fi
170#
171# loop on directories to be checked
[27]172dirchecksize=${#dircheck[@]} # ++ pb set -u
173if [ ${dirchecksize} -gt 0 ]
174then
175   idircheck=1
176   while [ ${idircheck} -le ${dirchecksize} ]
177   do
178      echo "iii : beginning of check of ${dircheck[${idircheck}]}" 1>>${log}
179      fverif="file://"${dircheck[${idircheck}]}
180      echo "iii : check of ${fverif}"
181      ${commandcheck} ${optcheck} ${fverif} 1>>${log} 2>&1
182      idircheck=$(( ${idircheck} + 1 ))
183   done
184fi
[26]185#
[27]186# loop on urls to be checked
187urlchecksize=${#urlcheck[@]} # ++ pb set -u
188if [ ${urlchecksize} -gt 0 ]
189then
190   iurlcheck=1
191   while [ ${iurlcheck} -le ${urlchecksize} ]
192   do
193      echo "iii : beginning of check of ${urlcheck[${iurlcheck}]}" 1>>${log}
194      # ++ test si urlcheck commence par http ou pas
195      fverif=${urlcheck[${iurlcheck}]}
196      echo "iii : check of ${fverif}"
197      ${commandcheck} ${optcheck} ${fverif} 1>>${log} 2>&1
198      iurlcheck=$(( ${iurlcheck} + 1 ))
199   done
200fi
[26]201#
202echo "iii : log in ${log}"
203# end
[100]204unset log
[2]205exit
Note: See TracBrowser for help on using the repository browser.