#!/bin/sh
SFJP_USER=....
SFJP_PASS=....

TAGNAME="$1"
LOG="$2"

exec_expect() {
  expect_path=`which expect`
  cat <<EOF>/tmp/exec_expect
#!$expect_path
spawn $1;
expect {
  "$2"
    { send "$3\r" }
}
interact
exit
EOF
  chmod 755 /tmp/exec_expect
  /tmp/exec_expect >/dev/null 2>/dev/null
  rm /tmp/exec_expect
}

cd /home/www/pyuki
cd htdocs
mkdir ../tmp
rm -rf ../tmp/DevelopmentEnvironment
mkdir ../tmp/DevelopmentEnvironment
cp -pR ./*  ../tmp/DevelopmentEnvironment
cp -pR ./.ht*  ../tmp/DevelopmentEnvironment
cp -pR attach/.ht*  ../tmp/DevelopmentEnvironment
cp -pR build/.ht*  ../tmp/DevelopmentEnvironment
cp -pR cache/.ht*  ../tmp/DevelopmentEnvironment
cp -pR counter/.ht*  ../tmp/DevelopmentEnvironment
cp -pR diff/.ht*  ../tmp/DevelopmentEnvironment
cp -pR image/.ht*  ../tmp/DevelopmentEnvironment
cp -pR info/.ht*  ../tmp/DevelopmentEnvironment
cp -pR lib/.ht*  ../tmp/DevelopmentEnvironment
cp -pR plugin/.ht*  ../tmp/DevelopmentEnvironment
cp -pR resource/.ht*  ../tmp/DevelopmentEnvironment
cp -pR sample/.ht*  ../tmp/DevelopmentEnvironment
cp -pR session/.ht*  ../tmp/DevelopmentEnvironment
cp -pR skin/.ht*  ../tmp/DevelopmentEnvironment
cp -pR user/.ht*  ../tmp/DevelopmentEnvironment
cp -pR wiki/.ht*  ../tmp/DevelopmentEnvironment
cd ../tmp
cd DevelopmentEnvironment
rm -rf font pyukiwiki release temp archive
cd ..
echo tar cvf DevelopmentEnvironment.tar DevelopmentEnvironment/* DevelopmentEnvironment/.ht*
tar cvf DevelopmentEnvironment.tar DevelopmentEnvironment/* DevelopmentEnvironment/.ht*
rm -rf DevelopmentEnvironment
rm PyukiWikiDevelopmentEnvironment.tar.7z
7za a -t7z -m1=LZMA:d25:fb255 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3 -mx PyukiWikiDevelopmentEnvironment.tar.7z DevelopmentEnvironment.tar
rm DevelopmentEnvironment.tar
cd ../htdocs
rm -rf release
make releasedevel
cd ..
rm -rf CVS
mkdir CVS
cd CVS
echo cvs co
exec_expect "cvs -d:ext:$SFJP_USER@cvs.sourceforge.jp:/cvsroot/pyukiwiki co ." "passphrase" "$SFJP_PASS"
mkdir DevelopmentEnvironment
cp /home/www/pyuki/tmp/PyukiWikiDevelopmentEnvironment.tar.7z DevelopmentEnvironment
echo copy
../cp.sh
if test "$TAGNAME" != ""; then
echo tag set $TAGNAME
exec_expect "cvs tag $TAGNAME" "passphrase" "$SFJP_PASS"
else
#echo tag delete
#exec_expect "cvs -d tag" "passphrase" "$SFJP_PASS"
fi
echo cvs update
exec_expect "cvs update" "passphrase" "$SFJP_PASS"
#exec_expect "cvs commit" "passphrase" "$SFJP_PASS"
echo cvs commit
if test "$LOG" != ""; then
echo -n "Wait cvs commit prompt : "
read a
cvs commit -m"$LOG"
else
echo -n "Wait cvs commit prompt : "
read a
cvs commit
fi
echo
