#!/bin/sh # # /usr/local/bin/localezmangle # Copyright 2001-2002 Jonas Smedegaard # # $Id: localezmangle,v 1.5 2002-12-03 01:43:12 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 "Options:" echo " origname: Search string" echo " targetname: Replacement string" echo " targetdir: Where to store mangled file hierarchy" echo " origdir: Where to look for original files" echo echo "1) is created if it doesn't exist. If is" echo "provided it is considered a \"first run\", and files matching" echo " are copied from to ." echo echo "2) Path + filename is matched against and replaced with" echo "." echo echo "3) All files in is run through the sed rulesfile ." echo "If not provided, a filename .sed is constructed" echo "and looked for in current dir." 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 if [ -d "$targetdir" ]; then echo "ERROR: targetdir exists and origdir provided! (either remove targetdir" echo "or only update existing targetdir (by not providing origdir option)." echo "Exiting...!" exit 1 fi # 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)..."