blob: 5d0c6910832685e9aa7db8ac33aad972915731e5 [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 Morales9f1c94b2017-11-07 07:56:04 -08009 source /etc/os-release || source /usr/lib/os-release
10 case ${ID,,} in
11 *suse)
12 zypper -n ref
13 ;;
14 ubuntu|debian)
15 if [[ "$debug" == "False" ]]; then
16 apt-get update > /dev/null
17 else
18 apt-get update
19 fi
20 ;;
21 rhel|centos|fedora)
22 yum updateinfo
23 ;;
24 esac
Victor Morales89ce3212017-06-16 18:32:48 -050025}
26
27# is_package_installed() - Function to tell if a package is installed
28function is_package_installed {
29 if [[ -z "$@" ]]; then
30 return 1
31 fi
Victor Morales9f1c94b2017-11-07 07:56:04 -080032 source /etc/os-release || source /usr/lib/os-release
33 case ${ID,,} in
34 *suse)
35 ;;
36 ubuntu|debian)
Victor Morales4ab71c12017-11-08 07:28:28 -080037 dpkg -s "$@" > /dev/null
Victor Morales9f1c94b2017-11-07 07:56:04 -080038 ;;
39 rhel|centos|fedora)
40 ;;
41 esac
Victor Morales89ce3212017-06-16 18:32:48 -050042}
43
Victor Morales7ae05a42017-08-22 14:39:00 -050044# install_packages() - Install a list of packages
45function install_packages {
46 local package=$@
Victor Morales9f1c94b2017-11-07 07:56:04 -080047 source /etc/os-release || source /usr/lib/os-release
48 case ${ID,,} in
49 *suse)
50 ;;
51 ubuntu|debian)
52 apt-get install -y -qq $package
53 ;;
54 rhel|centos|fedora)
55 ;;
56 esac
Victor Morales7ae05a42017-08-22 14:39:00 -050057}
58
Victor Morales89ce3212017-06-16 18:32:48 -050059# install_package() - Install specific package if doesn't exist
60function install_package {
61 local package=$1
Victor Morales7abf1a82017-11-06 09:20:27 -080062
Victor Morales89ce3212017-06-16 18:32:48 -050063 if ! is_package_installed $package; then
Victor Morales7abf1a82017-11-06 09:20:27 -080064 echo "Installing $package..."
65
Victor Morales9f1c94b2017-11-07 07:56:04 -080066 source /etc/os-release || source /usr/lib/os-release
67 case ${ID,,} in
68 *suse)
69 zypper install -y $package
70 ;;
71 ubuntu|debian)
72 if [[ "$debug" == "False" ]]; then
73 apt-get install -y -qq -o=Dpkg::Use-Pty=0 $package
74 else
75 apt-get install -y $package
76 fi
77 ;;
78 rhel|centos|fedora)
79 PKG_MANAGER=$(which dnf || which yum)
80 ${PKG_MANAGER} -y install $package
81 ;;
82 esac
Victor Morales89ce3212017-06-16 18:32:48 -050083 fi
84}
Victor Morales7ae05a42017-08-22 14:39:00 -050085
86# uninstall_packages() - Uninstall a list of packages
87function uninstall_packages {
88 local packages=$@
Victor Morales9f1c94b2017-11-07 07:56:04 -080089 source /etc/os-release || source /usr/lib/os-release
90 case ${ID,,} in
91 *suse)
92 ;;
93 ubuntu|debian)
94 apt-get purge -y -qq $packages
95 ;;
96 rhel|centos|fedora)
97 ;;
98 esac
Victor Morales7ae05a42017-08-22 14:39:00 -050099}
100
101# uninstall_package() - Uninstall specific package if exists
102function uninstall_package {
103 local package=$1
104 if is_package_installed $package; then
Victor Morales9f1c94b2017-11-07 07:56:04 -0800105 source /etc/os-release || source /usr/lib/os-release
106 case ${ID,,} in
107 *suse)
108 ;;
109 ubuntu|debian)
110 apt-get purge -y -qq $package
111 ;;
112 rhel|centos|fedora)
113 ;;
114 esac
Victor Morales7ae05a42017-08-22 14:39:00 -0500115 fi
116}