diff --git a/docker-mender-convert b/docker-mender-convert index 74fa3c2..af18a95 100755 --- a/docker-mender-convert +++ b/docker-mender-convert @@ -16,10 +16,15 @@ set -e +. modules/git.sh + IMAGE_NAME=${IMAGE_NAME:-mender-convert} MENDER_CONVERT_DIR="$(pwd)" +#Pass in version in-case we are added as a git submodule +MENDER_CONVERT_VERSION=$(git_mender_convert_version) + docker run \ --rm \ -v $MENDER_CONVERT_DIR:/mender-convert \ @@ -28,4 +33,5 @@ docker run \ -v /dev:/dev \ -v /lib/modules:/lib/modules:ro \ --env MENDER_ARTIFACT_NAME=${MENDER_ARTIFACT_NAME} \ + --env MENDER_CONVERT_VERSION=${MENDER_CONVERT_VERSION} \ $IMAGE_NAME "$@" diff --git a/mender-convert b/mender-convert index 9ebc885..2d438f8 100755 --- a/mender-convert +++ b/mender-convert @@ -14,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -MENDER_CONVERT_VERSION=$(git describe --tags --dirty --exact-match 2>/dev/null || git rev-parse --short HEAD) - function show_help() { cat << EOF mender-convert @@ -60,6 +58,12 @@ function trap_term() { trap trap_term INT TERM trap trap_exit EXIT +source modules/git.sh + +if [ -z "$MENDER_CONVERT_VERSION" ];then + MENDER_CONVERT_VERSION=$(git_mender_convert_version) +fi + # We only handle a selection of the arguments here, the rest are passed on # to the sub-scripts. while (("$#")); do diff --git a/modules/git.sh b/modules/git.sh new file mode 100644 index 0000000..289e6b8 --- /dev/null +++ b/modules/git.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Copyright 2019 Northern.tech AS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Print the mender convert version +# +git_mender_convert_version() { + git describe --tags --dirty --exact-match 2>/dev/null || git rev-parse --short HEAD +}