#!/bin/bash

#
# converts a site's file storage to be compatible with bamboo
# version 0.3 and later.
#


if [ ! -d $1 ]; then
   echo "Usage: $0 <site directory>"
   exit
fi

cd $1
if [ ! -f 'site.prop' ]; then
  echo "The directory $1 does not appear to be a bamboo site"
  exit
fi

for f in `find . -type f`; do

filename=`basename $f`
case "$filename" in
  "content.en.txt")  new="b.en.txt";;
  "content.en.html") new="b.en.html";;
  "content.en.php")  new="b.en.php";;
  "content.es.txt")  new="b.es.txt";;
  "content.es.html") new="b.es.html";;
  "content.es.php")  new="b.es.php";;
  "content.pt.txt")  new="b.pt.txt";;
  "content.pt.html") new="b.pt.html";;
  "content.pt.php")  new="b.pt.php";;
  "basic.prop")      new="b.basic";;
  "inherit.prop")    new="b.inherit";;
  "order")           new="b.order";;
  "index.sqlite")    new="b.index.sqlite";;
  "site.prop")       new="b.site";;
  *)                 new="";;
esac

if [ "$new" != "" ]; then
  dir=`dirname $f`
  mv $f $dir/$new
else
  echo "skipping $f"
fi

done

echo "Finished upgrading bamboo site."

