forked from libAtoms/GAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gapversion
executable file
·66 lines (60 loc) · 1.51 KB
/
gapversion
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
#!/bin/bash
#
# Determine the gap version from the git reported last changed date
# of file (or the file GAP_VERSION if it exists). The gapversion
# is the UNIX timestap of the most recently changed file.
GAP_FILES="descriptors.f95 descriptors_wrapper.f95 \
gp_predict.f95 \
clustering.f95 gp_fit.f95 \
gap_fit_module.f95 gap_fit.f95"
GAP_ROOT=$(dirname "$0")
# By default only show the date
VERBOSE=false
# Options for interactive use
while getopts 'v' opt; do
case $opt in
v)
VERBOSE=true
;;
\?)
echo "Usage: $0"
echo "'-v' to output name of newest file to stderr"
exit 1
;;
esac
done
function git_date
{
if [ -e "$1" ]
then
DATE=$(git log -n 1 --format="%at" -- `/bin/ls | grep -v doc_src`)
[[ $? -eq 0 && ! -z $DATE ]] && echo "$DATE" || echo 0
else
echo 0
fi
}
if [ -s "${GAP_ROOT}/GAP_VERSION" ]; then
echo -ne "$(cat "${GAP_ROOT}/GAP_VERSION")"
exit 0
elif [ -d "${GAP_ROOT}/.git" ] || [ -s "${GAP_ROOT}/.git" ]; then
# Sort everything as "DATE filename" list and take the last one
GAP_VERSION=$(
for I in $GAP_FILES
do
if [ -d "${GAP_ROOT}/$(dirname "$I")" ]
then
cd "${GAP_ROOT}/$(dirname "$I")"
echo $(git_date $(basename "$I")) "$I"
cd - >/dev/null
fi
done | sort -n | tail -1 )
# filename to stderr if requested;
# split string with parameter expansion
if [ $VERBOSE == "true" ]; then
echo "${GAP_VERSION##* }" >&2
fi
echo "${GAP_VERSION%% *}"
else
echo "0"
exit 0
fi