Blame Automation/Modules/Help/help.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# help.sh -- This function initializes the interface used by
Alain Reguera Delgado 8f60cb
# centos-art.sh script to perform documentation tasks through
Alain Reguera Delgado 8f60cb
# different documentation formats.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
    
Alain Reguera Delgado 8f60cb
function help {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize action name with an empty value.
Alain Reguera Delgado 8f60cb
    local ACTIONNAM=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize search option (`--search'). This option is used to
Alain Reguera Delgado 8f60cb
    # look for documentation inside documentation formats.
Alain Reguera Delgado 8f60cb
    local FLAG_SEARCH=""
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize manual's language.
Alain Reguera Delgado 8f60cb
    local MANUAL_L10N=${CLI_LANG_LC}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize manuals' top-level directory. This is the place where
Alain Reguera Delgado 8f60cb
    # source files for documentation manuals will be stored in. 
Alain Reguera Delgado 8f60cb
    local MANUAL_TLDIR="${TCAR_WORKDIR}/Documentation/Models"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize documentation format. This information defines the
Alain Reguera Delgado 8f60cb
    # kind of source files we work with inside the documentation
Alain Reguera Delgado 8f60cb
    # manual as well as the kind of actions required by them to
Alain Reguera Delgado 8f60cb
    # perform actions related to document management (e.g., creation,
Alain Reguera Delgado 8f60cb
    # edition, deletion, copying, renaming, etc.). By default texinfo
Alain Reguera Delgado 8f60cb
    # format is used. Other formats can be specified in the
Alain Reguera Delgado 8f60cb
    # command-line using the `--format' option.
Alain Reguera Delgado 8f60cb
    local FLAG_FORMAT='texinfo'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize specific function export id. This value is redefined
Alain Reguera Delgado 8f60cb
    # later once we know which is the documentation format.
Alain Reguera Delgado 8f60cb
    local EXPORTID=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize documentation entries arrays. Arrays defined here
Alain Reguera Delgado 8f60cb
    # contain all the information needed to process documentation
Alain Reguera Delgado 8f60cb
    # entries (e.g., manual, part, chapter and section).
Alain Reguera Delgado 8f60cb
    local -a MANUAL_SLFN
Alain Reguera Delgado 8f60cb
    local -a MANUAL_DIRN
Alain Reguera Delgado 8f60cb
    local -a MANUAL_PART
Alain Reguera Delgado 8f60cb
    local -a MANUAL_CHAP
Alain Reguera Delgado 8f60cb
    local -a MANUAL_SECT
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize documentation entries counter.
Alain Reguera Delgado 8f60cb
    local MANUAL_DOCENTRY_COUNT=0
Alain Reguera Delgado 8f60cb
    local MANUAL_DOCENTRY_ID=0
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Interpret option arguments passed through the command-line.
Alain Reguera Delgado 8f60cb
    help_getOptions
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Redefine arrays related to documentation entries using
Alain Reguera Delgado 8f60cb
    # non-option arguments passed through the command-line. At this
Alain Reguera Delgado 8f60cb
    # point all options have been removed from ARGUMENTS and
Alain Reguera Delgado 8f60cb
    # non-option arguments remain. Evaluate ARGUMENTS to retrieve the
Alain Reguera Delgado 8f60cb
    # information related documentation entries from there.
Alain Reguera Delgado 8f60cb
    help_getEntries
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Execute format-specific documentation tasks for each
Alain Reguera Delgado 8f60cb
    # documentation entry specified in the command-line, individually.
Alain Reguera Delgado 8f60cb
    # Notice that we've stored all documentation entries passed as
Alain Reguera Delgado 8f60cb
    # non-option arguments in array variables in order to process them
Alain Reguera Delgado 8f60cb
    # now, one by one.  This is particularly useful when we need to
Alain Reguera Delgado 8f60cb
    # reach items in the array beyond the current iteration cycle. For
Alain Reguera Delgado 8f60cb
    # example, when we perform actions that require source and target
Alain Reguera Delgado 8f60cb
    # locations (e.g., copying and renaming): we use the current value
Alain Reguera Delgado 8f60cb
    # as source location and the second value in the array as target
Alain Reguera Delgado 8f60cb
    # location; both defined from the first iteration cycle.
Alain Reguera Delgado 8f60cb
    while [[ $MANUAL_DOCENTRY_ID -lt $MANUAL_DOCENTRY_COUNT ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define name used by manual's main definition file.
Alain Reguera Delgado 8f60cb
        MANUAL_NAME=${MANUAL_SLFN[${MANUAL_DOCENTRY_ID}]}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define extension used by documentation manuals. The
Alain Reguera Delgado 8f60cb
        # extension used must be the same passed in the format option.
Alain Reguera Delgado 8f60cb
        MANUAL_EXTENSION=${FLAG_FORMAT}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to directory holding language-specific
Alain Reguera Delgado 8f60cb
        # models.
Alain Reguera Delgado 8f60cb
        MANUAL_BASEDIR="${MANUAL_TLDIR}/$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
            ${MANUAL_EXTENSION} -d)/${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to directory holding language-specific
Alain Reguera Delgado 8f60cb
        # source files.
Alain Reguera Delgado 8f60cb
        MANUAL_BASEDIR_L10N="${MANUAL_BASEDIR}/${MANUAL_L10N}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to changed directories inside the
Alain Reguera Delgado 8f60cb
        # manual. For example, when a section entry is edited, copied
Alain Reguera Delgado 8f60cb
        # or renamed inside  the same manual there is only one
Alain Reguera Delgado 8f60cb
        # absolute path to look for changes, the one holding the
Alain Reguera Delgado 8f60cb
        # section entry.  However, when an entire manual is renamed,
Alain Reguera Delgado 8f60cb
        # there might be two different locations to look changes for,
Alain Reguera Delgado 8f60cb
        # the source location deleted and the target location added.
Alain Reguera Delgado 8f60cb
        MANUAL_CHANGED_DIRS="${MANUAL_BASEDIR_L10N}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to base file. This is the main file
Alain Reguera Delgado 8f60cb
        # name (without extension) we use as reference to build output
Alain Reguera Delgado 8f60cb
        # files in different formats (.info, .pdf, .xml, etc.).
Alain Reguera Delgado 8f60cb
        MANUAL_BASEFILE="${MANUAL_BASEDIR_L10N}/${MANUAL_NAME}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Redefine function export id based on documentation format.
Alain Reguera Delgado 8f60cb
        EXPORTID="${CLI_FUNCDIRNAM}/$(cli_getRepoName ${MANUAL_EXTENSION} -d)/${MANUAL_EXTENSION}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define manual base file used for output.
Alain Reguera Delgado 8f60cb
        MANUAL_OUTPUT_BASEFILE=$(echo $MANUAL_BASEFILE | sed -r 's!Models/!Manuals/!')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define manual's part name.
Alain Reguera Delgado 8f60cb
        MANUAL_PART_NAME=${MANUAL_PART[${MANUAL_DOCENTRY_ID}]}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to manual's part directory.
Alain Reguera Delgado 8f60cb
        MANUAL_PART_DIR="${MANUAL_BASEDIR_L10N}/${MANUAL_PART_NAME}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define manual's chapter name.
Alain Reguera Delgado 8f60cb
        MANUAL_CHAPTER_NAME=${MANUAL_CHAP[${MANUAL_DOCENTRY_ID}]}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to chapter's directory. This is the
Alain Reguera Delgado 8f60cb
        # place where chapter-specific files are stored in. Be sure no
Alain Reguera Delgado 8f60cb
        # extra slash be present in the value (e.g., when the part
Alain Reguera Delgado 8f60cb
        # name isn't provided).
Alain Reguera Delgado 8f60cb
        MANUAL_CHAPTER_DIR="$(echo ${MANUAL_PART_DIR}/${MANUAL_CHAPTER_NAME} \
Alain Reguera Delgado 8f60cb
            | sed -r 's!/{2,}!/!g' | sed -r 's!/$!!' )"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define section name.
Alain Reguera Delgado 8f60cb
        MANUAL_SECTION_NAME=${MANUAL_SECT[${MANUAL_DOCENTRY_ID}]}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to manual's configuration file.  This
Alain Reguera Delgado 8f60cb
        # is the file that controls the way template files are applied
Alain Reguera Delgado 8f60cb
        # to documentation entries once they have been created as well
Alain Reguera Delgado 8f60cb
        # as the style and order used for printing sections. 
Alain Reguera Delgado 8f60cb
        MANUAL_CONFIG_FILE="${MANUAL_BASEFILE}.conf" 
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Notice that, because we are processing non-option arguments
Alain Reguera Delgado 8f60cb
        # one by one, there is no need to synchronize changes or
Alain Reguera Delgado 8f60cb
        # initialize functionalities to the same manual time after
Alain Reguera Delgado 8f60cb
        # time (assuming all documentation entries passed as
Alain Reguera Delgado 8f60cb
        # non-option arguments refer the same manual directory name).
Alain Reguera Delgado 8f60cb
        # That would be only necessary when documentation entries
Alain Reguera Delgado 8f60cb
        # refer to different manual directory names that could be
Alain Reguera Delgado 8f60cb
        # written in different documentation formats.
Alain Reguera Delgado 8f60cb
        if [[ ${MANUAL_DOCENTRY_ID} -eq 0 \
Alain Reguera Delgado 8f60cb
            || ( ( ${MANUAL_DOCENTRY_ID} -gt 0 ) && ( \
Alain Reguera Delgado 8f60cb
            ${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]} != ${MANUAL_DIRN[((${MANUAL_DOCENTRY_ID} - 1))]} ) ) ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Synchronize changes between repository and working copy.
Alain Reguera Delgado 8f60cb
            # At this point, changes in the repository are merged in
Alain Reguera Delgado 8f60cb
            # the working copy and changes in the working copy
Alain Reguera Delgado 8f60cb
            # committed up to repository.
Alain Reguera Delgado 8f60cb
            if [[ -d ${MANUAL_CHANGED_DIRS} ]];then
Alain Reguera Delgado 8f60cb
                cli_synchronizeRepoChanges "${MANUAL_CHANGED_DIRS}"
Alain Reguera Delgado 8f60cb
            fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Initialize documentation format functionalities. At
Alain Reguera Delgado 8f60cb
            # this point we load all functionalities required into
Alain Reguera Delgado 8f60cb
            # `centos-art.sh''s execution environment and make them
Alain Reguera Delgado 8f60cb
            # available, this way, to perform format-specific
Alain Reguera Delgado 8f60cb
            # documentation tasks.
Alain Reguera Delgado 8f60cb
            cli_exportFunctions "${EXPORTID}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Execute format-specific documentation tasks.
Alain Reguera Delgado 8f60cb
        ${MANUAL_EXTENSION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Unset the exported functions before go on with the next
Alain Reguera Delgado 8f60cb
        # documentation entry provided as non-option argument to
Alain Reguera Delgado 8f60cb
        # `centos-art.sh' script. Different documentation entries may
Alain Reguera Delgado 8f60cb
        # be written in different documentation formats. Each
Alain Reguera Delgado 8f60cb
        # documentation format is loaded in order to perform their
Alain Reguera Delgado 8f60cb
        # related documentation tasks. Assuming more that one
Alain Reguera Delgado 8f60cb
        # documentation entry be passed as non-option argument to
Alain Reguera Delgado 8f60cb
        # `centos-art.sh' script and they are written in different
Alain Reguera Delgado 8f60cb
        # formats, we might end up loading documentation format
Alain Reguera Delgado 8f60cb
        # functionalities that aren't used in the current
Alain Reguera Delgado 8f60cb
        # documentation entry being processed. In that sake, unset
Alain Reguera Delgado 8f60cb
        # documentation back-end functionalities when the next
Alain Reguera Delgado 8f60cb
        # documentation entry refers to a manual directory different
Alain Reguera Delgado 8f60cb
        # to that one being currently processed.
Alain Reguera Delgado 8f60cb
        if [[ ${MANUAL_DOCENTRY_ID} -gt 0 \
Alain Reguera Delgado 8f60cb
            && ${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]} != ${MANUAL_DIRN[((${MANUAL_DOCENTRY_ID} + 1))]} ]];then
Alain Reguera Delgado 8f60cb
            cli_unsetFunctions "${EXPORTID}"
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increment documentation entry counter id.
Alain Reguera Delgado 8f60cb
        MANUAL_DOCENTRY_ID=$(($MANUAL_DOCENTRY_ID + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Synchronize changes between repository and working copy. At this
Alain Reguera Delgado 8f60cb
    # point, changes in the repository are merged in the working copy
Alain Reguera Delgado 8f60cb
    # and changes in the working copy committed up to repository.
Alain Reguera Delgado 8f60cb
    cli_synchronizeRepoChanges "${MANUAL_CHANGED_DIRS}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}