blob: 41329ee2ba2ad41b7c5d6c80af24f21e3a52c5d2 [file] [log] [blame]
Igor Murashkin0334aa02012-12-04 14:59:53 -08001#!/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
19packager=""
20retcode=0
21if [[ "$OSTYPE" == "darwin"* ]]
22then
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
29elif [[ "$OSTYPE" == "linux-gnu" ]] && which apt-get >& /dev/null
30then
31 packager="apt-get"
32fi
33
34function 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
47function 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
Igor Murashkin6c936c12014-05-13 14:51:49 -070070 echo "Missing $bin binary; please install with '$(packager_install $pkg)'"
Igor Murashkin0334aa02012-12-04 14:59:53 -080071 fi
72
73 retcode=1
74 return 1
75}
76
77function python_check()
78{
79 local mod=$1
80 local macports=$2
81 local aptget=$3
82
83 local pkg=""
84
Eino-Ville Talvalaa5213a22020-05-10 16:57:36 -070085 if python3 -c "import $mod" >& /dev/null
Igor Murashkin0334aa02012-12-04 14:59:53 -080086 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
107binary_check xmllint libxml2 libxml2-utils
108binary_check tidy tidy tidy
Shuzhen Wang2687a332020-06-05 13:34:23 -0700109binary_check python3 python3 python3
Eino-Ville Talvalaa5213a22020-05-10 16:57:36 -0700110python_check bs4 python-bs4 python3-bs4
Shuzhen Wang2687a332020-06-05 13:34:23 -0700111python_check mako python3-mako python3-mako
Eino-Ville Talvalaa5213a22020-05-10 16:57:36 -0700112python_check markdown python-markdown python3-markdown
Igor Murashkin0334aa02012-12-04 14:59:53 -0800113
114exit $retcode
115