File update.sh of Package gpicsync

#!/bin/sh
#
# Updates source source and creates a tar file with the 
# correct version and svn revision number
#
# TODO:
#   - automatically update the version info in the spec file
#   - automatically put sources in place for RPM build
#   - use command line tools for suse build service to automatically
#     upload the sources and kick off a new build
#

BASE_NAME=gpicsync
TMP_FILE=/tmp/${BASE_NAME}_co.txt
MJVER=""
REV=""

# Remove old links if they exits.
for I in $(find -type l | grep -e "${BASE_NAME}-[[:digit:]]*$"); do
 rm -v $I
done

# Update/checkout code and set revision.
if [ -d ${BASE_NAME} ]; then
   cd ${BASE_NAME}
   svn update > ${TMP_FILE} 2>&1
   REV=$(grep -E "^Updated|^Checked|^At.*revision[[:space:]]*[[:digit:]]*" ${TMP_FILE} | \
         sed -n -e 's/^.*revision[[:space:]]*\([[:digit:]]*\)\./\1/gp')
   cd ..
else
   echo "Unable to cd into '${BASE_NAME}' directory. Checking out new version."
   svn co http://gpicsync.googlecode.com/svn/trunk ${BASE_NAME} >  ${TMP_FILE} 2>&1
   REV=$(grep -E "^Updated|^Checked|^At.*revision[[:space:]]*[[:digit:]]*" ${TMP_FILE} | \
         sed -n -e 's/^.*revision[[:space:]]*\([[:digit:]]*\)\./\1/gp')
fi
# Get Major version number
MJVER=$(sed -ne 's@[[:space:]]*text="GPicSync[[:space:]][[:space:]]*\([[:digit:]][[:digit:]]*\.[[:digit:]][[:digit:]]*\)[[:space:]]*.*$@\1@p' ${BASE_NAME}/gpicsync-GUI.py)
echo "MJVER = ${MJVER}"
if [ -z ${MJVER} ]; then
   echo "No major revision number. Exiting."
   exit 1
fi
echo "REV = ${REV}"
if [ -z ${REV} ]; then
   echo "No revision number. Exiting."
   exit 1
fi

# Exit if the archive already exists.
if [ -f ${BASE_NAME}-${MJVER}.${REV}.tar.bz2 ]; then
   echo "${BASE_NAME}-${MJVER}.${REV}.tar.bz2 already exists. Exiting"
   exit 0
fi

# Otherwise, create the tar file.
echo "Making tar archive ${BASE_NAME}-${MJVER}.${REV}.tar.bz2."
ln -s ${BASE_NAME} ${BASE_NAME}-${MJVER}.${REV}
tar --exclude=.svn -jhcf ${BASE_NAME}-${MJVER}.${REV}.tar.bz2 ${BASE_NAME}-${MJVER}.${REV}
echo "Done"
rm ${BASE_NAME}-${MJVER}.${REV}
rm ${TMP_FILE}

# Update version in spec file
if [ -e ${BASE_NAME}.spec ]; then
   sed -i -e "s@[[:space:]]*%define[[:space:]][[:space:]]*ver.*@%define ver ${MJVER}.${REV}@"  ${BASE_NAME}.spec
fi


openSUSE Build Service is sponsored by