blob: ba7c7613aeeecaffa35037193fa8fcdfc8a2497b [file] [log] [blame]
Victor Morales89ce3212017-06-16 18:32:48 -05001#!/bin/bash
2
Victor Morales89ce3212017-06-16 18:32:48 -05003# update_repos() - Function that updates linux repositories
4function update_repos {
Victor Morales7abf1a82017-11-06 09:20:27 -08005 echo "Updating repositories list..."
Victor Morales89ce3212017-06-16 18:32:48 -05006 if [ -f /var/onap/files/sources.list ]; then
7 cp /var/onap/files/sources.list /etc/apt/sources.list
8 fi
Victor Morales7abf1a82017-11-06 09:20:27 -08009 if [[ "$debug" == "False" ]]; then
10 apt-get update > /dev/null
11 else
12 apt-get update
Victor Moralesdd074802017-07-26 16:06:35 -050013 fi
Victor Morales89ce3212017-06-16 18:32:48 -050014}
15
16# is_package_installed() - Function to tell if a package is installed
17function is_package_installed {
18 if [[ -z "$@" ]]; then
19 return 1
20 fi
21 dpkg -s "$@" > /dev/null 2> /dev/null
22}
23
Victor Morales7ae05a42017-08-22 14:39:00 -050024# install_packages() - Install a list of packages
25function install_packages {
26 local package=$@
27 update_repos
28 apt-get install -y -qq $package
29}
30
Victor Morales89ce3212017-06-16 18:32:48 -050031# install_package() - Install specific package if doesn't exist
32function install_package {
33 local package=$1
Victor Morales7abf1a82017-11-06 09:20:27 -080034
Victor Morales89ce3212017-06-16 18:32:48 -050035 if ! is_package_installed $package; then
Victor Morales7abf1a82017-11-06 09:20:27 -080036 echo "Installing $package..."
37
38 if [[ "$debug" == "False" ]]; then
39 apt-get install -y -qq -o=Dpkg::Use-Pty=0 $package
40 else
41 apt-get install -y $package
42 fi
Victor Morales89ce3212017-06-16 18:32:48 -050043 fi
44}
Victor Morales7ae05a42017-08-22 14:39:00 -050045
46# uninstall_packages() - Uninstall a list of packages
47function uninstall_packages {
48 local packages=$@
49 apt-get purge -y -qq $packages
50}
51
52# uninstall_package() - Uninstall specific package if exists
53function uninstall_package {
54 local package=$1
55 if is_package_installed $package; then
56 apt-get purge -y -qq $package
57 fi
58}