summaryrefslogtreecommitdiff
path: root/localezmangle
blob: 88147a9cddb27de15e3fba6bdc968e59fbacd18d (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/bin/localezmangle
  4. # Copyright 2001-2002 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localezmangle,v 1.3 2002-12-03 01:11:25 jonas Exp $
  7. #
  8. # Extract, rename and auto-mangle eZ Publish 2.2.x templates and languages
  9. #
  10. #set -e
  11. prg=`basename $0`
  12. if [ -z "$1" -o -z "$2" -o -z "$3" ]; then
  13. echo "$prg: Extract, rename and auto-mangle eZ Publish 2.2.x templates and"
  14. echo " languages"
  15. echo
  16. echo "Usage: $prg origname targetname targetdir [origdir [sedfile]]"
  17. echo
  18. echo "Options:"
  19. echo " origname: Search string"
  20. echo " targetname: Replacement string"
  21. echo " targetdir: Where to store mangled file hierarchy"
  22. echo " origdir: Where to look for original files"
  23. echo
  24. echo "1) <targetdir> is created if it doesn't exist. If <origname> is"
  25. echo "provided it is considered a \"first run\", and files matching"
  26. echo "<origname> are copied from <origdir> to <targetdir>."
  27. echo
  28. echo "2) Path + filename is matched against <origname> and replaced with"
  29. echo "<targetname>."
  30. echo
  31. echo "3) All files in <targetdir> is run through the sed rulesfile <sedfile>."
  32. echo "If <sedfile> not provided, a filename <targetname>.sed is constructed"
  33. echo "and looked for in current dir."
  34. echo
  35. echo "Example: $prg /default/ /mytemplate/ /tmp/my_ez_tpl /var/www/ezsite"
  36. exit 1
  37. fi
  38. origname=$1
  39. targetname=$2
  40. targetdir=$3
  41. origdir=$4
  42. sedrules=`echo $targetname | sed 's/[^_[:alnum:]-]//g'`.sed
  43. if [ ! -f $sedrules ]; then
  44. echo "Warning: sed rulesfile \"$sedrules\" not found. Rename only..."
  45. fi
  46. if [ -n "$origdir" -a -d "$origdir" ]; then
  47. # Isolate all template files
  48. 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
  49. elif [ -d "$targetdir" ]; then
  50. echo "Notice: origdir not provided. Working with existing targetdir..."
  51. else
  52. echo "Error: origdir not provided, and targetdir doesn't exist. Exiting...!"
  53. exit 1
  54. fi
  55. # rename origname to targetname (ignored on multiple runs)
  56. for x in `cd $targetdir && find * -name "*$origname*"`; do
  57. mv $targetdir/$x $targetdir/`echo $x | sed "s $origname $targetname g"`
  58. done
  59. if [ ! -f $sedrules ]; then
  60. exit 1
  61. fi
  62. # Use super-sed if available (wins a few seconds)
  63. ssed=`which ssed`
  64. # TODO: only touch file if mangled
  65. for file in `find $targetdir -type f`; do
  66. if [ -n "$ssed" ]; then
  67. cat $file | $ssed -f $sedrules -i $file
  68. else
  69. cat $file | sed -f $sedrules > $file.tmp
  70. mv $file.tmp $file
  71. fi
  72. done
  73. echo "Done. Now patch manually with the .diff (if any)..."