File susexsl-fetch-source of Package suse-xsl-stylesheets

#!/bin/bash
#
# Create suse-xsl-stylesheet source tarball from SVN
#
# Copyright (C) 2011,2012 Frank Sundermeyer <fsundermeyer@opensuse.org>
#
# Author:
# Frank Sundermeyer <fsundermeyer@opensuse.org>

#set -x

NAME=suse-xsl-stylesheets
VERSION=
SPECFILE=${NAME}.spec
SRC_DIR=suse
NOVDOC_DIR=schema
SVNPATH=svn://svn.code.sf.net/p/daps/svn/trunk/daps
TMPDIR=$(mktemp -q -d --tmpdir susexsl_XXXXXXXX)
EXCLUDES=${TMPDIR}/${NAME}/${SRC_DIR}/packaging/exclude-files_for_susexsl_package.txt

#----------
# Functions
#----------

# exit on error
#
function exit_on_error {
    echo -e "$1"
    #rm -rf $TMPDIR
    exit 1
}
#-----
# MAIN
#-----
#
# This script needs to be called from the suse-xsl-stylesheet osc checkout
# directory, so lets check whethter we are in the correct directory
#
if [[ ! -s ${NAME}.spec && ! -d .osc ]]; then
    echo "Looks like you are not in the ${NAME} checkout directory."
    read -p "Continue anyway (y/n) [n]: " CONT
    if [[ n = $CONT || N = $CONT ]]; then
        exit_on_error "Aborted by user."
    fi
fi

#
# Export daps from SVN 
#
svn export -q $SVNPATH ${TMPDIR}/${NAME} || exit_on_error "SVN export failed"

#
# Get the version number
#
VERSION=$(egrep "^Version:\s*" ${TMPDIR}/${NAME}/${SRC_DIR}/packaging/$SPECFILE | sed 's/^Version:\s*//')

if [[ -z $VERSION ]]; then
    exit_on_error "Couldn't get version number from spec-file."
fi

#
# Create the tarball
#
export BZIP2=--best
tar cfh ${NAME}-${VERSION}.tar -C ${TMPDIR}/${NAME} \
    --exclude-from=$EXCLUDES --transform=s:suse/:suse-xsl-stylesheets/: \
    ${SRC_DIR} || exit_on_error "Failed to create the tarball."
# suse/aspell is excluded from tarball, because we only need one file, which we
# manually add here
tar rf ${NAME}-${VERSION}.tar -C ${TMPDIR}/${NAME} \
    --transform=s:suse:suse-xsl-stylesheets: \
    ${SRC_DIR}/aspell/suse_aspell.rws || exit_on_error "Failed to add aspell dictionary to the tarball."
bzip2 -9f ${NAME}-${VERSION}.tar
echo "Successfully created ${NAME}-${VERSION}.tar.bz2"

#
# Copy the spec file if necessary
#
diff -q $SPECFILE ${TMPDIR}/${NAME}/${SRC_DIR}/packaging/$SPECFILE >/dev/null
if [[ 0 = $? ]]; then
    echo "spec file is up-to-date"
else
    cp ${TMPDIR}/${NAME}/${SRC_DIR}/packaging/$SPECFILE . || exit_on_error "Failed to copy the specfile."
    echo "Successfully updated the spec file."
fi
    
rm -rf ${TMPDIR}

exit 0