Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -o xtrace |
| 4 | |
| 5 | # update_repos() - Function that updates linux repositories |
| 6 | function update_repos { |
| 7 | if [ -f /var/onap/files/sources.list ]; then |
| 8 | cp /var/onap/files/sources.list /etc/apt/sources.list |
| 9 | fi |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 10 | if [ -f /var/onap/files/proxyrc ]; then |
| 11 | source /var/onap/files/proxyrc |
| 12 | cp /var/onap/files/proxyrc /etc/profile.d/proxy.sh |
| 13 | |
| 14 | if [ -f /etc/apt/apt.conf ]; then |
| 15 | echo "Acquire::http::Proxy \"${http_proxy}\";" >> /etc/apt/apt.conf |
| 16 | echo "Acquire::https::Proxy \"${https_proxy}\";" >> /etc/apt/apt.conf |
| 17 | fi |
| 18 | if [ -d /etc/apt/apt.conf.d ] & [ ! -f /etc/apt/apt.conf.d/70proxy.conf ]; then |
| 19 | echo "Acquire::http::Proxy \"${http_proxy}\";" >> /etc/apt/apt.conf.d/70proxy.conf |
| 20 | echo "Acquire::https::Proxy \"${https_proxy}\";" >> /etc/apt/apt.conf.d/70proxy.conf |
| 21 | fi |
| 22 | fi |
| 23 | apt-get update -qq -y |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | # is_package_installed() - Function to tell if a package is installed |
| 27 | function is_package_installed { |
| 28 | if [[ -z "$@" ]]; then |
| 29 | return 1 |
| 30 | fi |
| 31 | dpkg -s "$@" > /dev/null 2> /dev/null |
| 32 | } |
| 33 | |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 34 | # install_packages() - Install a list of packages |
| 35 | function install_packages { |
| 36 | local package=$@ |
| 37 | update_repos |
| 38 | apt-get install -y -qq $package |
| 39 | } |
| 40 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 41 | # install_package() - Install specific package if doesn't exist |
| 42 | function install_package { |
| 43 | local package=$1 |
| 44 | if ! is_package_installed $package; then |
| 45 | update_repos |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 46 | apt-get install -y -qq $package |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 47 | fi |
| 48 | } |
Victor Morales | 7ae05a4 | 2017-08-22 14:39:00 -0500 | [diff] [blame] | 49 | |
| 50 | # uninstall_packages() - Uninstall a list of packages |
| 51 | function uninstall_packages { |
| 52 | local packages=$@ |
| 53 | apt-get purge -y -qq $packages |
| 54 | } |
| 55 | |
| 56 | # uninstall_package() - Uninstall specific package if exists |
| 57 | function uninstall_package { |
| 58 | local package=$1 |
| 59 | if is_package_installed $package; then |
| 60 | apt-get purge -y -qq $package |
| 61 | fi |
| 62 | } |