monochromatic

monochromatic blog: http://blog.z3bra.org
git clone git://z3bra.org/monochromatic
Log | Files | Refs

check.sh (1592B)


      1 #!/bin/bash
      2 
      3 uri=blog.z3bra.org
      4 charset=utf-8
      5 doctype=Inline
      6 profile=css3
      7 
      8 function w3c_valid () {
      9     if (curl -sI "$1" | grep -o 'Invalid' >/dev/null); then
     10         echo -e "[\033[1;31mFAIL\033[0m]"
     11         echo -e "  Errors : $1"
     12         exit 1
     13     fi
     14 }
     15 
     16 function rss_valid () {
     17     if (curl -s "$1"  | grep -o 'Sorry' >/dev/null); then
     18         echo -e "[\033[1;31mFAIL\033[0m]"
     19         echo -e "  Errors : $1"
     20         exit 1
     21     fi
     22 }
     23 
     24 
     25 # HTML files
     26 check_html() {
     27     http=http://validator.w3.org/check
     28     count=0
     29     total=`find -name '*.html'|wc -l`
     30     for file in `find -name '*.html'`; do
     31     
     32         count=$(( $count+1 ))
     33         echo -ne "\rChecking HTML file(s) ... $count/$total"
     34     
     35         full_uri=${uri}/${file/.\//}
     36         check="${http}?uri=${full_uri}&charset=${charset}&$doctype=${doctype}"
     37     
     38         w3c_valid "$check"
     39         echo -ne "\rChecking HTML file(s) ... "
     40     done
     41     
     42     echo -e "[\033[1;32m OK \033[0m]"
     43 }
     44 
     45 # CSS files
     46 check_css() {
     47     echo -n 'Checking CSS  file(s) ... '
     48     
     49     http=http://jigsaw.w3.org/css-validator/validator
     50     check="${http}?uri=${uri}&profile=${profile}"
     51     
     52     w3c_valid "$check"
     53     echo -e "[\033[1;32m OK \033[0m]"
     54 }
     55 
     56 # RSS feed
     57 check_rss() {
     58     echo -n 'Checking RSS  file(s) ... '
     59     http=http://feedvalidator.org/check.cgi
     60     check="${http}?url=${uri}/rss/feed.xml"
     61     
     62     rss_valid "$check"
     63     echo -e "[\033[1;32m OK \033[0m]"
     64 }
     65 
     66 case $1 in
     67     rss)    check_rss  ;;
     68     css)    check_css  ;;
     69     html)   check_html ;;
     70     *)      check_html
     71             check_css
     72             check_rss  ;;
     73 esac
     74 
     75 exit 0