From 0f5e7465e363f34a521644efbccd20007bfd5f26 Mon Sep 17 00:00:00 2001 From: dhowett Date: Thu, 24 Mar 2011 01:10:45 +0000 Subject: [PATCH] [package_version] Store the entire version string of the last built package. Allow -n to not update the version on-disk, and -o to just dump the (incremented) version number instead of the whole control file. git-svn-id: http://svn.howett.net/svn/theos/trunk@403 4410221e-0ddf-4ce3-99c0-2db6c0dbc727 --- bin/package_version.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bin/package_version.sh b/bin/package_version.sh index edf92122f3..f9926c16ba 100755 --- a/bin/package_version.sh +++ b/bin/package_version.sh @@ -1,6 +1,18 @@ #!/bin/bash -while getopts ":e:1c:" flag; do +UPDATE=1 +SKIPONE=0 +JUST_ECHO_VERSION=0 + +function build_num_from_file { + version=$(< "$1") + version=${version##*-} + version=${version%%+*} + version=${version%%~*} + echo -n "$version" +} + +while getopts ":e:1c:no" flag; do case "$flag" in :) echo "$0: Option -$OPTARG requires an argument." 1>&2 exit 1 @@ -11,6 +23,8 @@ while getopts ":e:1c:" flag; do e) EXTRAVERS="$OPTARG" ;; c) CONTROL="$OPTARG" ;; 1) SKIPONE=1 ;; + n) UPDATE=0 ;; + o) JUST_ECHO_VERSION=1 ;; esac done @@ -34,12 +48,10 @@ versionfile="${THEOS_PROJECT_DIR}/.theos/packages/$package-$version" build_number=0 if [[ ! -e "$versionfile" ]]; then - echo -n 1 > "$versionfile" build_number=1 else - build_number=$(< "$versionfile") + build_number=$(build_num_from_file "$versionfile") let build_number++ - echo -n "$build_number" > "$versionfile" fi buildno_part="-$build_number" @@ -52,4 +64,12 @@ if [[ ! -z "$EXTRAVERS" ]]; then extra_part="+$EXTRAVERS" fi -sed -e "s/^Version: \(.*\)/Version: \1$buildno_part$extra_part/g" $CONTROL +if [[ $UPDATE -eq 1 ]]; then + echo -n "$version$buildno_part$extra_part" > "$versionfile" +fi + +if [[ $JUST_ECHO_VERSION -eq 1 ]]; then + echo "$version$buildno_part$extra_part" +else + sed -e "s/^Version: \(.*\)/Version: \1$buildno_part$extra_part/g" $CONTROL +fi