Blame Scripts/Functions/Render/render_doLastActions.sh

c979f9
#!/bin/bash
c979f9
#
2a9294
# render_doLastActions.sh -- This function provides last-rendition
2a9294
# actions to files produced as result of base-rendition and
2a9294
# post-rendition output. Actions take place through any command you
2a9294
# specify in the `--last-rendition' option  (e.g., the `mogrify'
2a9294
# command from ImageMagick tool set.
c979f9
#
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
c979f9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c979f9
# General Public License for more details.
c979f9
#
c979f9
# You should have received a copy of the GNU General Public License
c979f9
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
c979f9
# ----------------------------------------------------------------------
c979f9
# $Id$
c979f9
# ----------------------------------------------------------------------
c979f9
ab1d67
function render_doLastActions {
c979f9
8af4d8
    # Verify position of file being produced in the list of files been
8af4d8
    # currently processed.
9b8686
    if [[ $THIS_FILE_DIR == $NEXT_FILE_DIR ]];then
9b8686
        return
9b8686
    fi
c979f9
2a9294
    # Define file extensions the last-rendition action will be applied
2a9294
    # to.
2a9294
    local EXTENSION=$(render_getConfigOption "$ACTION" '2')
c979f9
2a9294
    # Define the command string that will be evaluated as last-rendition.
2a9294
    local COMMAND=$(render_getConfigOption "$ACTION" '3-')
c979f9
2a9294
    # Define list of files the last-rendition action will be applied
2a9294
    # to.
2a9294
    local FILE=''
2a9294
    local FILES=$(cli_getFilesList $OUTPUT --pattern=".+\.${EXTENSION}")
2a9294
2a9294
    for FILE in $FILES;do
2a9294
2a9294
        # Identify file before processing it. Only formats recognized
2a9294
        # by ImageMagick are supported. In case the file isn't
2a9294
        # supported by ImageMagick, continue with the next file in the
2a9294
        # list.
2a9294
        identify -quiet ${FILE} > /dev/null
2a9294
        if [[ $? -ne 0 ]];then
2a9294
            continue
2a9294
        fi
2a9294
2a9294
        # Print action message.
2a9294
        cli_printMessage "${FILE}" --as-updating-line
2a9294
2a9294
        # Execute mogrify action on all files inside the same
2a9294
        # directory structure.
2a9294
        eval ${COMMAND} ${FILE}
2a9294
2a9294
        # Be sure the command was executed correctly. Otherwise stop
2a9294
        # script execution.
2a9294
        if [[ $? -ne 0 ]];then
2a9294
            exit
2a9294
        fi
2a9294
2a9294
    done
c979f9
c979f9
}