Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / install_prerequisites / install_prerequisites.sh
1 #!/bin/bash
2
3 # Copyright (c) 2019 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 error() {
18     local code="${3:-1}"
19     if [[ -n "$2" ]];then
20         echo "Error on or near line $1: $2; exiting with status ${code}"
21     else
22         echo "Error on or near line $1; exiting with status ${code}"
23     fi
24     exit "${code}"
25
26 trap 'error ${LINENO}' ERR
27
28
29 V_ENV=0
30
31 for ((i=1;i <= $#;i++)) {
32     case "${!i}" in
33         caffe|tf|mxnet|kaldi|onnx)
34             postfix="_"$1""
35             ;;
36         "venv")
37             V_ENV=1
38             ;;
39         *)
40             if [[ "$1" != "" ]]; then
41                 echo "\""${!i}"\" is unsupported parameter"
42                 echo $"Usage: $0 {caffe|tf|mxnet|kaldi|onnx} {venv}"
43                 exit 1
44             fi
45             ;;
46         esac
47 }
48
49 SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
50
51 if [[ -f /etc/centos-release ]]; then
52     DISTRO="centos"
53 elif [[ -f /etc/lsb-release ]]; then
54     DISTRO="ubuntu"
55 fi
56
57 if [[ $DISTRO == "centos" ]]; then
58     if command -v python3.5 >/dev/null 2>&1; then
59         python_binary=python3.5
60     fi
61     if command -v python3.6 >/dev/null 2>&1; then
62         python_binary=python3.6
63     fi
64     if [ -z "$python_binary" ]; then
65         sudo -E yum install -y https://centos7.iuscommunity.org/ius-release.rpm
66         #sudo -E yum install -y python36u easy_install python36u-pip
67         sudo -E yum install -y python36u python36u-pip
68         sudo -E pip3.6 install virtualenv
69         python_binary=python3.6
70     fi
71 elif [[ $DISTRO == "ubuntu" ]]; then
72     sudo -E apt update
73     sudo -E apt -y install python3-pip python3-venv libgfortran3
74     python_binary=python3
75 fi
76
77
78 if [[ $V_ENV -eq 1 ]]; then
79     $python_binary -m venv $SCRIPTDIR/../venv
80     source $SCRIPTDIR/../venv/bin/activate
81     $SCRIPTDIR/../venv/bin/$python_binary -m pip install -r $SCRIPTDIR/../requirements${postfix}.txt
82     echo
83     echo "Before running the Model Optimizer, please activate virtualenv environment by running \"source ${SCRIPTDIR}/../venv/bin/activate\""
84 else
85     if [[ "$OSTYPE" == "darwin"* ]]; then
86         python3 -m pip install -r $SCRIPTDIR/../requirements${postfix}.txt
87     else
88         sudo -E $python_binary -m pip install -r $SCRIPTDIR/../requirements${postfix}.txt
89     fi
90     echo [WARNING] All Model Optimizer dependencies are installed globally.
91     echo [WARNING] If you want to keep Model Optimizer in separate sandbox
92     echo [WARNING] run install_prerequisites.sh venv "{caffe|tf|mxnet|kaldi|onnx}"
93 fi