Blame Scripts/Bash/Style/replaceInFiles.sh

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# Use this script to update svg metadata information massively, based
4c79b5
# on one Tpl file. To use this script you need to be located inside
4c79b5
# the artwork component you want to update. For example if you want to
4c79b5
# update the svg metadata information used by CentOS Brands files, you
4c79b5
# type: 
4c79b5
#
4c79b5
#  cd ~/artwork/trunk/Identity/Brands
4c79b5
#
4c79b5
#  first, and later
4c79b5
#
4c79b5
#  ~/artwork/trunk/Scripts/Bash/Style/replaceInFiles '.*\.svg$'
4c79b5
#
4c79b5
# At this point you select the translation file you want to apply to
4c79b5
# all files matching the regular expression you defined as first
4c79b5
# argument ('.*\.svg$') in the above command. The svg metadata
4c79b5
# translation file used for CentOS Brands' svg file is:
4c79b5
# svg-metadata-centos.sed. Pick that and press return to go on. After
4c79b5
# that, if you are using subversion, use the following command to see
4c79b5
# changes:
4c79b5
#
4c79b5
#  svn diff | less
4c79b5
#
4c79b5
# Note that inside trunk/Scripts/Bash/Style/Tpl directory you can find
4c79b5
# standard translation files that you can apply to files. In order to
4c79b5
# have the appropriate result, it is important that you know what
4c79b5
# translation file you apply to which file. As convenction each
4c79b5
# translation file inside the above location have a comment on the
4c79b5
# first lines describing which kind of files they apply to.
4c79b5
#
4c79b5
# Copyright (C) 2009-2010 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation; either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
4c79b5
# $Id: replaceInFiles.sh 12 2010-09-10 09:55:08Z al $
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
REGEX=$1
4c79b5
TRANSLATIONS=~/artwork/trunk/Scripts/Bash/Style/Tpl
4c79b5
4c79b5
# Define translation file.
4c79b5
cli_printMessage "`gettext "Select the translation you want to apply:"`"
4c79b5
select TRANSLATION in $(ls $TRANSLATIONS);do
4c79b5
   TRANSLATION=$TRANSLATIONS/$TRANSLATION
4c79b5
   break
4c79b5
done
4c79b5
4c79b5
# Check regular expression.
4c79b5
if [ $REGEX == '' ];then
4c79b5
   cli_printMessage "`gettext "You need to provide a regular expression as first argument."`"
4c79b5
   exit
4c79b5
fi
4c79b5
4c79b5
# Check translation file.
4c79b5
if [ ! -f $TRANSLATION ];then
4c79b5
   cli_printMessage "`gettext "You need to provide a valid translation file."`"
4c79b5
   exit
4c79b5
fi
4c79b5
4c79b5
# Define keywords using repo path as base.
4c79b5
PATH_KEYWORDS=$(pwd | cut -d/ -f6- | tr '/' '\n')
4c79b5
4c79b5
# Redifine keywords using SVG standard format.
4c79b5
SVG_KEYWORDS=$(\
4c79b5
   for KEY in $PATH_KEYWORDS;do
4c79b5
      echo "            <rdf:li>$KEY</rdf:li>\\"
4c79b5
   done)
4c79b5
4c79b5
for FILE in $(find . -regextype posix-egrep -regex $REGEX);do
4c79b5
   cli_printMessage $FILE "AsUpdatingLine"
4c79b5
   sed -i -r -f $TRANSLATION $FILE
4c79b5
   sed -i -r -e /=KEYWORDS=/c\\"$SVG_KEYWORDS" $FILE
4c79b5
done \
4c79b5
   | awk 'BEGIN {FS=": "} \
4c79b5
      { if ( $0 ~ /^-+$/ ) print $0; else \
4c79b5
         printf "%s: \t%s\n", $1, $2 }'