Blame Scripts/Functions/Help/help.sh

4c79b5
#!/bin/bash
4c79b5
#
02d6e2
# help.sh -- This function standardizes the way documentation is
02d6e2
# produced and maintain inside the working copy of CentOS Artwork
02d6e2
# Repository.
4c79b5
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
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
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
    
0211a4
function help {
2bd980
c145a8
    local ACTIONNAM=''
c145a8
    local ACTIONVAL=''
c145a8
1b527b
    # Initialize the search option. The search option (`--search')
1b527b
    # specifies the pattern used inside info files when an index
1b527b
    # search is perform.
1b527b
    FLAG_SEARCH=""
1b527b
fa1906
    # Initialize the backend option. The backend option (`--backend')
fa1906
    # specifies the backend used to manipulate the repository
deaa54
    # documentation manual.
fa1906
    FLAG_BACKEND="docbook"
5285d6
e5750b
    # Interpret option arguments passed through the command-line.
e5750b
    ${FUNCNAM}_getOptions
e5750b
e5750b
    # Define manuals base directory. This is the place where
e5750b
    # documentation manuals base directory structures are stored and
e5750b
    # organized in.
e5750b
    MANUAL_BASEDIR="$(cli_getRepoTLDir)/Manuals/$(cli_getRepoName ${FLAG_BACKEND} -d)"
e5750b
3ae895
    # Define file name (without extension) for documentation manual.
69150d
    MANUAL_NAME=repository
1f6dd8
e5750b
    # Define base name for documentation manual files (without
e5750b
    # extension). This is the main file name used to build output
e5750b
    # related files (.info, .pdf, .xml, etc.).
e5750b
    MANUAL_BASEFILE="${MANUAL_BASEDIR}/${MANUAL_NAME}"
c145a8
e5750b
    # Define function configuration directory. The function
e5750b
    # configuration directory is used to store functionality's related
e5750b
    # files.
e5750b
    MANUAL_TEMPLATE=${FUNCDIR}/${FUNCDIRNAM}/Templates
116f45
c145a8
    # Redefine positional parameters using ARGUMENTS. At this point,
c145a8
    # option arguments have been removed from ARGUMENTS variable and
c145a8
    # only non-option arguments remain in it. 
c145a8
    eval set -- "$ARGUMENTS"
e5750b
 
e5750b
    # Verify and initialize backend functions.  There is no need to
e5750b
    # load all backend-specific functions when we can use just one
e5750b
    # backend among many. Keep the cli_getFunctions function calling
e5750b
    # after all variables and arguments definitions.
e5750b
    if [[ ${FLAG_BACKEND} =~ '^texinfo$' ]];then
e5750b
        cli_getFunctions "${FUNCDIR}/${FUNCDIRNAM}" 'texinfo'
e5750b
    elif [[ ${FLAG_BACKEND} =~ '^docbook$' ]];then
e5750b
        cli_getFunctions "${FUNCDIR}/${FUNCDIRNAM}" 'docbook'
e5750b
    else
e5750b
        cli_printMessage "`gettext "The backend provided is not supported."`" --as-error-line
e5750b
    fi
c145a8
e5750b
    # Execute backend functionalities. Notice that there are
e5750b
    # functionalities that need more than one action value in order to
b45dde
    # be executed (e.g.,  copying, and renaming), functionalities
e5750b
    # that need just one action value to be executed (e.g.,
b45dde
    # documentation reading and edition) and functionalities that
b45dde
    # don't need action value at all (e.g., searching and updating
b45dde
    # output files). This way, the execution of backend
b45dde
    # functionalities is splitted here.
e5750b
    if [[ $ACTIONNAM =~ "${FLAG_BACKEND}_(copy|rename|delete)Entry" ]];then
5ec287
b45dde
        # Define directories where documentation entries are stored
b45dde
        # in.  Since more than one action value might be affected
b45dde
        # here, more than one directory might be considered as chapter
b45dde
        # directory, as well.
b45dde
        MANUAL_CHAPTER_DIR=$(${FLAG_BACKEND}_getChapterDir "$@")
b45dde
b45dde
        # Syncronize changes between repository and working copy. At
b45dde
        # this point, changes in the repository are merged in the
b45dde
        # working copy and changes in the working copy committed up to
b45dde
        # repository.
b45dde
        cli_syncroRepoChanges ${MANUAL_CHAPTER_DIR}
b45dde
e5750b
        # Execute backend action names that may need to use more than
e5750b
        # one action value.
b45dde
        ${ACTIONNAM} $@
b45dde
b45dde
        # Commit changes from working copy to central repository only.
b45dde
        # At this point, changes in the repository are not merged in
b45dde
        # the working copy, but chages in the working copy do are
b45dde
        # committed up to repository.
b45dde
        cli_commitRepoChanges ${MANUAL_CHAPTER_DIR}
b45dde
b45dde
    elif [[ $ACTIONNAM =~ "${FLAG_BACKEND}_(searchIndex|updateOutputFiles)" ]];then
b45dde
b45dde
        # Bring changes from the repository to the working copy.
b45dde
        cli_updateRepoChanges ${MANUAL_BASEDIR}
b45dde
b45dde
        # Execute backend action names that don't need to use any
b45dde
        # action value as reference to do their work.
b45dde
        $ACTIONNAM
b45dde
b45dde
        # Backend action names that don't need to use any action value
b45dde
        # as reference to do their work are of one-pass only. They are
b45dde
        # executed and then the script execution is finished.
b45dde
        exit
5ec287
5ec287
    else
5ec287
e5750b
        # Execute backend action names that use one action value, only.
b45dde
        for ACTIONVAL in $@;do
b45dde
        
b45dde
            # Define directories where documentation entries are
b45dde
            # stored in.  Since just one action value is
b45dde
            # affected here, just one directory is considered as
b45dde
            # chapter directory, as well.
b45dde
            MANUAL_CHAPTER_DIR=$(${FLAG_BACKEND}_getChapterDir "${ACTIONVAL}")
b45dde
b45dde
            # Define chapter name for documentation entry we're working with.
b45dde
            MANUAL_CHAPTER_NAME=$(basename "$MANUAL_CHAPTER_DIR")
b45dde
b45dde
            # Define documentation entry.
b45dde
            ENTRY=$(${FLAG_BACKEND}_getEntry $ACTIONVAL)
b45dde
b45dde
            # Syncronize changes between repository and working copy.
b45dde
            # At this point, changes in the repository are merged in
b45dde
            # the working copy and changes in the working copy
b45dde
            # committed up to repository.
b45dde
            cli_syncroRepoChanges ${MANUAL_CHAPTER_DIR}
b45dde
b45dde
            # Execute backend action names that may need to use more
b45dde
            # than one action value.
b45dde
            $ACTIONNAM 
b45dde
b45dde
            # Commit changes from working copy to central repository
b45dde
            # only.  At this point, changes in the repository are not
b45dde
            # merged in the working copy, but chages in the working
b45dde
            # copy do are committed up to repository.
b45dde
            cli_commitRepoChanges ${MANUAL_CHAPTER_DIR}
b45dde
e5750b
        done
5ec287
f11f54
    fi
f11f54
b45dde
    # Rebuild output files to propagate recent changes.
b45dde
    ${FLAG_BACKEND}_updateOutputFiles
b45dde
3ae895
    # Perform language-specific actions when the current language is
3ae895
    # other but English language.
3ae895
    if [[ ! $(cli_getCurrentLocale) =~ '^en' ]];then
3ae895
3ae895
        # Update translatable strings in related portable objects.
3ae895
        eval ${CLI_BASEDIR}/${CLI_PROGRAM}.sh locale --update ${MANUAL_BASEFILE}.xhtml --dont-commit-changes
3ae895
3ae895
        # Update translatable strings in related portable objects.
3ae895
        eval ${CLI_BASEDIR}/${CLI_PROGRAM}.sh locale --edit ${MANUAL_BASEFILE}.xhtml
3ae895
3ae895
        # Print separator.
3ae895
        cli_printMessage '-' --as-separator-line
3ae895
3ae895
        # Print action message.
3ae895
        cli_printMessage "${MANUAL_BASEFILE}.xhtml/$(cli_getCurrentLocale)" '--as-updating-line'
3ae895
3ae895
        # Render translated versions of the XHTML output files,
3ae895
        # supressing the rendition output.
3ae895
        eval ${CLI_BASEDIR}/${CLI_PROGRAM}.sh render ${MANUAL_BASEFILE}.xhtml --dont-commit-changes --quiet
3ae895
3ae895
    fi
3ae895
4c79b5
}