blob: 90f73d2306e0787ca437cd9fa691b2533f41bdb4 [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)
Victor Morales96fe3882018-03-02 14:08:39 -080035 CHECK_CMD="zypper search --match-exact --installed"
Victor Morales9f1c94b2017-11-07 07:56:04 -080036 ;;
37 ubuntu|debian)
Victor Morales96fe3882018-03-02 14:08:39 -080038 CHECK_CMD="dpkg -l"
Victor Morales9f1c94b2017-11-07 07:56:04 -080039 ;;
40 rhel|centos|fedora)
Victor Morales96fe3882018-03-02 14:08:39 -080041 CHECK_CMD="rpm -q"
Victor Morales9f1c94b2017-11-07 07:56:04 -080042 ;;
43 esac
Victor Morales96fe3882018-03-02 14:08:39 -080044 ${CHECK_CMD} "$@" &> /dev/null
Victor Morales89ce3212017-06-16 18:32:48 -050045}
46
Victor Morales7ae05a42017-08-22 14:39:00 -050047# install_packages() - Install a list of packages
48function install_packages {
49 local package=$@
Victor Morales9f1c94b2017-11-07 07:56:04 -080050 source /etc/os-release || source /usr/lib/os-release
51 case ${ID,,} in
52 *suse)
53 ;;
54 ubuntu|debian)
55 apt-get install -y -qq $package
56 ;;
57 rhel|centos|fedora)
58 ;;
59 esac
Victor Morales7ae05a42017-08-22 14:39:00 -050060}
61
Victor Morales89ce3212017-06-16 18:32:48 -050062# install_package() - Install specific package if doesn't exist
63function install_package {
64 local package=$1
Victor Morales7abf1a82017-11-06 09:20:27 -080065
Victor Morales89ce3212017-06-16 18:32:48 -050066 if ! is_package_installed $package; then
Victor Morales7abf1a82017-11-06 09:20:27 -080067 echo "Installing $package..."
68
Victor Morales9f1c94b2017-11-07 07:56:04 -080069 source /etc/os-release || source /usr/lib/os-release
70 case ${ID,,} in
71 *suse)
72 zypper install -y $package
73 ;;
74 ubuntu|debian)
75 if [[ "$debug" == "False" ]]; then
76 apt-get install -y -qq -o=Dpkg::Use-Pty=0 $package
77 else
78 apt-get install -y $package
79 fi
80 ;;
81 rhel|centos|fedora)
82 PKG_MANAGER=$(which dnf || which yum)
83 ${PKG_MANAGER} -y install $package
84 ;;
85 esac
Victor Morales89ce3212017-06-16 18:32:48 -050086 fi
87}
Victor Morales7ae05a42017-08-22 14:39:00 -050088
89# uninstall_packages() - Uninstall a list of packages
90function uninstall_packages {
91 local packages=$@
Victor Morales9f1c94b2017-11-07 07:56:04 -080092 source /etc/os-release || source /usr/lib/os-release
93 case ${ID,,} in
94 *suse)
95 ;;
96 ubuntu|debian)
97 apt-get purge -y -qq $packages
98 ;;
99 rhel|centos|fedora)
100 ;;
101 esac
Victor Morales7ae05a42017-08-22 14:39:00 -0500102}
103
104# uninstall_package() - Uninstall specific package if exists
105function uninstall_package {
106 local package=$1
107 if is_package_installed $package; then
Victor Morales9f1c94b2017-11-07 07:56:04 -0800108 source /etc/os-release || source /usr/lib/os-release
109 case ${ID,,} in
110 *suse)
111 ;;
112 ubuntu|debian)
113 apt-get purge -y -qq $package
114 ;;
115 rhel|centos|fedora)
116 ;;
117 esac
Victor Morales7ae05a42017-08-22 14:39:00 -0500118 fi
119}