blob: d25c1f635ce749f0ff0de1b87df022462d813c5c [file] [log] [blame]
kasar64773772018-05-30 04:19:00 -07001#!/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
24echo '
beierlc6b00f02019-10-07 13:09:24 -040025 ################################################################
26 ##### Installing Required Packages #####
27 ################################################################'
kasar64773772018-05-30 04:19:00 -070028
29# Paths to copy application files
30Install_dir="/usr/local/bin"
31App_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
beierlc6b00f02019-10-07 13:09:24 -040032Converter_App_CLI_path="${App_dir}/ovf_converter_cli.py"
33Converter_Install_CLI_path="${Install_dir}/OVF_converter/ovf_converter_cli.py"
34Uploader_App_CLI_path="${App_dir}/ovf_uploader_cli.py"
35Uploader_Install_CLI_path="${Install_dir}/OVF_converter/ovf_uploader_cli.py"
kasar64773772018-05-30 04:19:00 -070036Logs_Folder="${Install_dir}/OVF_converter/logs"
kasar64773772018-05-30 04:19:00 -070037
38#Function to install packages using apt-get
39function install_packages(){
40 [ -x /usr/bin/apt-get ] && apt-get install -y $*
beierlc6b00f02019-10-07 13:09:24 -040041
kasar64773772018-05-30 04:19:00 -070042 #check properly installed
43 for PACKAGE in $*
44 do
45 PACKAGE_INSTALLED="no"
46 [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
47 if [ "$PACKAGE_INSTALLED" = "no" ]
48 then
49 echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" >&2
50 exit 1
51 fi
52 done
53 }
beierlc6b00f02019-10-07 13:09:24 -040054
kasar64773772018-05-30 04:19:00 -070055apt-get update # To get the latest package lists
56install_packages "libxml2-dev libxslt-dev python-dev python-pip python-lxml python-yaml"
57install_packages "qemu-utils"
58
59#apt-get install <package name> -y
60
61#Move OVF Converter to usr/bin
62cp -R "${App_dir}" "${Install_dir}"
63
64#Create logs folder and file
65mkdir "${Logs_Folder}"
kasar64773772018-05-30 04:19:00 -070066
67#Change permission
beierlc6b00f02019-10-07 13:09:24 -040068chmod -R 777 ${Converter_Install_CLI_path}
69chmod -R 777 ${Uploader_Install_CLI_path}
70chmod -R 777 ${Logs_Folder}
kasar64773772018-05-30 04:19:00 -070071
72touch "${Install_dir}/ovf_converter"
73echo "#!/bin/sh" > "${Install_dir}/ovf_converter"
beierlc6b00f02019-10-07 13:09:24 -040074echo "python3 ${Converter_Install_CLI_path} \"\$@\"" >> "${Install_dir}/ovf_converter"
kasar64773772018-05-30 04:19:00 -070075chmod a+x "${Install_dir}/ovf_converter"
76
beierlc6b00f02019-10-07 13:09:24 -040077touch "${Install_dir}/ovf_uploader"
78echo "#!/bin/sh" > "${Install_dir}/ovf_uploader"
79echo "python3 ${Uploader_Install_CLI_path} \"\$@\"" >> "${Install_dir}/ovf_uploader"
80chmod a+x "${Install_dir}/ovf_uploader"
81
82echo "Installation complete. More information can be found at:"
83echo " ${Install_dir}/OVF_converter/Usage.txt"