summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlocalezmangle78
1 files changed, 78 insertions, 0 deletions
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 <dr@jones.dk>
+#
+# $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 <origname>."
+ echo
+ echo "If <origname> is provided, it is considered a \"first run\":"
+ echo " <targetdir> is created, and files matching <origname> are copied"
+ echo " and renamed."
+ echo "If <sedfile> not provided, the file <targetname>.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)..."