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 | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 9 | if [[ "$debug" == "False" ]]; then |
| 10 | apt-get update > /dev/null |
| 11 | else |
| 12 | apt-get update |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 13 | fi |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | # is_package_installed() - Function to tell if a package is installed |
| 17 | function is_package_installed { |
| 18 | if [[ -z "$@" ]]; then |
| 19 | return 1 |
| 20 | fi |
| 21 | dpkg -s "$@" > /dev/null 2> /dev/null |
| 22 | } |
| 23 | |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 24 | # install_packages() - Install a list of packages |
| 25 | function install_packages { |
| 26 | local package=$@ |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 27 | apt-get install -y -qq $package |
| 28 | } |
| 29 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 30 | # install_package() - Install specific package if doesn't exist |
| 31 | function install_package { |
| 32 | local package=$1 |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 33 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 34 | if ! is_package_installed $package; then |
Victor Morales | 7abf1a8 | 2017-11-06 09:20:27 -0800 | [diff] [blame] | 35 | echo "Installing $package..." |
| 36 | |
| 37 | if [[ "$debug" == "False" ]]; then |
| 38 | apt-get install -y -qq -o=Dpkg::Use-Pty=0 $package |
| 39 | else |
| 40 | apt-get install -y $package |
| 41 | fi |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 42 | fi |
| 43 | } |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 44 | |
| 45 | # uninstall_packages() - Uninstall a list of packages |
| 46 | function uninstall_packages { |
| 47 | local packages=$@ |
| 48 | apt-get purge -y -qq $packages |
| 49 | } |
| 50 | |
| 51 | # uninstall_package() - Uninstall specific package if exists |
| 52 | function uninstall_package { |
| 53 | local package=$1 |
| 54 | if is_package_installed $package; then |
| 55 | apt-get purge -y -qq $package |
| 56 | fi |
| 57 | } |