#!/bin/bash

version="$1"
tag=$(echo "ldv$version" | sed -s 's/\./-/g')
DDIR=$PWD
#VER="2.6.9-11.EL"
VER="2.6.21.1"

if [ `uname -r` != "$VER" ]; then
  echo "Use $VER kernel!"
  exit 1
fi

if [ -z $version ]; then
  echo -n "Specify version, please, current version is: "
  grep CONFIG_COMBO_VERSION= configure.in | cut -f 2 -d '"'
  exit 1
fi

echo "version = $version, tag = $tag, ok? (Ctrl-C to abort)"
read i

sed -e "s/^CONFIG_COMBO_VERSION=\".*/CONFIG_COMBO_VERSION=\"${version}\"/g" configure.in > configure.in.new
mv configure.in.new configure.in

make clean


cd $DDIR

./svncompile

echo "Continue? (Ctrl-C to abort)"
read i

svn commit -m "linux driver: version $version" configure.in

#cd $DDIR/..
#svn tag -R -F $tag linux
#cvs tag -R -F LAST linux
#cd $DDIR

echo "Copying sources to all machines:"

find $DDIR/build -name "*.ko" -exec chmod a+x {} \;
scp `find $DDIR/build -name "*.ko"` $USER@vidal.ipv4.liberouter.org:/home/shared/liberouter/Linux-2.6.9-11.EL/lib/modules/$VER/kernel/drivers/net/combo6/

#if [ "$VER" != "2.6.9-11.EL" ]; then
#  ./distrib-nkern 2.6.9-11.EL
#fi
if [ "$VER" != "2.6.9-11.ELsmp" ]; then
  ./distrib-nkern 2.6.9-11.ELsmp
fi
if [ "$VER" != "2.6.19.1" ]; then
  ./distrib-nkern 2.6.19.1
fi
if [ "$VER" != "2.6.21.1" ]; then
  ./distrib-nkern 2.6.21.1
fi

exit 0
