Blame Scripts/Bash/Functions/Prepare/prepare_updatePackages.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# prepare_updatePackages.sh -- This function verifies the required
878a2b
# packages your workstation needs to have installed in order for
878a2b
# `centos-art.sh' script to run correctly. If there is one or more
878a2b
# missing packages, the `centos-art.sh' script asks you to confirm
878a2b
# their installation through `sudo yum'.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function prepare_updatePackages {
878a2b
878a2b
    local PACKAGE=''
878a2b
    local PACKAGES=''
878a2b
    local PACKAGES_THIRDS=''
878a2b
    local -a PACKAGES_MISSING
878a2b
    local -a PACKAGES_INSTALL
878a2b
    local RPM='/bin/rpm'
878a2b
    local YUM='/usr/bin/yum'
878a2b
    local YUM_OPTIONS=''
878a2b
878a2b
    # Check execution rights of package managers.
38a682
    cli_checkFiles -x $RPM
38a682
    cli_checkFiles -x $YUM
878a2b
878a2b
    # Define required packages needed by centos-art.sh script.
878a2b
    PACKAGES="inkscape ImageMagick netpbm netpbm-progs syslinux gimp
38a682
        coreutils texinfo texinfo-tex info tetex-latex tetex-fonts
38a682
        tetex-xdvi tetex-dvips gettext texi2html gnome-doc-utils
38a682
        elinks docbook-style-xsl docbook-utils docbook-dtds
878a2b
        docbook-style-dsssl docbook-simple docbook-utils-pdf
878a2b
        docbook-slides firefox sudo yum rpm ctags"
878a2b
878a2b
    # Define packages from third party repositories (i.e., packages
878a2b
    # not included in CentOS [base] repository.) required by
878a2b
    # centos-art to work as expected.
878a2b
    PACKAGES_THIRDS="(inkscape|blender)"
878a2b
878a2b
    # Build list of installed and missing packages.
878a2b
    for PACKAGE in $PACKAGES;do
878a2b
        $RPM -q --queryformat "%{NAME}\n" $PACKAGE --quiet
878a2b
        if [[ $? -ne 0 ]];then
878a2b
            PACKAGES_MISSING[((++${#PACKAGES_MISSING[*]}))]=$PACKAGE
878a2b
        else
878a2b
            PACKAGES_INSTALL[((++${#PACKAGES_INSTALL[*]}))]=$PACKAGE
878a2b
        fi
878a2b
    done
878a2b
878a2b
    # Define relation between centos-art.sh options and yum options.
878a2b
    [[ $FLAG_ANSWER == 'true' ]] && YUM_OPTIONS="${YUM_OPTIONS} -y"
878a2b
    [[ $FLAG_QUIET  == 'true' ]] && YUM_OPTIONS="${YUM_OPTIONS} -q"
878a2b
878a2b
    # Use `sudo yum' to install missing packages in your workstation.
878a2b
    if [[ ${#PACKAGES_MISSING[*]} -gt 0 ]];then
878a2b
        sudo ${YUM} ${YUM_OPTIONS} install ${PACKAGES_MISSING[*]}
878a2b
    fi
878a2b
        
878a2b
    # Use `sudo yum' to update installed packages in your workstation.
878a2b
    if [[ ${#PACKAGES_INSTALL[*]} -gt 0 ]];then
878a2b
        sudo ${YUM} ${YUM_OPTIONS} update ${PACKAGES_INSTALL[*]}
878a2b
    fi
878a2b
    
878a2b
}