[64] | 1 | #! /bin/sh |
---|
| 2 | #+ |
---|
| 3 | # |
---|
[83] | 4 | # .. _linkchecker.sh: |
---|
[64] | 5 | # |
---|
[83] | 6 | # ============== |
---|
| 7 | # linkchecker.sh |
---|
| 8 | # ============== |
---|
[64] | 9 | # |
---|
[83] | 10 | # --------------------------------------- |
---|
| 11 | # check links of a given directory or url |
---|
| 12 | # --------------------------------------- |
---|
| 13 | # |
---|
[64] | 14 | # SYNOPSIS |
---|
| 15 | # ======== |
---|
| 16 | # |
---|
| 17 | # :: |
---|
| 18 | # |
---|
| 19 | # $ linkchecker.sh -d dircheck -u url |
---|
| 20 | # |
---|
| 21 | # |
---|
| 22 | # DESCRIPTION |
---|
| 23 | # =========== |
---|
| 24 | # |
---|
| 25 | # check links of a given directory or url |
---|
| 26 | # cf. install.sh |
---|
| 27 | # |
---|
| 28 | # |
---|
| 29 | # EXAMPLES |
---|
| 30 | # ======== |
---|
| 31 | # |
---|
| 32 | # |
---|
| 33 | # EVOLUTIONS |
---|
| 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 possibilite de faire une carte du site avec graphviz |
---|
| 42 | # |
---|
| 43 | # exemple syntaxe |
---|
| 44 | # |
---|
| 45 | # :: |
---|
| 46 | # |
---|
| 47 | # $ linkchecker -odot -v http://www.lodyc.jussieu.fr/NEMO/general/biblio_new/ | dot -Tps > sitemap.ps |
---|
| 48 | # |
---|
| 49 | # |
---|
| 50 | # remove "set -u" because I don't know how to test if there is at least |
---|
| 51 | # one directory AND one url to be checked without this option |
---|
| 52 | # |
---|
| 53 | # !! ++ must be restore ASAP |
---|
| 54 | # |
---|
| 55 | # $Id: linkchecker.sh 53 2009-04-29 10:19:50Z pinsard $ |
---|
| 56 | # |
---|
| 57 | # - fplod 2008-12-19T10:05:59Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 58 | # |
---|
| 59 | # * bug fix for relative directory (thanks to Sébastien Masson) |
---|
| 60 | # |
---|
| 61 | # - fplod 2008-09-16T15:28:34Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 62 | # |
---|
| 63 | # * comment in ReStructured Text |
---|
| 64 | # |
---|
| 65 | # - fplod 2007-10-12T07:32:08Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 66 | # |
---|
| 67 | # * add -u pour url |
---|
| 68 | # * add multiple -d and suppression of interactivity |
---|
| 69 | # * replace -w by -d (more generic) |
---|
| 70 | # * use rather checklink than linkchecker because the first one exist either |
---|
| 71 | # on Mac and Unix, and because the second one exists only on Mac and |
---|
| 72 | # does'nt seem to detect every problem |
---|
| 73 | # |
---|
| 74 | # - fplod 2007-10-11T15:31:25Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 75 | # |
---|
| 76 | # * parametrization |
---|
| 77 | # * merge with checklink.sh ++ choisir entre les deux |
---|
| 78 | # |
---|
| 79 | # - fplod 2007-06-19T09:26:04Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 80 | # |
---|
| 81 | # * création |
---|
| 82 | # |
---|
| 83 | #- |
---|
| 84 | system=$(uname) |
---|
| 85 | case "${system}" in |
---|
[77] | 86 | AIX|IRIX64) |
---|
| 87 | echo " www : no specific posix checking" |
---|
| 88 | ;; |
---|
| 89 | *) |
---|
| 90 | set -o posix |
---|
| 91 | ;; |
---|
[64] | 92 | esac |
---|
| 93 | command=$(basename ${0}) |
---|
[67] | 94 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
[64] | 95 | log=/tmp/$(basename ${command} .sh).log.${log_date} |
---|
| 96 | # |
---|
| 97 | usage=" Usage : ${command} -d dircheck -u url" |
---|
| 98 | # |
---|
| 99 | minargcount=2 |
---|
| 100 | #echo " narg ${#}" |
---|
| 101 | if [ ${#} -lt ${minargcount} ] |
---|
| 102 | then |
---|
[77] | 103 | echo "eee : not enought arguments" |
---|
| 104 | echo "${usage}" |
---|
| 105 | exit 1 |
---|
[64] | 106 | fi |
---|
| 107 | # |
---|
| 108 | idircheck=0 |
---|
| 109 | iurl=0 |
---|
[81] | 110 | # |
---|
| 111 | set +u |
---|
[64] | 112 | while [ ! -z "${1}" ] |
---|
| 113 | do |
---|
[77] | 114 | case ${1} in |
---|
| 115 | -d) |
---|
| 116 | idircheck=$(( ${idircheck} + 1 )) |
---|
| 117 | dircheck[${idircheck}]=$(cd ${2};pwd) |
---|
| 118 | shift |
---|
| 119 | ;; |
---|
| 120 | -u) |
---|
| 121 | iurlcheck=$(( ${iurlcheck} + 1 )) |
---|
| 122 | urlcheck[${iurlcheck}]=${2} |
---|
| 123 | shift |
---|
| 124 | ;; |
---|
| 125 | esac |
---|
[78] | 126 | # next flag |
---|
| 127 | shift |
---|
[64] | 128 | done |
---|
| 129 | # |
---|
| 130 | # +++ remove temporarily |
---|
| 131 | # +++ set -u |
---|
| 132 | # |
---|
| 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 |
---|
[77] | 146 | echo "${command} : eee : ${commandcheck} unavailable" |
---|
| 147 | exit 1 |
---|
[64] | 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 | exit |
---|