1717# under the License.
1818
1919function 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=""
117135PACKAGEVAL=" "
118136RELEASE=" "
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
182197done
183198
184199packaging " $PACKAGEVAL " " $SIM " " $TARGETDISTRO " " $RELEASE "
185-
0 commit comments