-
Notifications
You must be signed in to change notification settings - Fork 21
/
bump_version.sh
executable file
·219 lines (158 loc) · 5.79 KB
/
bump_version.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
# Bump source version
# Copyright (C) 2015, Wazuh Inc.
# May 2, 2017
# Syntax:
# bump_version [ <version> ] [ -r <revision> ] [ -p <product_version> ]
# Example:
# ./bump_version.sh v3.0.0-alpha1 -r 3457 -p 3.0.0.1
while [ -n "$1" ]
do
case $1 in
"-p")
if [[ $2 =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]
then
product=$2
else
echo "Error: product does not match 'X.X.X.X'"
exit 1
fi
shift 2
;;
"-r")
if [[ $2 =~ ^[[:digit:]]+$ ]]
then
revision=$2
else
echo "Error: revision is not numeric."
exit 1
fi
shift 2
;;
*)
if [[ $1 =~ ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-[[:alnum:]]+)?$ ]]
then
version=$1
else
echo "Error: incorrect version (must have form 'vX.X.X' or 'vX.X.X-...')."
exit 1
fi
shift 1
esac
done
if [ -z "$version" ] && [ -z "$revision" ] && [ -z "$product" ]
then
echo "Error: no arguments given."
echo "Syntax: $0 [ <version> ] [ -r <revision> ] [ -p <product_version> ]"
exit 1
fi
cd $(dirname $0)
VERSION_FILE="../src/VERSION"
REVISION_FILE="../src/REVISION"
DEFS_FILE="../src/headers/defs.h"
WAZUH_SERVER="../src/init/wazuh-server.sh"
WAZUH_AGENT="../src/init/wazuh-client.sh"
WAZUH_LOCAL="../src/init/wazuh-local.sh"
NSIS_FILE="../src/win32/wazuh-installer.nsi"
MSI_FILE="../src/win32/wazuh-installer.wxs"
FW_INIT="../framework/wazuh/__init__.py"
CLUSTER_INIT="../framework/wazuh/core/cluster/__init__.py"
API_SETUP="../api/setup.py"
API_SPEC="../api/api/spec/spec.yaml"
VERSION_DOCU="../src/Doxyfile"
WIN_RESOURCE="../src/win32/version.rc"
if [ -n "$version" ]
then
# File VERSIONS
echo $version > $VERSION_FILE
# File defs.h
egrep "^#define __ossec_version +\"v.+\"" $DEFS_FILE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable version definition found at file $DEFS_FILE"
exit 1
fi
sed -E -i'' -e "s/^(#define __ossec_version +)\"v.*\"/\1\"$version\"/" $DEFS_FILE
# wazuh-control
sed -E -i'' -e "s/^(VERSION=+)\"v.*\"/\1\"$version\"/" $WAZUH_SERVER
sed -E -i'' -e "s/^(VERSION=+)\"v.*\"/\1\"$version\"/" $WAZUH_AGENT
sed -E -i'' -e "s/^(VERSION=+)\"v.*\"/\1\"$version\"/" $WAZUH_LOCAL
# File wazuh-installer.nsi
egrep "^\!define VERSION \".+\"" $NSIS_FILE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable version definition found at file $NSIS_FILE"
exit 1
fi
sed -E -i'' -e "s/^(\!define VERSION \").+\"/\1${version:1}\"/g" $NSIS_FILE
# File wazuh-installer.wxs
egrep '<Product Id="\*" Name="Wazuh Agent" Language="1033" Version=".+" Manufacturer=' $MSI_FILE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable version definition found at file $MSI_FILE"
exit 1
fi
sed -E -i'' -e "s/(<Product Id=\"\*\" Name=\"Wazuh Agent\" Language=\"1033\" Version=\").+(\" Manufacturer=)/\1${version:1}\2/g" $MSI_FILE
# Framework
sed -E -i'' -e "s/__version__ = '.+'/__version__ = '${version:1}'/g" $FW_INIT
# Cluster
sed -E -i'' -e "s/__version__ = '.+'/__version__ = '${version:1}'/g" $CLUSTER_INIT
# API
sed -E -i'' -e "s/version='.+',/version='${version:1}',/g" $API_SETUP
sed -E -i'' -e "s/version: '.+'/version: '${version:1}'/g" $API_SPEC
sed -E -i'' -e "s_/v[0-9]+\.[0-9]+\.[0-9]+_/${version}_g" $API_SPEC
sed -E -i'' -e "s_com/[0-9]+\.[0-9]+_com/$(expr match "$version" 'v\([0-9]*.[0-9]*\).*')_g" $API_SPEC
# Documentation config file
sed -E -i'' -e "s/PROJECT_NUMBER = \".+\"/PROJECT_NUMBER = \"$version\"/g" $VERSION_DOCU
# version.rc
egrep "^#define VER_PRODUCTVERSION_STR v.+" $WIN_RESOURCE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable version definition (VER_PRODUCTVERSION_STR) found at file $WIN_RESOURCE"
exit 1
fi
sed -E -i'' -e "s/^(#define VER_PRODUCTVERSION_STR +)v.+/\1$version/" $WIN_RESOURCE
egrep "^#define VER_PRODUCTVERSION [[:digit:]]+,[[:digit:]]+,[[:digit:]]+,[[:digit:]]+" $WIN_RESOURCE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable version definition (VER_PRODUCTVERSION) found at file $WIN_RESOURCE"
exit 1
fi
product_commas=`echo "${version:1}.0" | tr '.' ','`
sed -E -i'' -e "s/^(#define VER_PRODUCTVERSION +).+/\1$product_commas/" $WIN_RESOURCE
fi
if [ -n "$revision" ]
then
CURRENT_VERSION=$(cat $VERSION_FILE)
# File REVISION
echo $revision > $REVISION_FILE
# wazuh-control
sed -E -i'' -e "s/^(REVISION=+)\".*\"/\1\"$revision\"/" $WAZUH_SERVER
sed -E -i'' -e "s/^(REVISION=+)\".*\"/\1\"$revision\"/" $WAZUH_AGENT
sed -E -i'' -e "s/^(REVISION=+)\".*\"/\1\"$revision\"/" $WAZUH_LOCAL
# File wazuh-installer.nsi
egrep "^\!define REVISION \".+\"" $NSIS_FILE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable revision definition found at file $NSIS_FILE"
exit 1
fi
sed -E -i'' -e "s/^(\!define REVISION \").+\"/\1$revision\"/g" $NSIS_FILE
# Cluster
sed -E -i'' -e "s/__revision__ = '.+'/__revision__ = '$revision'/g" $CLUSTER_INIT
# API
sed -E -i'' -e "s/x-revision: .+'/x-revision: '$revision'/g" $API_SPEC
# Documentation config file
sed -E -i'' -e "s/PROJECT_NUMBER = \".+\"/PROJECT_NUMBER = \"$CURRENT_VERSION-$revision\"/g" $VERSION_DOCU
fi
if [ -n "$product" ]
then
# File wazuh-installer.nsi
egrep "^VIProductVersion \".+\"" $NSIS_FILE > /dev/null
if [ $? != 0 ]
then
echo "Error: no suitable product definition found at file $NSIS_FILE"
exit 1
fi
sed -E -i'' -e "s/^(VIProductVersion \").+\"/\1$product\"/g" $NSIS_FILE
fi