File get-from-git.sh of Package osm-gps-map

#!/bin/bash

NAME=osm-gps-map
GITHUB_USER=smartyg
OBJ=master
REMOTE="https://github.com/${GITHUB_USER}/${NAME}.git"
DIR=$NAME

# this is a huge hunk of stuff, so reuse the local repo if possible
if [ -d "${DIR}/.git" ]; then
	cd "${DIR}"
	git pull --tags
	cd ..
else
	set -e
	git clone "$REMOTE"
	set +e
fi

TOPDIR=$(pwd)
cd "$DIR"
LINE=$(git show --format=format:"%h %ai" -n 1 $OBJ | head -n 1)
set -- $LINE
REV=$1
DATE=$2
VER=$(git describe --tags $OBJ | sed -E -e 's/^([0-9]+[.0-9]*)(-([0-9]+)-([0-9a-g]+))?(-(modified))?/\1+git\3.\4.\6/' -e 's/[.]{2,}/./' -e 's/(\+git)?[.]$//')

set -e
git archive --prefix=$NAME-$REV/ -o $TOPDIR/$NAME-${REV}.tar ${OBJ} --
cd $TOPDIR
osc rm -f $NAME-*.tar.bz2 || true
bzip2 --force -9 $NAME-${REV}.tar
osc add $NAME-${REV}.tar.bz2
sed -i "s/^Version:.*/Version:        $VER/" $NAME.spec
sed -i "s/^%define git_rev.*/%define git_rev ${REV}/" $NAME.spec
echo "update source to version: ${VER}"
osc vc -m "Update to $REV ($DATE)"
openSUSE Build Service is sponsored by