1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#!/bin/bash
# OpenVPN 3 Linux client -- Next generation OpenVPN client
#
# SPDX-License-Identifier: AGPL-3.0-only
#
# Copyright (C) OpenVPN Inc <sales@openvpn.net>
# Copyright (C) David Sommerseth <davids@openvpn.net>
#
if [ $# -lt 1 ]; then
echo "Usage: $0 <--version|--gui-version|--prod-version|--core-version>"
exit 1
fi
set -u
PROJECT_ROOT="$(dirname $0)/.."
VERSION_RE='^v[[:digit:]]+(|\.[[:alnum:]]+)(|_[[:alnum:]]+)$'
if [ $1 = "--core-version" ]; then
PROJECT_ROOT="$(dirname $0)/../openvpn3-core"
VERSION_RE='^release/3\.[[:digit:]]+(|\.[[:digit:]]+)$'
fi
VERSION="noversion"
PRODVERSION="noversion"
if [ -e "${PROJECT_ROOT}/.git" ]; then
#
# Retrieve the version based on the git tree
#
# If a version tag is found (always prefixed with 'v'), this value
# is used. Otherwise compose a version string based on branch name
# and commit reference
VERSION="$(git --git-dir ${PROJECT_ROOT}/.git describe --always --tags)"
# Only accept explicit tag references, not a reference
# derived from a tag reference, such as "v3_beta-36-gcd68aee"
echo ${VERSION} | grep -qE "${VERSION_RE}"
ec=$?
set -eu
if [ $ec -ne 0 ]; then
# Presume not a version tag, so use commit reference
VERSION="$(git --git-dir ${PROJECT_ROOT}/.git rev-parse --symbolic-full-name HEAD | cut -d/ -f3-)_$(git rev-parse --short=16 HEAD)"
PRODVERSION="$(echo $VERSION | sed 's#/#_#g')"
else
# bash could use ${VERSION:1}, but we try to make it
# work with more basic sh - so we use 'cut' to get the
# same result
PRODVERSION="$(echo ${VERSION} | cut -b2-)"
fi
# Changed files from the index which are not staged gets the '+' flag
GIT_FLAGS="$(git --git-dir ${PROJECT_ROOT}/.git diff-files --name-status -r --ignore-submodules --quiet || echo 'm')"
# Changed files which are staged gets the '*' flag
GIT_FLAGS="${GIT_FLAGS}$(git --git-dir ${PROJECT_ROOT}/.git diff-index --cached --quiet --ignore-submodules HEAD || echo 's')"
if [ -n "${GIT_FLAGS}" ]; then
VERSION="${VERSION}__${GIT_FLAGS}"
PRODVERSION="${PRODVERSION}__${GIT_FLAGS}"
fi
elif [ -f "${PROJECT_ROOT}/src/build-version.h" ]; then
VERSION="$(cat ${PROJECT_ROOT}/src/build-version.h | awk '/define PACKAGE_GUIVERSION/{gsub("\"", ""); print $3}')"
PRODVERSION="$(echo $VERSION | sed -e 's#/#_#g' -e 's#:#_#g')"
fi
case "$1" in
--version)
echo "${VERSION}"
;;
--gui-version)
echo "${VERSION}" | sed -e 's#/#-#g'
;;
--core-version)
echo "${VERSION}" | sed -e 's#^release/##'
;;
--prod-version)
echo "${PRODVERSION}"
;;
*)
echo "$0: Unknown argument: $1"
exit 2
;;
esac
|