source: trunk/linkchecker.sh

Last change on this file was 353, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • Property svn:keywords set to Id
File size: 4.4 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# .. code-block:: sh
18#
19#    linkchecker.sh -d dircheck -u url
20#
21# DESCRIPTION
22# ===========
23#
24# .. option:: -d <dircheck>
25# .. option:: -u <url>
26#
27# check links of a given directory or url
28# cf. install.sh
29#
30# EXAMPLES
31# ========
32#
33# TODO
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 possibilité de faire une carte du site avec graphviz
42#
43# exemple syntaxe
44#
45# .. code-block:: sh
46#
47#    linkchecker -odot -v http://www.lodyc.jussieu.fr/NEMO/general/biblio_new/   | dot -Tps > sitemap.ps
48#
49# remove "set -u" because I don't know how to test if there is at least
50# one directory AND one url to be checked without this option
51#
52# !! ++ must be restore ASAP
53#
54# EVOLUTIONS
55# ==========
56#
57# $Id$
58#
59# - fplod 2008-12-19T10:05:59Z aedon.locean-ipsl.upmc.fr (Darwin)
60#
61#   * bug fix for relative directory (thanks to Sébastien Masson)
62#
63# - fplod 2008-09-16T15:28:34Z aedon.locean-ipsl.upmc.fr (Darwin)
64#
65#   * comment in reStructuredText
66#
67# - fplod 2007-10-12T07:32:08Z aedon.locean-ipsl.upmc.fr (Darwin)
68#
69#   * add -u pour url
70#   * add multiple -d and suppression of interactivity
71#   * replace -w by -d (more generic)
72#   * use rather checklink than linkchecker because the first one exist either
73#     on Mac and Unix, and because the second one exists only on Mac and
74#     does'nt seem to detect every problem
75#
76# - fplod 2007-10-11T15:31:25Z aedon.locean-ipsl.upmc.fr (Darwin)
77#
78#   * parametrization
79#   * merge with checklink.sh ++ choisir entre les deux
80#
81# - fplod 2007-06-19T09:26:04Z aedon.locean-ipsl.upmc.fr (Darwin)
82#
83#   * création
84#
85#-
86system=$(uname)
87case "${system}" in
88    AIX|IRIX64)
89        echo " www : no specific posix checking"
90    ;;
91    *)
92        set -o posix
93    ;;
94esac
95unset system
96command=$(basename ${0})
97log_date=$(date -u +"%Y%m%dT%H%M%SZ")
98log=/tmp/$(basename ${command} .sh).log.${log_date}
99#
100usage=" Usage : ${command} -d dircheck -u url"
101#
102minargcount=2
103#echo " narg ${#}"
104if [ ${#} -lt ${minargcount} ]
105then
106    echo "eee : not enough arguments"
107    echo "${usage}"
108    exit 1
109fi
110unset minargcount
111#
112idircheck=0
113iurl=0
114while [ ${#} -gt 0 ]
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# ++ 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
199unset log
200exit
Note: See TracBrowser for help on using the repository browser.