#!/bin/bash
##############################################################################
#This is a simple script to update aMsn from CVS
##############################################################################

today=$(date +%Y%m%d)
amsnbz=$(ls *.bz2 | tail -n 1)
if [ -z $amsnbz ]; then
  echo "There is no amsn*.bz2 here..."
  exit 1
fi

mv $amsnbz amsn-old.tar.bz2
amsnbz="amsn-old.tar.bz2"

echo "Uncompressing $amsnbz"
tar xjf $amsnbz

cd msn
echo "Updating amsn..."
cvs -f -q update -d -P "."

cd ../
echo "Regenerating icons..."
convert msn/icons/48x48/msn.png -scale 16x16 amsn.16.png
convert msn/icons/48x48/msn.png -scale 32x32 amsn.32.png
cp msn/icons/48x48/msn.png amsn.48.png

echo "Generating amsn-0.95-$today.tar.bz2"
tar cjf amsn-0.95-$today.tar.bz2 msn

if [ $? -eq 0 ]; then
  echo "Cleaning..."
  rm -rf $amsnbz msn
else
  echo "An error occurred... Please check..."
fi
