Skip to content

Commit b6c0013

Browse files
committed
Fix and enhance package script
- if there's a "branding" string in the POM version (e.g. `x.y.z.a-NAME[-SNAPSHOT]`), the branding name will be used in the final generated pacakge name such as following: `cloudstack-management-x.y.z.a-NAME.NUMBER.el7.centos.x86_64` - use `timestamp` in final package name where POM version contains SNAPSHOT - fix long opts (they were broken) - usage help reformat
1 parent 1acc869 commit b6c0013

File tree

3 files changed

+73
-49
lines changed

3 files changed

+73
-49
lines changed

packaging/centos63/cloud.spec

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
Name: cloudstack
2525
Summary: CloudStack IaaS Platform
2626
#http://fedoraproject.org/wiki/PackageNamingGuidelines#Pre-Release_packages
27+
%if "%{?_brand}" != ""
28+
%define _brandver %{_ver}%{_brand}
29+
%else
30+
%define _brandver %{_ver}
31+
%endif
2732
%if "%{?_prerelease}" != ""
28-
%define _maventag %{_ver}-SNAPSHOT
33+
%define _maventag %{_brandver}-SNAPSHOT
2934
Release: %{_rel}%{dist}
3035
%else
31-
%define _maventag %{_ver}
36+
%define _maventag %{_brandver}
3237
Release: %{_rel}%{dist}
3338
%endif
3439

packaging/centos7/cloud.spec

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
Name: cloudstack
2525
Summary: CloudStack IaaS Platform
2626
#http://fedoraproject.org/wiki/PackageNamingGuidelines#Pre-Release_packages
27+
%if "%{?_brand}" != ""
28+
%define _brandver %{_ver}%{_brand}
29+
%else
30+
%define _brandver %{_ver}
31+
%endif
2732
%if "%{?_prerelease}" != ""
28-
%define _maventag %{_ver}-SNAPSHOT
33+
%define _maventag %{_brandver}-SNAPSHOT
2934
Release: %{_rel}%{dist}
3035
%else
31-
%define _maventag %{_ver}
36+
%define _maventag %{_brandver}
3237
Release: %{_rel}%{dist}
3338
%endif
3439

packaging/package.sh

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,35 @@
1717
# under the License.
1818

1919
function usage() {
20-
echo ""
21-
echo "usage: ./package.sh [-h|--help] -d|--distribution <name> [-r|--release <version>] [-p|--pack oss|OSS|noredist|NOREDIST] [-s|--simulator default|DEFAULT|simulator|SIMULATOR]"
22-
echo ""
23-
echo "The supported arguments are:"
24-
echo " To package with only redistributable libraries (default)"
25-
echo " -p|--pack oss|OSS"
26-
echo " To package with non-redistributable libraries"
27-
echo " -p|--pack noredist|NOREDIST"
28-
echo " To build a package for a distribution (mandatory)"
29-
echo " -d|--distribution centos7|centos63|fedora20|fedora21"
30-
echo " To set the package release version (optional)"
31-
echo " (default is 1 for normal and prereleases, empty for SNAPSHOT)"
32-
echo " -r|--release version(integer)"
33-
echo " To build for Simulator (optional)"
34-
echo " -s|--simulator default|DEFAULT|simulator|SIMULATOR"
35-
echo " To display this information"
36-
echo " -h|--help"
37-
echo ""
38-
echo "Examples: ./package.sh --pack oss"
39-
echo " ./package.sh --pack noredist"
40-
echo " ./package.sh --pack oss --distribution centos7 --release 42"
41-
echo " ./package.sh --distribution centos7 --release 42"
42-
echo " ./package.sh --distribution centos7"
20+
cat << USAGE
21+
Usage: ./package.sh -d DISTRO [OPTIONS]...
22+
Package CloudStack for specific distribution and provided options.
23+
24+
If there's a "branding" string in the POM version (e.g. x.y.z.a-NAME[-SNAPSHOT]), the branding name will
25+
be used in the final generated pacakge like: cloudstack-management-x.y.z.a-NAME.NUMBER.el7.centos.x86_64
26+
27+
Mandatory arguments:
28+
-d, --distribution string Build package for specified distribution ("centos7"|"centos63")
29+
30+
Optional arguments:
31+
-p, --pack string Define which type of libraries to package ("oss"|"OSS"|"noredist"|"NOREDIST") (default "oss")
32+
- oss|OSS to package with only redistributable libraries
33+
- noredist|NOREDIST to package with non-redistributable libraries
34+
-r, --release integer Set the package release version (default is 1 for normal and prereleases, empty for SNAPSHOT)
35+
-s, --simulator string Build package for Simulator ("default"|"DEFAULT"|"simulator"|"SIMULATOR") (default "default")
36+
37+
Other arguments:
38+
-h, --help Display this help message and exit
39+
40+
Examples:
41+
package.sh --distribution centos7
42+
package.sh --distribution centos7 --pack oss
43+
package.sh --distribution centos7 --pack noredist
44+
package.sh --distribution centos7 --release 42
45+
package.sh --distribution centos7 --pack noredist --release 42
46+
47+
USAGE
48+
exit 0
4349
}
4450

