:
# HOW TO RENAME A TWIKI TOPIC USING THIS SCRIPT:
#
#     Go to the topic you want to rename / delete.
#     Find out the back-links to this page from Ref-By .
#     Modify other topics if needed.
#     Telnet to the TWiki installation.
#     cd to twiki. (eg /usr/local/httpd/twiki)
#     ./renameTopic.sh TheWebName CurrentTopicName NewTopicName
#     Example
#          ./renameTopic.sh CPE releasePlan developmentPlan
#
# Author: Andrew Fuqua

# VALIDATE INPUT

if ! [ $# == 3 ]; then
   echo
   echo Usage: renameTopic.sh WebName CurrentTopicName NewTopicName
   echo
   exit 1
fi

if ! [ -d data/$1 ]; then
   echo
   echo The web \'$1\' does not exist. Cannot continue.
   echo
   exit 1
fi

if ! [ -f data/$1/$2.txt ]; then
   echo
   echo The topic \'$1.$2\' does not exist. Cannot continue.
   echo
   exit 1
fi

if [ -f data/$1/$3.txt ]; then
   echo
   echo The topic \'$1.$3\' already exists. Cannot continue.
   echo
   exit 1
fi

mv data/$1/$2.txt data/$1/$3.txt
mv data/$1/$2.txt,v data/$1/$3.txt,v
mv data/$1/$2.lock data/$1/$3.lock

sed -e "s/^$2   /$3     /" data/$1/.changes > data/$1/.changes

# Uploaded files are kept in pub, but if a topic has no
# files, it might not have a directory under pub.
# So if the directory doesn't exist, it's ok, it's not
# an error.
if [ -d pub/$1/$2 ]; then
   rename pub/$1/$2 pub/$1/$3
fi

echo DONE!
echo          
