-
Notifications
You must be signed in to change notification settings - Fork 10
/
updateVersion.sh
executable file
·100 lines (82 loc) · 2.2 KB
/
updateVersion.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /bin/bash
#
# Update the version file each day for the daily build
#
# Exit on error
set -e
# Parsing logic
usage()
{
echo "$0 <options>"
echo
echo "Valid options are:"
echo " -f: Version file to update (mandatory option)"
echo " -h: This message"
echo " -i: Increment build number and set date"
echo " -r: Set for release build"
echo " -v: Verbose output"
echo
echo "With only the -f option specified, -i is assumed"
exit 1
}
P_INCREMENT=0
P_RELEASE=0
VERBOSE=0
while getopts "h?f:irv" opt; do
case "$opt" in
h|\?)
usage
;;
f)
VERSION_FILE=$OPTARG
;;
i)
P_INCREMENT=1
;;
r)
P_RELEASE=1
;;
v)
VERBOSE=1
;;
esac
done
shift $((OPTIND-1))
if [ "$@ " != " " ]; then
echo "Parsing error: '$@' is unparsed, use -h for help" 1>& 2
exit 1
fi
if [ -z "$VERSION_FILE" ]; then
echo "Must specify -f qualifier (version file)" 1>& 2
exit 1
fi
if [ ! -f $VERSION_FILE ]; then
echo "Can't find file $VERSION_FILE" 1>& 2
exit 1
fi
if [ ! -w $VERSION_FILE ]; then
echo "File $VERSION_FILE is not writeable" 1>& 2
exit 1
fi
# Set default behavior
[ $P_RELEASE -eq 0 ] && P_INCREMENT=1
# Increment build number
if [ $P_INCREMENT -ne 0 ]; then
VERSION_OLD=`grep '^[A-Z]*_BUILDVERSION_BUILDNR' $VERSION_FILE | cut -d= -f2`
DATE_OLD=`grep '^[A-Z]*_BUILDVERSION_DATE' $VERSION_FILE | cut -d= -f2`
VERSION_NEW=$(( $VERSION_OLD + 1 ))
DATE_NEW=`date +%Y%m%d`
perl -i -pe "s/(^[A-Z]*_BUILDVERSION_BUILDNR)=.*/\1=$VERSION_NEW/" $VERSION_FILE
perl -i -pe "s/(^[A-Z]*_BUILDVERSION_DATE)=.*/\1=$DATE_NEW/" $VERSION_FILE
if [ $VERBOSE -ne 0 ]; then
echo "Updated version number, Was: $VERSION_OLD, Now $VERSION_NEW"
echo "Updated release date, Was: $DATE_OLD, Now $DATE_NEW"
fi
fi
# Set release build
if [ $P_RELEASE -ne 0 ]; then
perl -i -pe "s/^([A-Z]*_BUILDVERSION_STATUS)=.*/\1=Release_Build/" $VERSION_FILE
[ $VERBOSE -ne 0 ] && echo "Set BUILDVERSION_STATUS to \"Release_Build\""
echo "WARNING: Never commit $VERSION_FILE with release build set!" 1>& 2
fi
exit 0