4551
# packaging
@@ -51,6 +57,7 @@ function packaging() {
5157
CWD=$(pwd)
5258
RPMDIR=$CWD/../dist/rpmbuild
5359
PACK_PROJECT=cloudstack
60+
5461
if [ -n "$1" ] ; then
5562
DEFOSSNOSS="-D_ossnoss $1"
5663
fi
@@ -59,6 +66,7 @@ function packaging() {
5966
fi
6067

6168
DISTRO=$3
69+
6270
MVN=$(which mvn)
6371
if [ -z "$MVN" ] ; then
6472
MVN=$(locate bin/mvn | grep -e mvn$ | tail -1)
@@ -67,22 +75,32 @@ function packaging() {
6775
exit 2
6876
fi
6977
fi
78+
7079
VERSION=$(cd ../; $MVN org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep --color=none '^[0-9]\.')
80+
BASEVER=$(echo "$VERSION" | sed 's/-SNAPSHOT//g')
81+
REALVER=$(echo "$BASEVER" | cut -d '-' -f 1)
82+
BRAND=$(echo "$BASEVER" | cut -d '-' -f 2)
83+
84+
if [ "$REALVER" != "$BRAND" ]; then
85+
DEFBRN="-D_brand -$BRAND"
86+
BRAND="${BRAND}."
87+
else
88+
BRAND=""
89+
fi
90+
7191
if echo "$VERSION" | grep -q SNAPSHOT ; then
72-
REALVER=$(echo "$VERSION" | cut -d '-' -f 1)
7392
if [ -n "$4" ] ; then
7493
DEFPRE="-D_prerelease $4"
75-
DEFREL="-D_rel SNAPSHOT$4"
94+
DEFREL="-D_rel ${BRAND}$(date +%s)$4"
7695
else
7796
DEFPRE="-D_prerelease 1"
78-
DEFREL="-D_rel SNAPSHOT"
97+
DEFREL="-D_rel ${BRAND}$(date +%s)"
7998
fi
8099
else
81-
REALVER="$VERSION"
82100
if [ -n "$4" ] ; then
83-
DEFREL="-D_rel $4"
101+
DEFREL="-D_rel ${BRAND}$4"
84102
else
85-
DEFREL="-D_rel 1"
103+
DEFREL="-D_rel ${BRAND}1"
86104
fi
87105
fi
88106
DEFVER="-D_ver $REALVER"
@@ -102,7 +120,7 @@ function packaging() {
102120
echo ". executing rpmbuild"
103121
cp "$DISTRO/cloud.spec" "$RPMDIR/SPECS"
104122

105-
(cd "$RPMDIR"; rpmbuild --define "_topdir ${RPMDIR}" "${DEFVER}" "${DEFREL}" ${DEFPRE+"$DEFPRE"} ${DEFOSSNOSS+"$DEFOSSNOSS"} ${DEFSIM+"$DEFSIM"} -bb SPECS/cloud.spec)
123+
(cd "$RPMDIR"; rpmbuild --define "_topdir ${RPMDIR}" "${DEFVER}" "${DEFREL}" ${DEFPRE+"$DEFPRE"} ${DEFOSSNOSS+"$DEFOSSNOSS"} ${DEFSIM+"$DEFSIM"} ${DEFBRN+"$DEFBRN"} -bb SPECS/cloud.spec)
106124
if [ $? -ne 0 ]; then
107125
echo "RPM Build Failed "
108126
exit 3
@@ -117,17 +135,13 @@ SIM=""
117135
PACKAGEVAL=""
118136
RELEASE=""
119137

120-
SHORTOPTS="hp:s:d:r:"
121-
LONGOPTS="help,pack:simulator:distribution:release:"
122-
ARGS=$(getopt -s bash -u -a --options "$SHORTOPTS" --longoptions "$LONGOPTS" --name "$0" -- "$@")
123-
eval set -- "$ARGS"
124-
echo "$ARGS"
125-
while [ $# -gt 0 ] ; do
138+
while [ -n "$1" ]; do
126139
case "$1" in
127140
-h | --help)
128141
usage
129142
exit 0
130143
;;
144+
131145
-p | --pack)
132146
echo "Packaging CloudStack..."
133147
PACKAGEVAL=$2
@@ -141,8 +155,9 @@ while [ $# -gt 0 ] ; do
141155
usage
142156
exit 1
143157
fi
144-
shift
158+
shift 2
145159
;;
160+
146161
-s | --simulator)
147162
SIM=$2
148163
echo "$SIM"
@@ -155,31 +170,30 @@ while [ $# -gt 0 ] ; do
155170
usage
156171
exit 1
157172
fi
158-
shift
173+
shift 2
159174
;;
175+
160176
-d | --distribution)
161177
TARGETDISTRO=$2
162178
if [ -z "$TARGETDISTRO" ] ; then
163179
echo "Error: Missing target distribution"
164180
usage
165181
exit 1
166182
fi
167-
shift
183+
shift 2
168184
;;
185+
169186
-r | --release)
170187
RELEASE=$2
171-
shift
188+
shift 2
172189
;;
173-
-)
190+
191+
-*|*)
174192
echo "Error: Unrecognized option"
175193
usage
176194
exit 1
177195
;;
178-
*)
179-
shift
180-
;;
181196
esac
182197
done
183198

184199
packaging "$PACKAGEVAL" "$SIM" "$TARGETDISTRO" "$RELEASE"
185-

0 commit comments

Comments
 (0)