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
Line 
1#! /bin/sh
2#+
3#
4# .. program:: 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# .. option:: -d <dircheck>
26# .. option:: -u <url>
27#
28# check links of a given directory or url
29# cf. install.sh
30#
31# EXAMPLES
32# ========
33#
34# TODO
35# ====
36#
37# ++ linkchecker ne voit pas les erreurs !!
38#
39# ++ dirpublish forme fplod@cerbere.locean-ipsl.upmc.fr:./WWW/ par example
40# donc pas http
41#
42# + ajouter la possibilite de faire une carte du site avec graphviz
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#
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
53#
54# !! ++ must be restore ASAP
55#
56# EVOLUTIONS
57# ==========
58#
59# $Id$
60#
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#
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
86#
87#-
88system=$(uname)
89case "${system}" in
90   AIX|IRIX64)
91      echo " www : no specific posix checking"
92   ;;
93   *)
94      set -o posix
95   ;;
96esac
97unset system
98command=$(basename ${0})
99log_date=$(date -u +"%Y%m%dT%H%M%SZ")
100log=/tmp/$(basename ${command} .sh).log.${log_date}
101#
102usage=" Usage : ${command} -d dircheck -u url"
103#
104minargcount=2
105#echo " narg ${#}"
106if [ ${#} -lt ${minargcount} ]
107then
108   echo "eee : not enought arguments"
109   echo "${usage}"
110   exit 1
111fi
112unset minargcount
113#
114idircheck=0
115iurl=0
116set +u
117while [ ! -z "${1}" ]
118do
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
131   # next flag
132   shift
133done
134#
135# +++ remove temporarily
136# +++ set -u
137#
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
151      echo "${command} : eee : ${commandcheck} unavailable"
152      exit 1
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
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
185#
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
201#
202echo "iii : log in ${log}"
203# end
204unset log
205exit
Note: See TracBrowser for help on using the repository browser.