#!/bin/sh
#
#
# This script is used to make a Bacula win32 and win64 releases
# 
# It writes in the current directory, so we recommend that you
#  do not run it in the Bacula source or Git directory, but
#  in a special release directory.
#
# Commit all changes, export the release, make a release tar.
#
# source ./config
. ./config

tagbase=Release-
base_pkg=bacula
remote=$2
branch=$3
ver=$4
fulltag=$tagbase$ver

if [ $# != 4 ] ; then
  echo "Need $0 <bacula-source-directory> <remote-name> <branch> <version>"
  echo "e.g. $0 rescue-source bee Branch-4.0 4.0.3"
  exit 1
fi
cd $1
if [ $? -ne 0 ]; then
   echo "Directory: $1 does not exist"
   exit 1
fi
cd bacula
if [ $?  -ne 0 ]; then
   echo "Directory: $1 does not exist"
   exit 1
fi
current=`git branch | awk '/*/ { print $2 }'`
src=`pwd` 
git checkout ${branch}
if [ $? -ne 0 ]; then
   echo "Checkout of branch ${branch} in ${src} failed."
   exit 1
fi
git pull ${remote} ${branch}
echo " "
echo "Making $reltype for Windows $base_pkg-$ver ..."
echo " "
#echo "OK?  ctl-c to stop"
#read a

cd src/win32
rm -f release32/${base_pkg}-win32-$ver.exe
rm -f release64/${base_pkg}-win64-$ver.exe
make clean
cd ../..
./configure --with-sqlite3
cd src/win32
./makeall
cp release32/${base_pkg}-win32-$ver.exe ${cwd}
cp release64/${base_pkg}-win64-$ver.exe ${cwd}
cd ${cwd}
rm -f *.exe.sig
./sign ${base_pkg}-win32-$ver.exe
./sign ${base_pkg}-win64-$ver.exe
ls -l ${base_pkg}-win*.exe*

cd ${src}
# get back to original branch
git checkout ${current}
