Blame Scripts/Functions/Prepare/prepare_doPackages.sh

4c79b5
#!/bin/bash
4c79b5
#
8e457b
# prepare_doPackages.sh -- This function verifies the required
8e457b
# packages your workstation needs to have installed in order for
8e457b
# centos-art command to run correctly. If there is one or more missing
8e457b
# packages, the `centos-art.sh' script asks you to confirm their
8e457b
# installation through yum.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
fa95b1
# the Free Software Foundation; either version 2 of the License, or
fa95b1
# (at your option) any later version.
fa95b1
#
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
# ----------------------------------------------------------------------
3b853a
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
1700f3
function prepare_doPackages {
4c79b5
8e457b
    # Verify `--packages' option.
8e457b
    if [[ $FLAG_PACKAGES == 'false' ]];then
8e457b
        return
8e457b
    fi
8e457b
8e457b
    # Print line separator.
8e457b
    cli_printMessage '-' 'AsSeparatorLine'
8e457b
7cc10e
    # Print action message.
7cc10e
    cli_printMessage "`gettext "Checking required packages"`" 'AsResponseLine'
7cc10e
7cc10e
    # Print line separator.
7cc10e
    cli_printMessage '-' 'AsSeparatorLine'
7cc10e
8e457b
    local PACKAGE=''
8e457b
    local WARNING=''
4c79b5
    local PACKAGES=''
8e457b
    local PACKAGES_THIRDS=''
8d73a3
    local -a PACKAGES_MISSING
8e457b
    local RPM='/bin/rpm'
8e457b
    local YUM='/usr/bin/yum'
8e457b
8e457b
    # Check execution rights of package managers.
8e457b
    cli_checkFiles $RPM 'x'
8e457b
    cli_checkFiles $YUM 'x'
4c79b5
4c79b5
    # Define required packages needed by centos-art.sh script.
8e457b
    PACKAGES="inkscape ImageMagick netpbm netpbm-progs syslinux gimp
8e457b
        coreutils texinfo info tetex-latex tetex-fonts tetex-xdvi
8e457b
        tetex-dvips gettext texi2html gnome-doc-utils elinks
8e457b
        docbook-style-xsl docbook-utils docbook-dtds
8e457b
        docbook-style-dsssl docbook-simple docbook-utils-pdf
8e457b
        docbook-slides firefox sudo yum rpm"
8e457b
8e457b
    # Define packages from third party repositories (i.e., packages
8e457b
    # not included in CentOS [base] repository.) required by
8e457b
    # centos-art to work as expected.
8e457b
    PACKAGES_THIRDS="(inkscape|blender)"
8e457b
8e457b
    # Build list of missing packages.
8e457b
    for PACKAGE in $PACKAGES;do
8e457b
        $RPM -q --queryformat "%{NAME}\n" $PACKAGE --quiet
8e457b
        if [[ $? -ne 0 ]];then
8e457b
            PACKAGES_MISSING[((++${#PACKAGES_MISSING[*]}))]=$PACKAGE
8e457b
        fi
8e457b
    done
8e457b
8e457b
    # Is there any package missing?
8e457b
    if [[ ${#PACKAGES_MISSING[*]} -eq 0 ]];then
8e457b
        cli_printMessage "`gettext "The required packages has been already installed."`"
8e457b
        return
8e457b
    fi
8e457b
8e457b
    # At this point there is one or more missing packages that need to
8e457b
    # be installed in the workstation. Report this issue and specify
8e457b
    # which these packages are.
8e457b
    cli_printMessage "`ngettext "The following package needs to be installed" \
8e457b
        "The following packages need to be installed" \
8e457b
        "${#PACKAGES_MISSING[*]}"`:"
8e457b
8e457b
    # Build report of missing packages and remark those comming from
8e457b
    # third party repository.
8e457b
    for PACKAGE in ${PACKAGES_MISSING[@]};do
8e457b
        if [[ $PACKAGE =~ $PACKAGES_THIRDS ]];then
8e457b
            WARNING=" (`gettext "requires third party repository!"`)"
8e457b
        fi
8e457b
        cli_printMessage "${PACKAGE}${WARNING}" 'AsResponseLine'
8e457b
    done
4c79b5
8e457b
    # Print confirmation request.
8e457b
    cli_printMessage "`gettext "Do you want to continue"`" 'AsYesOrNoRequestLine'
4c79b5
8e457b
    # Use sudo to install the missing packages in your system through
8e457b
    # yum.
8e457b
    sudo ${YUM} install ${PACKAGES_MISSING[*]}
8d73a3
4c79b5
}