-
Notifications
You must be signed in to change notification settings - Fork 3
/
changeversion
126 lines (111 loc) · 3.38 KB
/
changeversion
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# Change the version of the source code to the supplied value
# Day Suffix Function
DaySuffix() {
case $(date +%-d) in
1|21|31) echo "st";;
2|22) echo "nd";;
3|23) echo "rd";;
*) echo "th";;
esac
}
usage() {
echo "Usage: $0 <TARGET> [-c] [-p] [-m] [-i] [-r] [-d] [-s X.Y.Z]"
echo " -M Increase major version number (X.0.0)"
echo " -m Increase minor version number (0.X.0)"
echo " -p Increase patch version number (0.0.X)"
echo " -s Set version explicitly to X.Y.Z"
echo ""
echo "TARGET is one of: code - change version numbering in code, and installer and packaging scripts"
echo " release - change release version value and date in README.md"
echo ""
echo "If no options are specified the default behaviour is to print current versions across relevant files."
}
# Check for no args provided
if [ $# == 0 ]
then
usage
exit 1
fi
# Get target type and shift to next option
TYPE=$1
shift
if [ "$TYPE" != "code" ] && [ "$TYPE" != "release" ]
then
echo "Invalid target '${TYPE}' given (must be 'code', 'release'"
exit 1
fi
# Get current version number from correct target
CURRENT_VERSION=$(grep "VERSION =" gudpy.spec | sed "s/.*\"\(.*\)\"/\1/g")
PARTS=($(echo $CURRENT_VERSION | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
CHECK="true"
echo "Current major version (${TYPE}) is : ${MAJOR}"
echo "Current minor version (${TYPE}) is : ${MINOR}"
echo "Current patch version (${TYPE}) is : ${PATCH}"
while getopts ":mMps:" opt
do
case $opt in
M) echo "Major version number will be increased from $MAJOR to $((MAJOR+1))"
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
CHECK="false"
;;
m) echo "Minor version number will be increased from $MINOR to $((MINOR+1))"
MINOR=$((MINOR+1))
PATCH=0
CHECK="false"
;;
p) echo "Minor version number will be increased from $PATCH to $((PATCH+1))"
PATCH=$((PATCH+1))
CHECK="false"
;;
s) MAJOR=$(echo $OPTARG | cut -f1 -d.)
MINOR=$(echo $OPTARG | cut -f2 -d.)
PATCH=$(echo $OPTARG | cut -f3 -d.)
CHECK="false"
echo "Version will be set explicitly to MAJOR=$MAJOR MINOR=$MINOR PATCH=$PATCH"
;;
\?) usage
exit 1
;;
*) echo "Error: Extra operands given."
usage
exit 1
;;
esac
done
#########################################
# Code / Installer / Packaging Versions #
#########################################
if [ "$TYPE" = "code" ]
then
# Program (gudpy.spec)
if [ "$CHECK" = "false" ]
then
sed -i -e "s/VERSION = \"[0-9\.]\+\(.*\)\"/VERSION = \"$MAJOR.$MINOR.$PATCH\"\1/g" gudpy.spec
fi
echo -n " gudpy.spec (Program Version) : "
grep 'VERSION =' gudpy.spec | sed -e 's/VERSION = "\([0-9a-z\.]\+\).*"/\1/g'
fi
#############
# README.md #
#############
if [ "$TYPE" = "release" ]
then
# README.md
if [ "$CHECK" = "false" ]
then
DAYSUFFIX=$(DaySuffix)
TODAY=$(date "+%A %-d${DAYSUFFIX} %B %Y")
sed -i -e "s/Last Release: [0-9\.]*, \(.*\)_/Last Release: $MAJOR.$MINOR.$PATCH, ${TODAY}_/g" README.md
fi
echo -n " README.md (Release Version) : "
grep 'Last Release:' README.md | sed -e 's/.*Release: \([0-9\.]*\),.*/\1/g'
echo -n " README.md (Release Date) : "
grep 'Last Release:' README.md | sed -e "s/.*Release: .*, \(.*\)_/\1/g"
fi
exit 0