#!/bin/sh

set -e

TMP=tmp.build_gpl_release
NOW=`date +%Y-%m-%d`
DIR=hostap-$NOW

REMOVE="build_gpl_release todo.lst Prism2-HW.txt"
REMOVE_DIRS="testing www"

if [ -r $TMP ]; then
    echo "Temporary directory '$TMP' exists. Remove it before running this."
    exit 1
fi

mkdir $TMP
cd $TMP

cvs export -D now -d "$DIR" hostap

cd "$DIR"
if [ -n "$REMOVE" ]; then
    rm $REMOVE
fi
if [ -n "$REMOVE_DIRS" ]; then
    rm -r $REMOVE_DIRS
fi

CONF=driver/modules/hostap_config.h
sed "s/\(^#define PRISM2_VERSION \"[^ ]* \)CVS/\1$NOW/" < $CONF > $CONF.tmp &&
    mv $CONF.tmp $CONF

VER=`grep "^#define PRISM2_VERSION" $CONF`
echo "Version: $VER"
DATE=`echo "$VER" | cut -d" " -f4 | tr -d \"`

if [ "$DATE" != "$NOW" ]; then
    echo "NOTE! Date mismatch: $DATE != $NOW"
fi

cd ..
tar czf ../$DIR.tar.gz $DIR
cd ..
rm -r $TMP
ls -l $DIR.tar.gz
