#!/bin/bash
updatePath=$1
currentPath=$2

echo "=========Script starts here=========" >> update.log
date >> update.log
echo "Start update... Try to stop pilot-server" >> update.log

rm -rf $updatePath/*.tar.bz2 >> update.log 2>> update.log
rm -rf $updatePath/*.msi >> update.log 2>> update.log
rm -rf $updatePath/Source >> update.log 2>> update.log
echo "Unzip whole package" >> update.log
unzip -j -o $updatePath/*.zip -d $updatePath >> update.log 2>> update.log
rm $updatePath/*.zip >> update.log 2>> update.log

echo "Untar update package" >> update.log
tar xvjf $updatePath/*.tar.bz2 -C "$currentPath" "pilot-server/" >> update.log 2>> update.log
if [ -e "settings.xml" ]
then
        rm -f ./pilot-server/settings.xml >> update.log 2>> update.log
        echo "Settings were removed!" >> update.log
fi
echo "Copy files" >> update.log
cp pilot-server/* "$currentPath" >> update.log 2>> update.log
rm -rf pilot-server* >> update.log 2>> update.log
echo "Try to start server" >> update.log
echo "=========Script ends here=========" >> update.log

