Blame Scripts/Bash/Functions/Tuneup/Svg/svg_doMetadata.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# svg_doMetadata.sh -- This function updates metadata values inside
878a2b
# scalable vector graphic (SVG) files using default values from The
878a2b
# CentOS Project.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function svg_doMetadata {
878a2b
878a2b
    # Define template file name.
878a2b
    local TEMPLATE="${TUNEUP_CONFIG_DIR}/metadata.sed"
878a2b
878a2b
    # Check template file existence.
eb0622
    cli_checkFiles -e $TEMPLATE
878a2b
878a2b
    # Build title from file path.
878a2b
    local TITLE=$(basename "$FILE")
878a2b
878a2b
    # Build url from file path.
878a2b
    local URL=$(echo $FILE | sed 's!/home/centos!https://projects.centos.org/svn!')
878a2b
878a2b
    # Build keywords from file path. Do not include filename, it is
878a2b
    # already on title.
878a2b
    local KEY=''
878a2b
    local KEYS=$(dirname "$FILE" | cut -d/ -f6- | tr '/' '\n')
878a2b
878a2b
    # Build keywords using SVG standard format. Note that this
878a2b
    # information is inserted inside template file. The template file
878a2b
    # is a replacement set of sed commands so we need to escape the
878a2b
    # new line of each line using one backslash (\). As we are doing
878a2b
    # this inside bash, it is required to escape the backslash with
878a2b
    # another backslash so one of them passes literally to template
878a2b
    # file.
878a2b
    KEYS=$(\
878a2b
        for KEY in $KEYS;do
878a2b
            echo "            <rdf:li>$KEY</rdf:li>\\"
878a2b
        done)
878a2b
878a2b
    # Redefine template instance file name.
878a2b
    local INSTANCE=$(cli_getTemporalFile $TEMPLATE)
878a2b
878a2b
    # Create instance.
878a2b
    cp $TEMPLATE $INSTANCE
878a2b
878a2b
    # Check template instance. We cannot continue if the template
878a2b
    # instance couldn't be created.
eb0622
    cli_checkFiles -e $INSTANCE
878a2b
878a2b
    # Expand translation markers inside template instance.
878a2b
    sed -r -i \
878a2b
        -e "s!=TITLE=!$TITLE!" \
878a2b
        -e "s!=URL=!$URL!" \
878a2b
        -e "s!=DATE=!$(date "+%Y-%m-%d")!" $INSTANCE
878a2b
    sed -i -r "/=KEYWORDS=/c\\${KEYS}" $INSTANCE
878a2b
    sed -i -r 's/>$/>\\/g' $INSTANCE
878a2b
    cli_expandTMarkers $INSTANCE
878a2b
878a2b
    # Update scalable vector graphic using template instance.
878a2b
    sed -i -f $INSTANCE $FILE
878a2b
878a2b
    # Remove template instance.
878a2b
    if [[ -f $INSTANCE ]];then
878a2b
        rm $INSTANCE
878a2b
    fi
878a2b
878a2b
    # Sanitate scalable vector graphic.
878a2b
    sed -i -r '/^[[:space:]]*$/d' $FILE
878a2b
878a2b
}