source: trunk/linkchecker.sh @ 140

Last change on this file since 140 was 116, checked in by pinsard, 13 years ago

Consolidation of shell scripts

  • 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
116while [ ${#} -gt 0 ]
117do
118   case ${1} in
119      -d)
120         idircheck=$(( ${idircheck} + 1 ))
121         dircheck[${idircheck}]=$(cd ${2};pwd)
122         shift
123      ;;
124      -u)
125         iurlcheck=$(( ${iurlcheck} + 1 ))
126         urlcheck[${iurlcheck}]=${2}
127         shift
128      ;;
129   esac
130   # next flag
131   shift
132done
133#
134# +++ remove temporarily
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.