-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathversion-update.sh
executable file
·45 lines (41 loc) · 1.21 KB
/
version-update.sh
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
#!/bin/sh -
if [[ ! -d ".git" ]]; then
version=`cat VERSION | grep "^version" | awk '{print $2}'`
commit=`cat VERSION | grep commit | awk '{print $2}'`
# version=`cat VERSION | grep "^gitdescribe" | sed -E 's/.*tag: ([^\)]+)\)/\1/'`
else
echo "Getting information from git"
describe=`git describe --long --dirty`
if [ -n "$describe" ]
then
version=`echo $describe | cut -d '-' -f1`
version=`cat VERSION | grep "^version" | awk '{print $2}'`
delta=`echo $describe | cut -d '-' -f2`
commit=`echo $describe | cut -d '-' -f3 | cut -c2-`
dirty=`echo $describe | cut -d '-' -f4`
else
version="0.0.0"
commit="None"
delta=""
dirty=""
fi
fi
if [ -n "$dirty" ]
then
commit="${commit}-d"
fi
if [ -f "$1" ]
then
echo "Modifying $1"
# sed -i .bak -E "s/^(__version__ = )\"([^\"]*)\"/\1\"${version}\"/" $1 || exit 3
sed -i .bak -E "s/\"version\": \"([^\"]+)\"/\"version\": \"${version}\"/" $1 || exit 3
sed -i .bak -E "s/\"build\": \"([^\"]+)\"/\"build\": \"${commit}\"/" $1 || exit 3
rm $1.bak
elif [ -z "$1" ]
then
echo "Must supply a file to modify"
exit 1
else
echo "File $1 does not exist"
exit 2
fi