source: trunk/adm/linkchecker.sh @ 74

Last change on this file since 74 was 67, checked in by pinsard, 15 years ago

project homogenization

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