1#!/bin/sh 2 3# Variable Declaration 4TMP_DIR="/tmp" 5 6# Help Display function 7display_help () { 8 echo "----------------------------------------------------------------------------" 9 echo " Spine Package Script" 10 echo " Attempts to package spine from a repository checkout directory of" 11 echo " spine. If all goes well a tar.gz file will be created." 12 echo "----------------------------------------------------------------------------" 13 echo " Syntax:" 14 echo " ./`basename $0` <Version>" 15 echo "" 16 echo " <Version> - Designated version for build (required)" 17 echo "" 18} 19 20# Sanity checks 21[ ! -e configure.ac ] && echo "ERROR: Your current working directory must be the SVN check out of Spine" && exit -1 22 23if [ "${1}x" = "--helpx" -o "${1}x" = "-hx" ]; then 24 display_help 25 exit 0 26fi 27 28if [ -z "${1}" ]; then 29 echo "" 30 echo "ERROR: Invalid syntax, missing required argument" 31 echo "" 32 display_help 33 exit -1 34fi 35VERSION=${1} 36 37# Perform packaging 38echo "" 39echo "----------------------------------------------------------------------------" 40echo "Spine package builder" 41echo " Version: ${VERSION}" 42echo "----------------------------------------------------------------------------" 43 44# Clean up previous builds 45if [ -e ${TMP_DIR}/cacti-spine-${VERSION} ]; then 46 echo "INFO: Removing previous build ${TMP_DIR}/cacti-spine-${VERSION}..." 47 rm -Rf ${TMP_DIR}/cacti-spine-${VERSION} > /dev/null 2>&1 48 [ $? -gt 1 ] && echo "ERROR: Unable to remove directory: ${TMP_DIR}/cacti-spine-${VERSION}" && exit -1 49fi 50if [ -e ${TMP_DIR}/cacti-spine-${VERSION}.tar.gz ]; then 51 rm -Rf ${TMP_DIR}/cacti-spine-${VERSION}.tar.gz > /dev/null 2>&1 52 [ $? -gt 1 ] && echo "ERROR: Unable to remove file: ${TMP_DIR}/cacti-spine-${VERSION}.tar.gz" && exit -1 53fi 54 55# Copy repository 56mkdir -p ${TMP_DIR}/cacti-spine-${VERSION} > /dev/null 2>&1 57tar -cf - --exclude '.svn' * | (cd ${TMP_DIR}/cacti-spine-${VERSION}; tar -xf -) 58[ $? -gt 0 ] && echo "ERROR: Unable to repository to ${TMP_DIR}/cacti-spine-${VERSION}" && exit -1 59 60# Change working directory 61pushd ${TMP_DIR}/cacti-spine-${VERSION} > /dev/null 2>&1 62 63# Get version from source files, warn if different than defined for build 64SRC_VERSION=`cat configure.ac | grep AM_INIT_AUTOMAKE | awk -F, '{print $2}' | tr -d ')' | tr -d ' '` 65if [ "${SRC_VERSION}" != "${VERSION}" ]; then 66 echo "WARNING: Build version and source version are not the same"; 67 echo "WARNING: Build Version: ${VERSION}" 68 echo "WARNING: Source Version: ${SRC_VERSION}" 69fi 70 71# Call bootstrap 72echo "INFO: call bootstrap..." 73./bootstrap 74 75# Check working directory 76cd .. 77 78# Package it 79echo "INFO: Packaging..." 80tar -zcf cacti-spine-${VERSION}.tar.gz cacti-spine-${VERSION} 81[ $? -gt 1 ] && echo "ERROR: Unable to package" && exit -1 82 83# Change working directory 84popd > /dev/null 2>&1 85 86# Clean up 87echo "INFO: Cleaning up build directory..." 88rm -rf ${TMP_DIR}/cacti-spine-${VERSION} > /dev/null 2>&1 89 90# Display file locations 91echo "INFO: Completed..." 92echo "" 93echo "Package file: ${TMP_DIR}/cacti-spine-${VERSION}.tar.gz" 94echo "" 95 96exit 0 97 98