Home | History | Annotate | Download | only in docs
      1 #!/bin/bash
      2 
      3 #
      4 # Copyright (C) 2012 The Android Open Source Project
      5 #
      6 # Licensed under the Apache License, Version 2.0 (the "License");
      7 # you may not use this file except in compliance with the License.
      8 # You may obtain a copy of the License at
      9 #
     10 #      http://www.apache.org/licenses/LICENSE-2.0
     11 #
     12 # Unless required by applicable law or agreed to in writing, software
     13 # distributed under the License is distributed on an "AS IS" BASIS,
     14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 # See the License for the specific language governing permissions and
     16 # limitations under the License.
     17 #
     18 
     19 packager=""
     20 retcode=0
     21 if [[ "$OSTYPE" == "darwin"* ]]
     22 then
     23     packager="macports"
     24 
     25     if ! which port >& /dev/null
     26     then
     27         echo "Missing port binary, please install from http://www.macports.org/" >& 2
     28     fi
     29 elif [[ "$OSTYPE" == "linux-gnu" ]] && which apt-get >& /dev/null
     30 then
     31     packager="apt-get"
     32 fi
     33 
     34 function packager_install
     35 {
     36     if [[ $packager == "macports" ]]
     37     then
     38         echo "sudo port install $1"
     39     elif [[ $packager == "apt-get" ]]
     40     then
     41         echo "sudo apt-get install $1"
     42     else
     43         echo "<your package manager> install $1"
     44     fi
     45 }
     46 
     47 function binary_check()
     48 {
     49     local bin=$1
     50     local macports=$2
     51     local aptget=$3
     52 
     53     local pkg=""
     54 
     55     if type -f "$bin" >& /dev/null
     56     then
     57         return 0
     58     fi
     59 
     60     if [[ $packager == "macports" ]]
     61     then
     62         pkg="$macports"
     63     elif [[ $packager == "apt-get" ]]
     64     then
     65         pkg="$aptget"
     66     fi
     67 
     68     if [[ -n $pkg ]]
     69     then
     70         echo "Missing $bin binary please install with '$(packager_install $pkg)'"
     71     fi
     72 
     73     retcode=1
     74     return 1
     75 }
     76 
     77 function python_check()
     78 {
     79     local mod=$1
     80     local macports=$2
     81     local aptget=$3
     82 
     83     local pkg=""
     84 
     85     if python -c "import $mod" >& /dev/null
     86     then
     87         return 0
     88     fi
     89 
     90     if [[ $packager == "macports" ]]
     91     then
     92         pkg="$macports"
     93     elif [[ $packager == "apt-get" ]]
     94     then
     95         pkg="$aptget"
     96     fi
     97 
     98     if [[ -n $pkg ]]
     99     then
    100         echo "Missing python module $mod, please install with '$(packager_install $pkg)'"
    101     fi
    102 
    103     retcode=1
    104     return 1
    105 }
    106 
    107 binary_check xmllint libxml2 libxml2-utils
    108 binary_check tidy tidy tidy
    109 binary_check python python27 python2.7
    110 python_check bs4 py27-beautifulsoup4 python-bs4
    111 python_check mako py27-mako python-mako
    112 
    113 exit $retcode
    114 
    115