summaryrefslogtreecommitdiff
path: root/Tools/scripts/git-get-latest-remote-version.sh
blob: 3148305b4f9556dc2b9b88e1c178bdc3e97ffdbe (plain) (blame)
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
#!/bin/sh
#
# MAINTAINER: yuri@FreeBSD.org

set -e
set -o pipefail

export LC_ALL=C

##
## git-get-latest-remote-version.sh: retrieves the latest version of a remote project at the given Git URL
##

# args

REPOSITORY_URL="$1"
TAG_PREFIX="$2"

if [ -z "$REPOSITORY_URL" ]; then
	echo "Usage: $0 <repository-url> <tag-prefix>"
	exit 1
fi

# check that packaged dependencies are installed

for dep in git version_sort; do
	if ! which -s $dep; then
		echo "error: the '$dep' dependency is missing"
		if [ $dep = "git" ]; then
			echo "... please install the 'git' package"
		elif [ $dep = "version_sort" ]; then
			echo "... please install the 'libversion' package"
		fi
		exit 1
	fi
done


# MAIN

git ls-remote --refs --tags $REPOSITORY_URL 2>/dev/null |
	grep "refs/tags/$TAG_PREFIX" |
	sed -e "s|.*refs/tags/$TAG_PREFIX||" |
	version_sort |
	tail -1 ||
	! echo "failed to find the git project '$REPOSITORY_URL' or tags in it"