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