#!/bin/sh
#120801 download Woof.
#this code is clumsy, had to checkout, then set some parameters in repo, then erase and checkout again.
#One optional parameter, 'update'.

if [ $1 ];then
 case $1 in
  *update)
   [ ! -d woofx ] && exit 2
   cd woofx
   fossil status >/dev/null
   [ $? -ne 0 ] && fossil open ../woofx.fossil
   fossil update
   [ $? -ne 0 ] && exit 3
  ;;
  *help)
   echo "Current directory must be in a Linux filesystem."
   echo "The Woof repository will be downloaded as file 'woofx.fossil' and"
   echo "checked-out into directory 'woofx'."
   echo "Option passed parameter 'update' will update 'woofx.fossil' from the
online Woof repository and update files in 'woofx' directory."
  ;;
 esac
 exit 0
fi

if [ -d woofx ];then
 cd woofx
 fossil close --force 2>/dev/null
 cd ..
 rm -rf woofx
fi
rm -f woofx.fossil 2>/dev/null
rm -f Woof2-*.tar.gz 2>/dev/null
rm -rf Woof2-* 2>/dev/null
sync

fossil clone --admin-user MrSmith http://bkhome.org/fossil/woof2.cgi woofx.fossil
sync

mkdir -p woofx

cd woofx
fossil open ../woofx.fossil
fossil setting allow-symlinks yes
fossil setting editor defaulttexteditor
fossil setting web-browser defaultbrowser
fossil setting dont-push yes #prevent pushing to online repo.
fossil setting autosync no
sync
fossil close
if [ ! -f merge2out ];then
 echo "There has been an error downloading the Woof repository, aborting."
 exit 1
fi
cd ..

rm -rf woofx/*
sync
cd woofx
fossil open ../woofx.fossil
sync
echo "Success."
exit 0
