source: trunk/adm/linkchecker.sh @ 83

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

no more direct usage of docutils

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