summaryrefslogtreecommitdiff
path: root/localezmangle
blob: 2be131f076dfd1cf461243cb8fcc91cdf9699153 (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.2 2002-12-03 00:54:05 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 " origname: String to search for in path + filename."
  19. echo " targetname: Replacement string."
  20. echo " targetdir: Where to store mangled file hierarchy."
  21. echo " origdir: Where to look for files matching <origname>."
  22. echo
  23. echo "If <origname> is provided, it is considered a \"first run\":"
  24. echo " <targetdir> is created, and files matching <origname> are copied"
  25. echo " and renamed."
  26. echo "If <sedfile> not provided, the file <targetname>.sed in current dir"
  27. echo " is attempted."
  28. echo
  29. echo "Example: $prg /default/ /mytemplate/ /tmp/my_ez_tpl /var/www/ezsite"
  30. exit 1
  31. fi
  32. origname=$1
  33. targetname=$2
  34. targetdir=$3
  35. origdir=$4
  36. sedrules=`echo $targetname | sed 's/[^_[:alnum:]-]//g'`.sed
  37. if [ ! -f $sedrules ]; then
  38. echo "Warning: sed rulesfile \"$sedrules\" not found. Rename only..."
  39. fi
  40. if [ -n "$origdir" -a -d "$origdir" ]; then
  41. # Isolate all template files
  42. 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
  43. elif [ -d "$targetdir" ]; then
  44. echo "Notice: origdir not provided. Working with existing targetdir..."
  45. else
  46. echo "Error: origdir not provided, and targetdir doesn't exist. Exiting...!"
  47. exit 1
  48. fi
  49. # rename origname to targetname (ignored on multiple runs)
  50. for x in `cd $targetdir && find * -name "*$origname*"`; do
  51. mv $targetdir/$x $targetdir/`echo $x | sed "s $origname $targetname g"`
  52. done
  53. if [ ! -f $sedrules ]; then
  54. exit 1
  55. fi
  56. # Use super-sed if available (wins a few seconds)
  57. ssed=`which ssed`
  58. # TODO: only touch file if mangled
  59. for file in `find $targetdir -type f`; do
  60. if [ -n "$ssed" ]; then
  61. cat $file | $ssed -f $sedrules -i $file
  62. else
  63. cat $file | sed -f $sedrules > $file.tmp
  64. mv $file.tmp $file
  65. fi
  66. done
  67. echo "Done. Now patch manually with the .diff (if any)..."