#!/bin/ksh

VERSION=`cat configure.ac | grep AM_INIT_AUTOMAKE | awk -F, '{print $2}' | tr -d ')' | tr -d ' '` 
clear
echo "-----------------------------------------------------------"
echo "Spine packager for spine version $VERION"
echo "spine-$VERSION.tar.gz will be placed in /tmp"
echo "--------------------------------------------------------------"
echo "Spine package process is beginnning"
echo "--------------------------------------------------------------"
echo "NOTE: Removing hardware specific directories"
rm -rf autom4te.cache .deps

# ----------------------------------------------------------
# Get rid of nasty Microsoftisms
# ----------------------------------------------------------
if [ `which dos2unix` != "" ]; then
  echo "--------------------------------------------------------------"
  echo "NOTE: Performing a dos2unix conversion of all files"
  for FILE in `ls`; do 
    if [ ! -d $FILE ]; then
      dos2unix $FILE > /dev/null 2>&1
    fi
  done
  
  for FILE in `ls config`; do
    if [ -d $FILE ]; then
      dos2unix $FILE > /dev/null 2>&1
    fi
  done
else
  echo "--------------------------------------------------------------"
  echo "NOTE: dos2unix not found, not double checking file formats"
fi

# ----------------------------------------------------------
# Make sure things are executable if they exist
# ----------------------------------------------------------
echo "--------------------------------------------------------------"
echo "NOTE: Setting some permissions"
[ -f ./configure ] && chmod +x configure

# ----------------------------------------------------------
# Perform packaging
# ----------------------------------------------------------
rm -rf /tmp/cacti-spine-$VERSION /tmp/cacti-spine-$VERSION.*
svn export . /tmp/cacti-spine-$VERSION
cd /tmp
tar -zcf  cacti-spine-$VERSION.tar.gz cacti-spine-$VERSION
zip -lrq cacti-spine-$VERSION.zip cacti-spine-$VERSION/*
rm -rf /tmp/cacti-spine-$VERSION
cd -
echo "--------------------------------------------------------------"
echo "NOTE: Done!!!"
echo "--------------------------------------------------------------"

