#!/bin/sh

echo "Welcome to Trac2Moin."
echo "This script will use a Trac text file dump to create a subdirectory called MoinMoin, with MoinMoin file structure.  "
echo "One way to create such a dump (works with 0.10.4) is with the following (exact location may vary by distribution): "
echo "   trac-admin /var/local/yourtrac wiki dump /home/yourusername/tracdump"
echo ""
echo "Note that this script will *not* correct the differences in wiki markup - the most important of these being links.  "
echo "Likewise, note that attachments will not be automatically transferred.  Please add those features to this program if "
echo "you know how - thanks!" 
echo ""
echo "Location of your Trac text file dump (MoinMoin subdirectory will be created inside this directory): "
read TRACDIR

cd $TRACDIR

mkdir MoinMoin

for file in `dir -d *` ; do

  echo "MoinMoin/"$file
  mkdir "MoinMoin/"$file
  chmod 770 "MoinMoin/"$file

  mkdir "MoinMoin/"$file"/revisions/"
  chmod 770 "MoinMoin/"$file"/revisions/"

  cp $file "MoinMoin/"$file"/revisions/"
  chmod 660 "MoinMoin/"$file"/revisions/"$file
  mv "MoinMoin/"$file"/revisions/"$file "MoinMoin/"$file"/revisions/00000001"

  touch "MoinMoin/"$file"/current"
  echo "00000001">"MoinMoin/"$file"/current"
  chmod 660 "MoinMoin/"$file"/current"

done

chown -R www-data:www-data MoinMoin

echo "Done!"
echo "Everything is in your Trac dump directory in a subdirectory called MoinMoin.  Copy (as root) the contents of this "
echo "subdirectory into /usr/share/moin/yourwikiname/data/pages/ (location may vary depending on your distribution) and "
echo "make sure the owner and group are still 'www-data' (or whatever username your apache server is using).  If not, "
echo "this can be changed by changing directory to your 'pages' directory and typing (as root):"
echo "chown -R www-data:www-data"
echo "Thanks for using Trac2Moin!"
