#!/bin/bash # Converts a TWiki Extension to a Foswiki Extension if [ $# -ne 1 ] then echo "Usage: `basename $0` Extension_name" echo "You must run the script from a current working directory in which you have the extension to be converted in a subdirectory with the same name as the extension." echo "If the extension is in an SVN checkout and the script finds a directory called .svn in the extension directory, the script with use svn mv commands when converting." exit $E_BADARGS fi curdir=`pwd` # If there is a .svn directory in the extension directory # we assume we are within an SVN checkout and will put svn # in front of the mv commands svncommand='' if [ -d $curdir/$1/.svn ] then svncommand=svn fi #first we change directory names if [ -d $curdir/$1/data/TWiki ] then $svncommand mv $curdir/$1/data/TWiki $curdir/$1/data/System fi if [ -d $curdir/$1/lib/TWiki ] then $svncommand mv $curdir/$1/lib/TWiki $curdir/$1/lib/Foswiki fi if [ -d $curdir/$1/pub/TWiki ] then $svncommand mv $curdir/$1/pub/TWiki $curdir/$1/pub/System fi #name space change all .pm files in contrib and plugins cd $curdir/$1/lib/Foswiki for file in $( find . -type f -name '*.pm') do sed -i.bak -e "s/TWiki::/Foswiki::/g" $file sed -i.bak -e "s/new TWiki\(\);/new Foswiki();/g" $file sed -i.bak -e "s/use TWiki;/use Foswiki;/g" $file sed -i.bak -e "s/twiki\([A-Z][A-Za-z]\+\)/foswiki\1/g" $file sed -i.bak -e "s/'twiki'/'foswiki'/g" $file sed -i.bak -e "s/TWikiCompatibility/FoswikiCompatibility/g" $file sed -i.bak -e 's/&Foswiki::Func::getTwikiWebname()/$Foswiki::cfg{SystemWebName}/g' $file sed -i.bak -e 's/Foswiki::Func::getTwikiWebname()/$Foswiki::cfg{SystemWebName}/g' $file sed -i.bak -e "s/^=begin twiki/=begin TML/g" $file done # First then we update the build contrib files for a plugin if [ -d Plugins ] then cd $curdir/$1/lib/Foswiki/Plugins/$1 sed -i.bak -e "s.^data/TWiki.data/System.g" MANIFEST sed -i.bak -e "s.^pub/TWiki.pub/System.g" MANIFEST sed -i.bak -e "s.^lib\/TWiki.lib/Foswiki.g" MANIFEST sed -i.bak -e "s/TWiki::/Foswiki::/g" build.pl sed -i.bak -e "s/TWiki::/Foswiki::/g" Config.spec sed -i.bak -e "s/new TWiki\(\);/new Foswiki();/g" build.pl sed -i.bak -e "s/TWiki::/Foswiki::/g" DEPENDENCIES fi cd $curdir/$1/lib/Foswiki # Updating build contrib files if it is a contrib if [ -d Contrib ] then cd $curdir/$1/lib/Foswiki/Contrib/$1 sed -i.bak -e "s.^data/TWiki.data/System.g" MANIFEST sed -i.bak -e "s.^pub/TWiki.pub/System.g" MANIFEST sed -i.bak -e "s.^lib\/TWiki.lib/Foswiki.g" MANIFEST sed -i.bak -e "s/TWiki::/Foswiki::/g" build.pl sed -i.bak -e "s/TWiki::/Foswiki::/g" Config.spec sed -i.bak -e "s/new TWiki\(\);/new Foswiki();/g" build.pl sed -i.bak -e "s/TWiki::/Foswiki::/g" DEPENDENCIES fi # name space change pub files for css and js name space changes cd $curdir/$1 if [ -d pub/System/$1 ] then cd $curdir/$1/pub/System/$1 for file in $( find . -type f -name '*.css') do sed -i.bak -e "s/twiki\([A-Z][A-Za-z]\+\)/foswiki\1/g" $file done for file in $( find . -type f -name '*.js') do sed -i.bak -e "s/twiki\([A-Z][A-Za-z]\+\)/foswiki\1/g" $file done fi # name space change templates cd $curdir/$1 if [ -d templates ] then cd $curdir/$1/templates for file in $( find . -type f -name '*.tmpl') do sed -i.bak -e "s/twiki\([A-Z][A-Za-z]\+\)/foswiki\1/g" $file done fi # name space change tools files cd $curdir/$1 if [ -d tools ] then cd $curdir/$1/tools for file in $( find . -type f -name '*') do sed -i.bak -e "s/TWiki::/Foswiki::/g" $file sed -i.bak -e "s/new TWiki\(\);/new Foswiki();/g" $file sed -i.bak -e "s/use TWiki;/use Foswiki;/g" $file sed -i.bak -e "s/twiki\([A-Z][A-Za-z]\+\)/foswiki\1/g" $file done fi # name space the most common things in Data files. # Note you still have to manually do some work cd $curdir/$1 if [ -d data ] then cd $curdir/$1/data/System sed -i.bak -e "s/%TWIKIWEB%\.TWikiPlugins/[[%SYSTEMWEB%.Plugins][Plugins]]/g" $1.txt sed -i.bak -e "s'| Plugin Home: | http://TWiki\.org/cgi-bin/view/Plugins/%TOPIC% |'| Plugin Home: | http://foswiki.org/Extensions/%TOPIC% |'g" $1.txt sed -i.bak -e "s'| Feedback: | http://TWiki\.org/cgi-bin/view/Plugins/%TOPIC%Dev |'| Feedback: | http://foswiki.org/Extensions/%TOPIC%Dev |'g" $1.txt sed -i.bak -e "/TWiki.org\/cgi-bin\/view\/Plugins\/%TOPIC%Appraisal/d" $1.txt sed -i.bak -e "/\[\[TWiki:Plugins\/Benchmark\]\[Benchmarks\]\]/d" $1.txt sed -i.bak -e "s/| TWiki Dependency: | \$TWiki::Plugins::VERSION/| Dependency: | \$Foswiki::Plugins::VERSION/g" $1.txt sed -i.bak -e "s'data/TWiki/'data/System/'g" $1.txt sed -i.bak -e "s'pub/TWiki/'pub/System/'g" $1.txt sed -i.bak -e "s'lib/TWiki/'lib/Foswiki/'g" $1.txt sed -i.bak -e "s/%TWIKIWEB%\.TWikiPreferences/%SYSTEMWEB%.SitePreferences/g" $1.txt sed -i.bak -e "s/%TWIKIWEB%\.TextFormattingRules/%SYSTEMWEB%.TextFormattingRules/g" $1.txt sed -i.bak -e "s/TWiki 4\.0 and up: //g" $1.txt sed -i.bak -e "s/author=\"[^\"]*\"/author=\"ProjectContributor\"/" $1.txt sed -i.bak -e "s/reprev=\"1..\"//" $1.txt fi