blob: 26e2cc26a4c2d869329df120e91792bd21b7ca5e [file] [log] [blame]
Victor Morales89ce3212017-06-16 18:32:48 -05001#!/bin/bash
2
3set -o xtrace
4
5# update_repos() - Function that updates linux repositories
6function update_repos {
7 if [ -f /var/onap/files/sources.list ]; then
8 cp /var/onap/files/sources.list /etc/apt/sources.list
9 fi
Victor Moralesdd074802017-07-26 16:06:35 -050010 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
Victor Morales89ce3212017-06-16 18:32:48 -050024}
25
26# is_package_installed() - Function to tell if a package is installed
27function is_package_installed {
28 if [[ -z "$@" ]]; then
29 return 1
30 fi
31 dpkg -s "$@" > /dev/null 2> /dev/null
32}
33
Victor Morales7ae05a42017-08-22 14:39:00 -050034# install_packages() - Install a list of packages
35function install_packages {
36 local package=$@
37 update_repos
38 apt-get install -y -qq $package
39}
40
Victor Morales89ce3212017-06-16 18:32:48 -050041# install_package() - Install specific package if doesn't exist
42function install_package {
43 local package=$1
44 if ! is_package_installed $package; then
45 update_repos
Victor Moralesdd074802017-07-26 16:06:35 -050046 apt-get install -y -qq $package
Victor Morales89ce3212017-06-16 18:32:48 -050047 fi
48}
Victor Morales7ae05a42017-08-22 14:39:00 -050049
50# uninstall_packages() - Uninstall a list of packages
51function uninstall_packages {
52 local packages=$@
53 apt-get purge -y -qq $packages
54}
55
56# uninstall_package() - Uninstall specific package if exists
57function uninstall_package {
58 local package=$1
59 if is_package_installed $package; then
60 apt-get purge -y -qq $package
61 fi
62}