diff --git a/obs-service-set_version.changes b/obs-service-set_version.changes index 54b0360..07d3cae 100644 --- a/obs-service-set_version.changes +++ b/obs-service-set_version.changes @@ -1,3 +1,20 @@ +------------------------------------------------------------------- +Tue Feb 14 20:01:13 GMT 2012 - aspiers@suse.com + +- only change the first occurrence of Version: header +- output useful info during run +- when auto-detecting the version, use the newest matching file + +------------------------------------------------------------------- +Tue Feb 14 17:54:29 GMT 2012 - aspiers@suse.com + +- patch License to follow spdx.org standard + +------------------------------------------------------------------- +Mon Jan 30 17:54:19 GMT 2012 - aspiers@suse.com + +- add --basename to usage help text + ------------------------------------------------------------------- Fri Jul 8 15:43:23 UTC 2011 - andrea@opensuse.org diff --git a/obs-service-set_version.spec b/obs-service-set_version.spec index 1a43bd0..ffaccc1 100644 --- a/obs-service-set_version.spec +++ b/obs-service-set_version.spec @@ -1,7 +1,7 @@ # # spec file for package obs-service-set_version # -# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,10 +18,10 @@ Name: obs-service-set_version -License: GPL v2 or later +License: GPL-2.0+ Group: Development/Tools/Building Summary: An OBS source service: Update spec file version -Version: 0.1 +Version: 0.2 Release: 1 Source: set_version Source1: set_version.service diff --git a/set_version b/set_version index 688f73d..215f339 100644 --- a/set_version +++ b/set_version @@ -36,52 +36,62 @@ while test $# -gt 0; do ;; *) echo Unknown parameter $1. - echo 'Usage: set_version --version $VERSION --file $FILE --outdir $OUT' + echo 'Usage: set_version --version $VERSION --file $FILE --basename $BASENAME --outdir $OUT' exit 1 ;; esac shift done -if [ -z "$MYVERSION" ]; then - MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).tar.*,\1,p" | head -n 1` -fi -if [ -z "$MYVERSION" ]; then - MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).tgz$,\1,p" | head -n 1` -fi -if [ -z "$MYVERSION" ]; then - MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).tbz2$,\1,p" | head -n 1` -fi -if [ -z "$MYVERSION" ]; then - MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).zip$,\1,p" | head -n 1` -fi -if [ -z "$MYVERSION" ]; then - echo "ERROR: no version is given and can't get detected automatically" - exit 1 -fi -if [ -z "$FILES" ]; then - FILES="*.spec *.dsc" -fi -if [ -z "$MYOUTDIR" ]; then - echo "ERROR: no output directory is given via --outdir parameter!" - exit 1 -fi - -for i in $FILES; do - FILE=`ls -1 $i 2>/dev/null` - [ -e "$FILE" ] || continue - - sed "s,^Version:.*,Version: $MYVERSION," "$FILE" > "$MYOUTDIR/$FILE" || exit 1 - if [ "${FILE%.spec}" != "$FILE" ]; then - # set release back to zero after version upgrade, will be increased by OBS during build - # also keep macros in release in case of fedora/mandriva - sed -r -i 's,^Release:[^%]*,Release: 0,' "$MYOUTDIR/$FILE" || exit 1 - fi - - if [ "${FILE#_service:}" != "$FILE" ]; then - # we can remove service files, no need to store them twice - rm -f "$FILE" +get_version_from_file () { + if [ -z "$MYVERSION" ]; then + MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tar.*,\1,p" | head -n 1` fi -done + if [ -z "$MYVERSION" ]; then + MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tgz$,\1,p" | head -n 1` + fi + if [ -z "$MYVERSION" ]; then + MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tbz2$,\1,p" | head -n 1` + fi + if [ -z "$MYVERSION" ]; then + MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).zip$,\1,p" | head -n 1` + fi + if [ -z "$MYVERSION" ]; then + echo "ERROR: no version is given and can't get detected automatically" + exit 1 + fi + echo "Detected version as $MYVERSION" +} + +write_files () { + if [ -z "$FILES" ]; then + FILES="*.spec *.dsc" + fi + if [ -z "$MYOUTDIR" ]; then + echo "ERROR: no output directory is given via --outdir parameter!" + exit 1 + fi + + for i in $FILES; do + FILE=`ls -1 $i 2>/dev/null` + [ -e "$FILE" ] || continue + + sed "0,/^Version:.*/s//Version: $MYVERSION/" "$FILE" > "$MYOUTDIR/$FILE" || exit 1 + echo "Updated first occurrence (if any) of Version in $FILE to $MYVERSION" + if [ "${FILE%.spec}" != "$FILE" ]; then + # set release back to zero after version upgrade, will be increased by OBS during build + # also keep macros in release in case of fedora/mandriva + sed -r -i 's,^Release:[^%]*,Release: 0,' "$MYOUTDIR/$FILE" || exit 1 + fi + + if [ "${FILE#_service:}" != "$FILE" ]; then + # we can remove service files, no need to store them twice + rm -f "$FILE" + fi + done +} + +get_version_from_file +write_files exit 0