Blame Automation/Modules/Tuneup/Svg/svg_doMetadata.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_doMetadata.sh -- This function updates metadata values inside
Alain Reguera Delgado 8f60cb
# scalable vector graphic (SVG) files using default values from The
Alain Reguera Delgado 8f60cb
# CentOS Project.
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 svg_doMetadata {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define template file name.
Alain Reguera Delgado 8f60cb
    local TEMPLATE="${TUNEUP_CONFIG_DIR}/metadata.sed"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Check template file existence.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e $TEMPLATE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build title from file path.
Alain Reguera Delgado 8f60cb
    local TITLE=$(basename "$FILE")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build url from file path.
Alain Reguera Delgado 8f60cb
    local URL=$(echo $FILE | sed 's!/home/centos!https://projects.centos.org/svn!')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build keywords from file path. Do not include filename, it is
Alain Reguera Delgado 8f60cb
    # already on title.
Alain Reguera Delgado 8f60cb
    local KEY=''
Alain Reguera Delgado 8f60cb
    local KEYS=$(dirname "$FILE" | cut -d/ -f6- | tr '/' '\n')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build keywords using SVG standard format. Note that this
Alain Reguera Delgado 8f60cb
    # information is inserted inside template file. The template file
Alain Reguera Delgado 8f60cb
    # is a replacement set of sed commands so we need to escape the
Alain Reguera Delgado 8f60cb
    # new line of each line using one backslash (\). As we are doing
Alain Reguera Delgado 8f60cb
    # this inside bash, it is required to escape the backslash with
Alain Reguera Delgado 8f60cb
    # another backslash so one of them passes literally to template
Alain Reguera Delgado 8f60cb
    # file.
Alain Reguera Delgado 8f60cb
    KEYS=$(\
Alain Reguera Delgado 8f60cb
        for KEY in $KEYS;do
Alain Reguera Delgado 8f60cb
            echo "            <rdf:li>$KEY</rdf:li>\\"
Alain Reguera Delgado 8f60cb
        done)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Redefine template instance file name.
Alain Reguera Delgado 8f60cb
    local INSTANCE=$(cli_getTemporalFile $TEMPLATE)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Create instance.
Alain Reguera Delgado 8f60cb
    cp $TEMPLATE $INSTANCE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Check template instance. We cannot continue if the template
Alain Reguera Delgado 8f60cb
    # instance couldn't be created.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e $INSTANCE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Expand translation markers inside template instance.
Alain Reguera Delgado 8f60cb
    sed -r -i \
Alain Reguera Delgado 8f60cb
        -e "s!=TITLE=!$TITLE!" \
Alain Reguera Delgado 8f60cb
        -e "s!=URL=!$URL!" \
Alain Reguera Delgado 8f60cb
        -e "s!=DATE=!$(date "+%Y-%m-%d")!" $INSTANCE
Alain Reguera Delgado 8f60cb
    sed -i -r "/=KEYWORDS=/c\\${KEYS}" $INSTANCE
Alain Reguera Delgado 8f60cb
    sed -i -r 's/>$/>\\/g' $INSTANCE
Alain Reguera Delgado 8f60cb
    cli_expandTMarkers $INSTANCE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Update scalable vector graphic using template instance.
Alain Reguera Delgado 8f60cb
    sed -i -f $INSTANCE $FILE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove template instance.
Alain Reguera Delgado 8f60cb
    if [[ -f $INSTANCE ]];then
Alain Reguera Delgado 8f60cb
        rm $INSTANCE
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Sanitate scalable vector graphic.
Alain Reguera Delgado 8f60cb
    sed -i -r '/^[[:space:]]*$/d' $FILE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}