From e682ce4a8dc198730ab175cedf7a80a517f81e37 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Tue, 3 Dec 2002 00:50:45 +0000 Subject: Add new script localezmangle: Extract, rename and auto-mangle eZ Publish 2.2.x templates and languages. --- localezmangle | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 localezmangle (limited to 'localezmangle') diff --git a/localezmangle b/localezmangle new file mode 100755 index 0000000..e39dd74 --- /dev/null +++ b/localezmangle @@ -0,0 +1,78 @@ +#!/bin/sh +# +# /usr/local/bin/localezmangle +# Copyright 2001-2002 Jonas Smedegaard +# +# $Id: localezmangle,v 1.1 2002-12-03 00:50:45 jonas Exp $ +# +# Extract, rename and auto-mangle eZ Publish 2.2.x templates and languages +# + +#set -e + +prg=`basename $0` + +if [ -z "$1" -o -z "$2" -o -z "$3" ]; then + echo "$prg: Extract, rename and auto-mangle eZ Publish 2.2.x templates and" + echo " languages" + echo + echo "Usage: $prg origname targetname targetdir [origdir [sedfile]]" + echo + echo " origname: String to search for in path + filename." + echo " targetname: Replacement string." + echo " targetdir: Where to store mangled file hierarchy." + echo " origdir: Where to look for files matching ." + echo + echo "If is provided, it is considered a \"first run\":" + echo " is created, and files matching are copied" + echo " and renamed." + echo "If not provided, the file .sed in current dir" + echo " is attempted." + echo + echo "Example: $prg /default/ /mytemplate/ /tmp/my_ez_tpl /var/www/ezsite" + exit 1 +fi + +origname=$1 +targetname=$2 +targetdir=$3 +origdir=$4 +sedrules=`basename $prg .sh`.`echo $targetname | sed 's/[^_[:alnum:]-]//g'`.sed + +if [ ! -f $sedrules ]; then + echo "Warning: sed rulesfile \"$sedrules\" not found. Rename only..." +fi + +if [ -n "$origdir" -a -d "$origdir" ]; then + # Isolate all template files + for x in `cd $origdir && find * -type f | grep -v cache | grep "$origname"`; do mkdir -p $targetdir/`dirname $x`; cp -a $origdir/$x $targetdir/`dirname $x`; done +elif [ -d "$targetdir" ]; then + echo "Notice: origdir not provided. Working with existing targetdir..." +else + echo "Error: origdir not provided, and targetdir doesn't exist. Exiting...!" + exit 1 +fi + +# rename origname to targetname (ignored on multiple runs) +for x in `cd $targetdir && find * -name "*$origname*"`; do + mv $targetdir/$x $targetdir/`echo $x | sed "s $origname $targetname g"` +done + +if [ ! -f $sedrules ]; then + exit 1 +fi + +# Use super-sed if available (wins a few seconds) +ssed=`which ssed` + +# TODO: only touch file if mangled +for file in `find $targetdir -type f`; do + if [ -n "$ssed" ]; then + cat $file | $ssed -f $sedrules -i $file + else + cat $file | sed -f $sedrules > $file.tmp + mv $file.tmp $file + fi +done + +echo "Done. Now patch manually with the .diff (if any)..." -- cgit v1.2.3