| kasar | 6477377 | 2018-05-30 04:19:00 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ## |
| 4 | # Copyright 2016-2017 VMware Inc. |
| 5 | # This file is part of ETSI OSM |
| 6 | # All Rights Reserved. |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | # not use this file except in compliance with the License. You may obtain |
| 10 | # a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 17 | # License for the specific language governing permissions and limitations |
| 18 | # under the License. |
| 19 | # |
| 20 | # For those usages not covered by the Apache License, Version 2.0 please |
| 21 | # contact: osslegalrouting@vmware.com |
| 22 | ## |
| 23 | |
| 24 | echo ' |
| 25 | ################################################################# |
| 26 | ##### Installing Require Packages ##### |
| 27 | #################################################################' |
| 28 | |
| 29 | # Paths to copy application files |
| 30 | Install_dir="/usr/local/bin" |
| 31 | App_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 32 | App_CLI_path="${App_dir}/format_converter/ovf_converter_cli.py" |
| 33 | Install_CLI_path="${Install_dir}/OVF_converter/format_converter/ovf_converter_cli.py" |
| 34 | Logs_Folder="${Install_dir}/OVF_converter/logs" |
| 35 | Log_Path="${Install_dir}/OVF_converter/logs/ovf_converter.log" |
| 36 | |
| 37 | #Function to install packages using apt-get |
| 38 | function install_packages(){ |
| 39 | [ -x /usr/bin/apt-get ] && apt-get install -y $* |
| 40 | |
| 41 | #check properly installed |
| 42 | for PACKAGE in $* |
| 43 | do |
| 44 | PACKAGE_INSTALLED="no" |
| 45 | [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes" |
| 46 | if [ "$PACKAGE_INSTALLED" = "no" ] |
| 47 | then |
| 48 | echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" >&2 |
| 49 | exit 1 |
| 50 | fi |
| 51 | done |
| 52 | } |
| 53 | |
| 54 | apt-get update # To get the latest package lists |
| 55 | install_packages "libxml2-dev libxslt-dev python-dev python-pip python-lxml python-yaml" |
| 56 | install_packages "qemu-utils" |
| 57 | |
| 58 | #apt-get install <package name> -y |
| 59 | |
| 60 | #Move OVF Converter to usr/bin |
| 61 | cp -R "${App_dir}" "${Install_dir}" |
| 62 | |
| 63 | #Create logs folder and file |
| 64 | mkdir "${Logs_Folder}" |
| 65 | touch "${Log_Path}" |
| 66 | |
| 67 | #Change permission |
| 68 | chmod -R 777 $Install_CLI_path |
| 69 | chmod -R 777 $Log_Path |
| 70 | |
| 71 | touch "${Install_dir}/ovf_converter" |
| 72 | echo "#!/bin/sh" > "${Install_dir}/ovf_converter" |
| 73 | echo "python ${Install_CLI_path} \"\$@\"" >> "${Install_dir}/ovf_converter" |
| 74 | chmod a+x "${Install_dir}/ovf_converter" |
| 75 | |
| 76 | echo ' |
| 77 | ################################################################# |
| 78 | ##### Done ##### |
| 79 | #################################################################' |