Blame Automation/Modules/Help/Texinfo/texinfo_createChapter.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# texinfo_createChapter.sh -- This function standardizes chapter
Alain Reguera Delgado 8f60cb
# creation insdie the manual structure.
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 texinfo_createChapter {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify chapter directory inside the manual structure.  The
Alain Reguera Delgado 8f60cb
    # chapter directory is where chapter-specific information (e.g.,
Alain Reguera Delgado 8f60cb
    # chapter definition files and sections) are stored in.  If this
Alain Reguera Delgado 8f60cb
    # directory already exist, assume it was created correctly in the
Alain Reguera Delgado 8f60cb
    # past. Otherwise, request confirmation for creating it.
Alain Reguera Delgado 8f60cb
    if [[ -d $MANUAL_CHAPTER_DIR ]];then
Alain Reguera Delgado 8f60cb
        return
Alain Reguera Delgado 8f60cb
    else
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "The following documentation chapter doesn't exist:"`" --as-stdout-line
Alain Reguera Delgado 8f60cb
        cli_printMessage "${MANUAL_CHAPTER_DIR}.${MANUAL_EXTENSION}" --as-response-line
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "Do you want to create it now?"`" --as-yesornorequest-line
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize chapter node, chapter index and chapter title.
Alain Reguera Delgado 8f60cb
    local MANUAL_CHAPTER_NODE=''
Alain Reguera Delgado 8f60cb
    local MANUAL_CHAPTER_TITLE=''
Alain Reguera Delgado 8f60cb
    local MANUAL_CHAPTER_CIND=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Request the user to enter a chapter title.
Alain Reguera Delgado 8f60cb
    cli_printMessage "`gettext "Enter chapter's title"`" --as-request-line
Alain Reguera Delgado 8f60cb
    read MANUAL_CHAPTER_TITLE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Sanitate chapter node, chapter index and chapter title.
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_NODE=$(texinfo_getEntryNode "$MANUAL_CHAPTER_NAME")
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_CIND=$(texinfo_getEntryIndex "$MANUAL_CHAPTER_TITLE")
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_TITLE=$(texinfo_getEntryTitle "$MANUAL_CHAPTER_TITLE")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of template files used to build the chapter main
Alain Reguera Delgado 8f60cb
    # definition files.
Alain Reguera Delgado 8f60cb
    local FILE=''
Alain Reguera Delgado 8f60cb
    local FILES=$(cli_getFilesList "${MANUAL_TEMPLATE_L10N}" \
Alain Reguera Delgado 8f60cb
        --maxdepth='1' \
Alain Reguera Delgado 8f60cb
        --pattern="^.+/Chapters(-menu|-nodes)?\.${MANUAL_EXTENSION}$")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create chapter directory using version control. This is the
Alain Reguera Delgado 8f60cb
    # place where all chapter-specific files will be stored in.
Alain Reguera Delgado 8f60cb
    if [[ ! -d ${MANUAL_CHAPTER_DIR} ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage "${MANUAL_CHAPTER_DIR}" --as-creating-line
Alain Reguera Delgado 8f60cb
        cli_runFnEnvironment vcs --quiet --mkdir ${MANUAL_CHAPTER_DIR}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create chapter-specific files using template files as reference.
Alain Reguera Delgado 8f60cb
    for FILE in $FILES;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify texinfo templates used as based to build the chapter
Alain Reguera Delgado 8f60cb
        # structure.  Be sure they are inside the working copy of The
Alain Reguera Delgado 8f60cb
        # CentOS Artwork Repository (-w) and under version control
Alain Reguera Delgado 8f60cb
        # (-n), too.
Alain Reguera Delgado 8f60cb
        cli_checkFiles ${FILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Redefine the chapter file using the correct name.
Alain Reguera Delgado 8f60cb
        local MANUAL_CHAPTER_FILE=${MANUAL_CHAPTER_DIR}$(basename ${FILE} \
Alain Reguera Delgado 8f60cb
            | sed -r 's,Chapters,,')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Print action name.
Alain Reguera Delgado 8f60cb
        cli_printMessage "${MANUAL_CHAPTER_FILE}" --as-creating-line
Alain Reguera Delgado 8f60cb
        
Alain Reguera Delgado 8f60cb
        # Copy template files into the chapter directory.
Alain Reguera Delgado 8f60cb
        cli_runFnEnvironment vcs --quiet --copy ${FILE} ${MANUAL_CHAPTER_FILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Before expanding chapter information, be sure the slash (/)
Alain Reguera Delgado 8f60cb
    # character be escaped. Otherwise, if the slashes aren't scape,
Alain Reguera Delgado 8f60cb
    # they will be interpreted as sed's separator and might provoke
Alain Reguera Delgado 8f60cb
    # sed to complain.
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_NODE=$(echo "$MANUAL_CHAPTER_NODE" | sed -r 's/\//\\\//g')
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_CIND=$(echo "$MANUAL_CHAPTER_CIND" | sed -r 's/\//\\\//g')
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_TITLE=$(echo "$MANUAL_CHAPTER_TITLE" | sed -r 's/\//\\\//g')
Alain Reguera Delgado 8f60cb
    MANUAL_CHAPTER_NAME=$(echo "$MANUAL_CHAPTER_NAME" | sed -r 's/\//\\\//g')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Expand translation markers inside chapter main definition file.  
Alain Reguera Delgado 8f60cb
    sed -i -r \
Alain Reguera Delgado 8f60cb
        -e "s/=CHAPTER_NODE=/${MANUAL_CHAPTER_NODE}/" \
Alain Reguera Delgado 8f60cb
        -e "s/=CHAPTER_TITLE=/${MANUAL_CHAPTER_TITLE}/" \
Alain Reguera Delgado 8f60cb
        -e "s/=CHAPTER_CIND=/${MANUAL_CHAPTER_CIND}/" \
Alain Reguera Delgado 8f60cb
        -e "s/=CHAPTER_NAME=/${MANUAL_CHAPTER_NAME}/" \
Alain Reguera Delgado 8f60cb
        ${MANUAL_CHAPTER_DIR}.${MANUAL_EXTENSION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove content from `chapter-nodes.texinfo' file to start with a
Alain Reguera Delgado 8f60cb
    # clean node structure. This file is also used to create new
Alain Reguera Delgado 8f60cb
    # documentation entries, but we don't need that information right
Alain Reguera Delgado 8f60cb
    # now (when the chapter structure is created), just an empty copy
Alain Reguera Delgado 8f60cb
    # of the file. The node structure of chapter is created
Alain Reguera Delgado 8f60cb
    # automatically based on action value.
Alain Reguera Delgado 8f60cb
    echo "" > ${MANUAL_CHAPTER_DIR}-nodes.${MANUAL_EXTENSION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Update chapter information inside the manual's texinfo
Alain Reguera Delgado 8f60cb
    # structure.
Alain Reguera Delgado 8f60cb
    texinfo_updateChapterMenu
Alain Reguera Delgado 8f60cb
    texinfo_updateChapterNodes
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}