#!/bin/sh
ARCH=`arch`
if [ "$ARCH" != "x86_64" ]; then
  ARCH=""
fi
LATEST_VER=`ls hsfmodem*${ARCH}full.tar.gz | tail -n 1 | sed "s/hsfmodem-\(.*\)${ARCH}full\.tar\.gz/\1/"`

[ -n "$LATEST_VER" ] || { echo -e "\nERROR: Cannot find Linuxant HSF modem driver for your architecture.\nYou can download the latest TAR version from: \n\thttp://www.linuxant.com/drivers/hsf/full/downloads.php"; exit 1; }

echo "HSF Modem Driver latest version in this directory: $LATEST_VER"
tar xf hsfmodem-${LATEST_VER}${ARCH}full.tar.gz 
tar xf hsfmodem-7.68.00.09${ARCH}oem.tar.gz 
mv hsfmodem-${LATEST_VER}${ARCH}full hsfmodem-${LATEST_VER}${ARCH}oem
mv hsfmodem-${LATEST_VER}${ARCH}oem/modules/imported/ .
mv hsfmodem-7.68.00.09${ARCH}oem/modules/imported/ hsfmodem-${LATEST_VER}${ARCH}oem/modules/
mv imported/include/{framewrk,osservices}.h hsfmodem-${LATEST_VER}${ARCH}oem/modules/imported/include/
sed -i "s|4full|4oem|g" hsfmodem-${LATEST_VER}${ARCH}oem/hsfmodem.spec
tar czf hsfmodem-${LATEST_VER}${ARCH}oem.tar.gz hsfmodem-${LATEST_VER}${ARCH}oem/
rpmbuild -tb hsfmodem-${LATEST_VER}${ARCH}oem.tar.gz
rm -rf hsfmodem-7.68.00.09${ARCH}oem hsfmodem-${LATEST_VER}${ARCH}oem imported/ 

