Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 3 | # update_repos() - Function that updates linux repositories |
| 4 | function update_repos { |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 5 | echo "Updating repositories list..." |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 6 | if [ -f /var/onap/files/sources.list ]; then |
| 7 | cp /var/onap/files/sources.list /etc/apt/sources.list |
| 8 | fi |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 9 | 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 Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | # is_package_installed() - Function to tell if a package is installed |
| 28 | function is_package_installed { |
| 29 | if [[ -z "$@" ]]; then |
| 30 | return 1 |
| 31 | fi |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 32 | source /etc/os-release || source /usr/lib/os-release |
| 33 | case ${ID,,} in |
| 34 | *suse) |
| 35 | ;; |
| 36 | ubuntu|debian) |
| 37 | dpkg -s "$@" > /dev/null 2> /dev/null |
| 38 | ;; |
| 39 | rhel|centos|fedora) |
| 40 | ;; |
| 41 | esac |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 44 | # install_packages() - Install a list of packages |
| 45 | function install_packages { |
| 46 | local package=$@ |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 47 | 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 Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 59 | # install_package() - Install specific package if doesn't exist |
| 60 | function install_package { |
| 61 | local package=$1 |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 62 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 63 | if ! is_package_installed $package; then |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 64 | echo "Installing $package..." |
| 65 | |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 66 | 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 Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 83 | fi |
| 84 | } |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 85 | |
| 86 | # uninstall_packages() - Uninstall a list of packages |
| 87 | function uninstall_packages { |
| 88 | local packages=$@ |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 89 | 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 Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | # uninstall_package() - Uninstall specific package if exists |
| 102 | function uninstall_package { |
| 103 | local package=$1 |
| 104 | if is_package_installed $package; then |
Victor Morales | 9f1c94b | 2017-11-07 07:56:04 -0800 | [diff] [blame] | 105 | 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 Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 115 | fi |
| 116 | } |