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

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# prepare_forUsingPackages.sh -- This function queries your system's
4c79b5
# rpm database to verify centos-art.sh required packages existence.
4c79b5
# If there is any missing package, leave a message and quit script
4c79b5
# execution.
4c79b5
#
4c79b5
# Copyright (C) 2009-2010 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation; either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
4c79b5
# $Id: prepare_forUsingPackages.sh 65 2010-09-18 03:18:50Z al $
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function prepare_forUsingPackages {
4c79b5
4c79b5
    # Output action message.
4c79b5
    cli_printMessage "`gettext "Packages"`" "AsHeadingLine"
4c79b5
4c79b5
    # Define variables as local to avoid conflicts outside.
4c79b5
    local PACKAGE=''
4c79b5
    local PACKAGES=''
4c79b5
    local PACKAGES_FROM_THIRDS=''
4c79b5
    local MISSING_PACKAGES=''
4c79b5
    local MISSING_PACKAGES_COUNTER=0
4c79b5
    local MISSING_PACKAGES_REPORT='' 
4c79b5
    local MISSING_PACKAGES_FROM_THIRDS=''
4c79b5
    local MISSING_PACKAGES_FROM_THIRDS_COUNTER=0
4c79b5
4c79b5
    # Define required packages needed by centos-art.sh script.
4c79b5
    PACKAGES="bash inkscape ImageMagick netpbm netpbm-progs
4c79b5
        syslinux gimp coreutils texinfo info tetex-latex tetex-fonts
4c79b5
        tetex-doc tetex-xdvi tetex-dvips gettext sudo yum texi2html"
4c79b5
4c79b5
    # Define, from required packages, packages being from third
4c79b5
    # parties (i.e., packages not included in rhel, nor centos [base]
4c79b5
    # repository.).
4c79b5
    PACKAGES_FROM_THIRDS="(inkscape|blender)"
4c79b5
4c79b5
    # Query RPM's database looking for required packages and build
4c79b5
    # list of missing packages.
4c79b5
    for PACKAGE in $PACKAGES;do
4c79b5
        rpm -q "$PACKAGE" >> /dev/null
4c79b5
        if [[ $? -gt 0 ]];then
4c79b5
            MISSING_PACKAGES="$PACKAGE $MISSING_PACKAGES"
4c79b5
            MISSING_PACKAGES_COUNTER=$(($MISSING_PACKAGES_COUNTER + 1))
4c79b5
            if [[ $PACKAGE =~ $PACKAGES_FROM_THIRDS ]];then
4c79b5
                MISSING_PACKAGES_FROM_THIRDS="$PACKAGE $MISSING_PACKAGES_FROM_THIRDS"
4c79b5
                MISSING_PACKAGES_FROM_THIRDS_COUNTER=$(($MISSING_PACKAGES_FROM_THIRDS_COUNTER + 1))
4c79b5
            fi
4c79b5
        fi
4c79b5
    done
4c79b5
4c79b5
    # Check required packages.
4c79b5
    if [[ $MISSING_PACKAGES_COUNTER -gt 0 ]];then
4c79b5
4c79b5
        cli_printMessage "`ngettext "The following package needs to be installed:"\
4c79b5
                                    "The following packages need to be installed:"\
4c79b5
                                    $MISSING_PACKAGES_COUNTER`"
4c79b5
        for PACKAGE in $MISSING_PACKAGES;do
4c79b5
            cli_printMessage $PACKAGE "AsResponseLine"
4c79b5
        done
4c79b5
        cli_printMessage "`gettext "Do you want to install the packages now?"`" "AsYesOrNoRequestLine"
4c79b5
4c79b5
        # Before installing packages, output a warning about
4c79b5
        # centos-art.sh required packages being from third parties (if
4c79b5
        # any).
4c79b5
        if [[ $MISSING_PACKAGES_FROM_THIRDS_COUNTER -gt 0 ]];then
4c79b5
4c79b5
            # Give format to missing packages from third parties.
4c79b5
            MISSING_PACKAGES_FROM_THIRDS=$(echo $MISSING_PACKAGES_FROM_THIRDS \
4c79b5
                | sed -r -e 's![[:space:]]+$!!' -e 's![[:space:]]+!, !g')
4c79b5
4c79b5
            cli_printMessage "`eval_ngettext \
4c79b5
            "The package \\\"\\\$MISSING_PACKAGES_FROM_THIRDS\\\" is not part of CentOS distribution. In order to install this package, you need to install third party repositories first.  For more information about installing third party repositories on CentOS distribution, see the url: http://wiki.centos.org/AdditionalResourses/Repositories."\
4c79b5
            "The packages \\\"\\\$MISSING_PACKAGES_FROM_THIRDS\\\" are not part of CentOS distribution. In order to install these packages, you need to install third party repositories first.  For more information about installing third party repositories on CentOS distribution, see the url: http://wiki.centos.org/AdditionalResourses/Repositories."  $MISSING_PACKAGES_FROM_THIRDS_COUNTER`" "AsWarningLine"
4c79b5
            
4c79b5
            cli_printMessage "`gettext "Do you want to continue?"`" "AsYesOrNoRequestLine"
4c79b5
 
4c79b5
        fi
4c79b5
4c79b5
        # Use sudo to install packages. By default user names
4c79b5
        # need to be set inside sudoers configuration file
4c79b5
        # (/etc/sudoers) in order to perform sudo commands.
4c79b5
        sudo yum install $MISSING_PACKAGES
4c79b5
4c79b5
        # Re-check packages. This is needed for those situations where
4c79b5
        # the user chooses not to install the required packages when
4c79b5
        # yum request for confirmation. If we don't re-check install
4c79b5
        # package the successful message is display after answering
4c79b5
        # negatively to yum's confirmation message. Additionally, it
4c79b5
        # helps to let the user know that third party packages are
4c79b5
        # still missing when third party repositories are not
4c79b5
        # installed inside CentOS distribution.
4c79b5
        for PACKAGE in $PACKAGES;do
4c79b5
            rpm -q "$PACKAGE" >> /dev/null
4c79b5
            if [[ $? -gt 0 ]];then
4c79b5
                prepare_forUsingPackages
4c79b5
            fi
4c79b5
        done
4c79b5
4c79b5
    else
4c79b5
4c79b5
        cli_printMessage "`gettext "The packages required by centos-art.sh script are already installed."`"
4c79b5
4c79b5
    fi
4c79b5
4c79b5
}