source: trunk/linkchecker.sh @ 105

Last change on this file since 105 was 103, checked in by pinsard, 14 years ago

modif. of headers for manuals hyperlinks improvements

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