:
# HOW TO MOVE A TWIKI TOPIC to a different web USING THIS SCRIPT:
#
#     Go to the topic you want to move.
#     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)
#     ./mvTopic.sh TheTopicToMove CurrentWeb NewWeb
#     Example
#          ./mvTopic.sh BackOrifice CPE Glossary
#
# Author: Andrew Fuqua

# VALIDATE INPUT

if ! [ $# == 3 ]; then
   echo
   echo Usage: mvTopic.sh TheTopicToMove CurrentWeb NewWeb
   echo
   exit 1
fi

if ! [ -d data/$2 ]; then
   echo
   echo The web \'$2\' does not exist. Cannot continue.
   echo
   exit 1
fi

if ! [ -d data/$3 ]; then
   echo
   echo The web \'$3\' does not exist. Cannot continue.
   echo
   exit 1
fi

if ! [ -f data/$2/$1.txt ]; then
   echo
   echo The topic \'$2.$1\' does not exist. Cannot continue.
   echo
   exit 1
fi

if [ -f data/$3/$1.txt ]; then
   echo
   echo The topic \'$3.$1\' already exists. Cannot continue.
   echo
   exit 1
fi
                     
mv data/$2/$1.txt data/$3/$1.txt
mv data/$2/$1.txt,v data/$3/$1.txt,v
mv data/$2/$1.lock data/$3/$1.lock

# 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/$2/$1 ]; then
   mkdir pub/$3
   mv pub/$2/$1 pub/$3
   rmdir pub/$2/$1
fi

echo DONE!   
