summaryrefslogtreecommitdiff
path: root/localezmangle
blob: 1164b69edb84eb3eb99f3d028e42b19614a56b91 (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.5 2002-12-03 01:43:12 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. if [ -d "$targetdir" ]; then
  48. echo "ERROR: targetdir exists and origdir provided! (either remove targetdir"
  49. echo "or only update existing targetdir (by not providing origdir option)."
  50. echo "Exiting...!"
  51. exit 1
  52. fi
  53. # Isolate all template files
  54. 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
  55. elif [ -d "$targetdir" ]; then
  56. echo "NOTICE: origdir not provided. Working with existing targetdir..."
  57. else
  58. echo "ERROR: origdir not provided, and targetdir doesn't exist. Exiting...!"
  59. exit 1
  60. fi
  61. # rename origname to targetname (ignored on multiple runs)
  62. for x in `cd $targetdir && find * -name "*$origname*"`; do
  63. mv $targetdir/$x $targetdir/`echo $x | sed "s $origname $targetname g"`
  64. done
  65. if [ ! -f $sedrules ]; then
  66. exit 1
  67. fi
  68. # Use super-sed if available (wins a few seconds)
  69. ssed=`which ssed`
  70. # TODO: only touch file if mangled
  71. for file in `find $targetdir -type f`; do
  72. if [ -n "$ssed" ]; then
  73. cat $file | $ssed -f $sedrules -i $file
  74. else
  75. cat $file | sed -f $sedrules > $file.tmp
  76. mv $file.tmp $file
  77. fi
  78. done
  79. echo "Done. Now patch manually with the .diff (if any)..."