Merge "Add CSIT cases for vfc-sfc-driver-zte"
[integration.git] / bootstrap / vagrant-onap / lib / commons
1 #!/bin/bash
2
3 set -o xtrace
4
5 # update_repos() - Function that updates linux repositories
6 function update_repos {
7     if [ -f /var/onap/files/sources.list ]; then
8         cp /var/onap/files/sources.list /etc/apt/sources.list
9     fi
10     if [ -f /var/onap/files/proxyrc ]; then
11         source /var/onap/files/proxyrc
12         cp /var/onap/files/proxyrc /etc/profile.d/proxy.sh
13
14         if [ -f /etc/apt/apt.conf ]; then
15             echo "Acquire::http::Proxy \"${http_proxy}\";" >>  /etc/apt/apt.conf
16             echo "Acquire::https::Proxy \"${https_proxy}\";" >>  /etc/apt/apt.conf
17         fi
18         if [ -d /etc/apt/apt.conf.d ] & [ ! -f /etc/apt/apt.conf.d/70proxy.conf ]; then
19             echo "Acquire::http::Proxy \"${http_proxy}\";" >>  /etc/apt/apt.conf.d/70proxy.conf
20             echo "Acquire::https::Proxy \"${https_proxy}\";" >>  /etc/apt/apt.conf.d/70proxy.conf
21         fi
22     fi
23     apt-get update -qq -y
24 }
25
26 # is_package_installed() - Function to tell if a package is installed
27 function is_package_installed {
28     if [[ -z "$@" ]]; then
29         return 1
30     fi
31     dpkg -s "$@" > /dev/null 2> /dev/null
32 }
33
34 # install_packages() - Install a list of packages
35 function install_packages {
36     local package=$@
37     update_repos
38     apt-get install -y -qq $package
39 }
40
41 # install_package() - Install specific package if doesn't exist
42 function install_package {
43     local package=$1
44     if ! is_package_installed $package; then
45         update_repos
46         apt-get install -y -qq $package
47     fi
48 }
49
50 # uninstall_packages() - Uninstall a list of packages
51 function uninstall_packages {
52     local packages=$@
53     apt-get purge -y -qq $packages
54 }
55
56 # uninstall_package() - Uninstall specific package if exists
57 function uninstall_package {
58     local package=$1
59     if is_package_installed $package; then
60         apt-get purge -y -qq $package
61     fi
62 }