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 | #- |
---|
86 | system=$(uname) |
---|
87 | case "${system}" in |
---|
88 | AIX|IRIX64) |
---|
89 | echo " www : no specific posix checking" |
---|
90 | ;; |
---|
91 | *) |
---|
92 | set -o posix |
---|
93 | ;; |
---|
94 | esac |
---|
95 | unset system |
---|
96 | command=$(basename ${0}) |
---|
97 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
98 | log=/tmp/$(basename ${command} .sh).log.${log_date} |
---|
99 | # |
---|
100 | usage=" Usage : ${command} -d dircheck -u url" |
---|
101 | # |
---|
102 | minargcount=2 |
---|
103 | #echo " narg ${#}" |
---|
104 | if [ ${#} -lt ${minargcount} ] |
---|
105 | then |
---|
106 | echo "eee : not enough arguments" |
---|
107 | echo "${usage}" |
---|
108 | exit 1 |
---|
109 | fi |
---|
110 | unset minargcount |
---|
111 | # |
---|
112 | idircheck=0 |
---|
113 | iurl=0 |
---|
114 | while [ ${#} -gt 0 ] |
---|
115 | do |
---|
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 |
---|
130 | done |
---|
131 | # |
---|
132 | # +++ remove temporarily |
---|
133 | # ++ check directories or URL |
---|
134 | # |
---|
135 | # choose the command to be used |
---|
136 | # |
---|
137 | commandcheck=checklink |
---|
138 | # |
---|
139 | if [ ${commandcheck} = "linkchecker" ] |
---|
140 | then |
---|
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" |
---|
150 | fi |
---|
151 | # |
---|
152 | if [ ${commandcheck} = "checklink" ] |
---|
153 | then |
---|
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" |
---|
164 | fi |
---|
165 | # |
---|
166 | # loop on directories to be checked |
---|
167 | dirchecksize=${#dircheck[@]} # ++ pb set -u |
---|
168 | if [ ${dirchecksize} -gt 0 ] |
---|
169 | then |
---|
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 |
---|
179 | fi |
---|
180 | # |
---|
181 | # loop on urls to be checked |
---|
182 | urlchecksize=${#urlcheck[@]} # ++ pb set -u |
---|
183 | if [ ${urlchecksize} -gt 0 ] |
---|
184 | then |
---|
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 |
---|
195 | fi |
---|
196 | # |
---|
197 | echo "iii : log in ${log}" |
---|
198 | # end |
---|
199 | unset log |
---|
200 | exit |
---|