[55] | 1 | #! /bin/sh |
---|
[75] | 2 | #+ |
---|
[80] | 3 | # |
---|
[109] | 4 | # .. program:: linkchecker.sh |
---|
[103] | 5 | # |
---|
[95] | 6 | # ============== |
---|
| 7 | # linkchecker.sh |
---|
| 8 | # ============== |
---|
[2] | 9 | # |
---|
[95] | 10 | # --------------------------------------- |
---|
| 11 | # check links of a given directory or url |
---|
| 12 | # --------------------------------------- |
---|
[75] | 13 | # |
---|
[93] | 14 | # SYNOPSIS |
---|
[75] | 15 | # ======== |
---|
| 16 | # |
---|
| 17 | # :: |
---|
| 18 | # |
---|
| 19 | # $ linkchecker.sh -d dircheck -u url |
---|
| 20 | # |
---|
| 21 | # |
---|
| 22 | # DESCRIPTION |
---|
| 23 | # =========== |
---|
| 24 | # |
---|
[108] | 25 | # .. option:: -d <dircheck> |
---|
| 26 | # .. option:: -u <url> |
---|
| 27 | # |
---|
[50] | 28 | # check links of a given directory or url |
---|
[2] | 29 | # cf. install.sh |
---|
| 30 | # |
---|
[75] | 31 | # EXAMPLES |
---|
| 32 | # ======== |
---|
| 33 | # |
---|
[95] | 34 | # TODO |
---|
| 35 | # ==== |
---|
[75] | 36 | # |
---|
[26] | 37 | # ++ linkchecker ne voit pas les erreurs !! |
---|
[75] | 38 | # |
---|
[26] | 39 | # ++ dirpublish forme fplod@cerbere.locean-ipsl.upmc.fr:./WWW/ par example |
---|
| 40 | # donc pas http |
---|
[2] | 41 | # |
---|
[83] | 42 | # + ajouter la possibilite de faire une carte du site avec graphviz |
---|
[75] | 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 | # |
---|
[27] | 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 |
---|
[75] | 53 | # |
---|
[27] | 54 | # !! ++ must be restore ASAP |
---|
[75] | 55 | # |
---|
[95] | 56 | # EVOLUTIONS |
---|
| 57 | # ========== |
---|
| 58 | # |
---|
[33] | 59 | # $Id$ |
---|
[26] | 60 | # |
---|
[83] | 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 | # |
---|
[75] | 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 |
---|
[80] | 86 | # |
---|
[75] | 87 | #- |
---|
| 88 | system=$(uname) |
---|
| 89 | case "${system}" in |
---|
[100] | 90 | AIX|IRIX64) |
---|
| 91 | echo " www : no specific posix checking" |
---|
| 92 | ;; |
---|
| 93 | *) |
---|
| 94 | set -o posix |
---|
| 95 | ;; |
---|
[75] | 96 | esac |
---|
[100] | 97 | unset system |
---|
[80] | 98 | command=$(basename ${0}) |
---|
[93] | 99 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
[80] | 100 | log=/tmp/$(basename ${command} .sh).log.${log_date} |
---|
[2] | 101 | # |
---|
[26] | 102 | usage=" Usage : ${command} -d dircheck -u url" |
---|
[2] | 103 | # |
---|
[26] | 104 | minargcount=2 |
---|
| 105 | #echo " narg ${#}" |
---|
| 106 | if [ ${#} -lt ${minargcount} ] |
---|
[2] | 107 | then |
---|
[100] | 108 | echo "eee : not enought arguments" |
---|
| 109 | echo "${usage}" |
---|
| 110 | exit 1 |
---|
[2] | 111 | fi |
---|
[100] | 112 | unset minargcount |
---|
[2] | 113 | # |
---|
[26] | 114 | idircheck=0 |
---|
| 115 | iurl=0 |
---|
[102] | 116 | set +u |
---|
[26] | 117 | while [ ! -z "${1}" ] |
---|
| 118 | do |
---|
[100] | 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 |
---|
[101] | 131 | # next flag |
---|
| 132 | shift |
---|
[26] | 133 | done |
---|
[2] | 134 | # |
---|
[55] | 135 | # +++ remove temporarily |
---|
[27] | 136 | # +++ set -u |
---|
[2] | 137 | # |
---|
[26] | 138 | # ++ check directories or URL |
---|
| 139 | # |
---|
| 140 | # choose the command to be used |
---|
| 141 | # |
---|
| 142 | commandcheck=checklink |
---|
| 143 | # |
---|
| 144 | if [ ${commandcheck} = "linkchecker" ] |
---|
| 145 | then |
---|
| 146 | # test if linkchecker is available |
---|
| 147 | type ${commandcheck} 1> /dev/null 2>&1 |
---|
| 148 | status=${?} |
---|
| 149 | if [ ${status} -ne 0 ] |
---|
| 150 | then |
---|
[101] | 151 | echo "${command} : eee : ${commandcheck} unavailable" |
---|
| 152 | exit 1 |
---|
[26] | 153 | fi |
---|
| 154 | optcheck="--anchors --recursion-level=-1" |
---|
| 155 | fi |
---|
| 156 | # |
---|
| 157 | if [ ${commandcheck} = "checklink" ] |
---|
| 158 | then |
---|
| 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" |
---|
| 169 | fi |
---|
| 170 | # |
---|
| 171 | # loop on directories to be checked |
---|
[27] | 172 | dirchecksize=${#dircheck[@]} # ++ pb set -u |
---|
| 173 | if [ ${dirchecksize} -gt 0 ] |
---|
| 174 | then |
---|
| 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 |
---|
| 184 | fi |
---|
[26] | 185 | # |
---|
[27] | 186 | # loop on urls to be checked |
---|
| 187 | urlchecksize=${#urlcheck[@]} # ++ pb set -u |
---|
| 188 | if [ ${urlchecksize} -gt 0 ] |
---|
| 189 | then |
---|
| 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 |
---|
| 200 | fi |
---|
[26] | 201 | # |
---|
| 202 | echo "iii : log in ${log}" |
---|
| 203 | # end |
---|
[100] | 204 | unset log |
---|
[2] | 205 | exit |
---|