#!/bin/sh # # /usr/local/bin/localezmangle # Copyright 2001-2002 Jonas Smedegaard # # $Id: localezmangle,v 1.2 2002-12-03 00:54:05 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=`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)..."