summaryrefslogtreecommitdiff
path: root/localezmangle
blob: 613e030098d983b72e5c40194c42b48315f006c9 (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.8 2002-12-05 21:41:56 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, the file mangle.<targetname>.sed is looked"
  33. echo "for in current dir."
  34. echo
  35. echo "Examples:"
  36. echo " $prg /default/ /mytemplate/ /tmp/my_ez_tpl /var/www/ezsite"
  37. echo " $prg en_GB en_US_slang ezlang/2.2.7-en_US_slang ez/2.2.7"
  38. exit 1
  39. fi
  40. origname=$1
  41. targetname=$2
  42. targetdir=$3
  43. origdir=$4
  44. sedrules=mangle.`echo $targetname | sed 's/[^_[:alnum:]-]//g'`.sed
  45. if [ ! -f $sedrules ]; then
  46. echo "WARNING: sed rulesfile \"$sedrules\" not found. Rename only..."
  47. fi
  48. if [ -n "$origdir" -a -d "$origdir" ]; then
  49. if [ -d "$targetdir" ]; then
  50. echo "ERROR: targetdir exists and origdir provided! (either remove targetdir"
  51. echo "or only update existing targetdir (by not providing origdir option)."
  52. echo "Exiting...!"
  53. exit 1
  54. fi
  55. # Isolate all template files
  56. 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
  57. elif [ -d "$targetdir" ]; then
  58. echo "NOTICE: origdir not provided. Working with existing targetdir..."
  59. else
  60. echo "ERROR: origdir not provided, and targetdir doesn't exist. Exiting...!"
  61. exit 1
  62. fi
  63. # rename origname to targetname (ignored on multiple runs)
  64. for x in `cd $targetdir && find * -type d | sed 's!$!/!' | grep "$origname"`; do
  65. mv $targetdir/$x $targetdir/`echo $x | sed -e "s $origname $targetname g" -e 's!/$!!'`
  66. done
  67. for x in `cd $targetdir && find * -not -type d | grep "$origname"`; do
  68. mv $targetdir/$x $targetdir/`echo $x | sed "s $origname $targetname g"`
  69. done
  70. if [ ! -f $sedrules ]; then
  71. exit 1
  72. fi
  73. # Use super-sed if available (wins a few seconds)
  74. ssed=`which ssed`
  75. # TODO: only touch file if mangled
  76. for file in `find $targetdir -type f`; do
  77. if [ -n "$ssed" ]; then
  78. cat $file | $ssed -f $sedrules -i $file
  79. else
  80. cat $file | sed -f $sedrules > $file.tmp
  81. mv $file.tmp $file
  82. fi
  83. done
  84. echo "Done. Now patch manually using mangle.$targetname.diff (if available)..."