forked from rundeck/rundeck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·313 lines (259 loc) · 8.03 KB
/
build.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
###################################
# script for full rundeck build
###################################
# find wget
if which wget >/dev/null; then
GET="wget -N"
elif which curl >/dev/null; then
GET="curl -O"
else
echo "Couldn't find wget or curl, need one or the other!" 1>&2
exit 1
fi
# configure JAVA_HOME and BUILD_ROOT as required
#export JAVA_HOME=/usr/java/jdk1.5.0_15
if [ -z "$BUILD_ROOT" ] ; then
export BUILD_ROOT=`pwd`/build
fi
if [ ! -f $JAVA_HOME/bin/java ] ; then
echo "ERROR: java is not configured correctly. Set JAVA_HOME."
exit 1
fi
BASEDIR=`pwd`
# VERS will be determined from "version.properties" file in root
#grails version for rundeckapp
GRAILSVERS=1.2.0
JETTYVERS=6.1.21
prepare_build(){
mkdir -p $BUILD_ROOT
# dl dir is for downloaded files
mkdir -p $BUILD_ROOT/dl
# local dir is for installed components needed for build
mkdir -p $BUILD_ROOT/local
# localrepo dir is the local repository for intermediate build files and other dependencies
mkdir -p $BUILD_ROOT/localrepo
export LOCALREPO=$BUILD_ROOT/localrepo
export LOCALREPOURL=file:$LOCALREPO
export LOCALDEPSREPO=$BASEDIR/dependencies
export LOCALDEPSREPOURL=file:$LOCALDEPSREPO
mkdir -p $LOCALREPO/jetty/zips
if [ ! -f $LOCALREPO/jetty/zips/jetty-${JETTYVERS}.zip ] ; then
if [ ! -z "$PKGREPO" -a -f $PKGREPO/jetty/zips/jetty-${JETTYVERS}.zip ] ; then
cp $PKGREPO/jetty/zips/jetty-${JETTYVERS}.zip $LOCALREPO/jetty/zips/
else
# get ant zip dependency to local repo if it doesn't exist
echo "Downloading jetty-${JETTYVERS}.zip ... "
cd $LOCALREPO/jetty/zips
$GET http://dist.codehaus.org/jetty/jetty-${JETTYVERS}/jetty-${JETTYVERS}.zip
fi
fi
# extract grails to local dir for use during build of Run Deck
if [ ! -f $BUILD_ROOT/local/grails-$GRAILSVERS/bin/grails ] ; then
if [ ! -z "$PKGREPO" -a -f $PKGREPO/grails/zips/grails-$GRAILSVERS.zip ] ; then
cd $BUILD_ROOT/local
unzip $PKGREPO/grails/zips/grails-$GRAILSVERS.zip
else
# get grails bin distribution
cd $BUILD_ROOT/dl
$GET http://dist.codehaus.org/grails/grails-$GRAILSVERS.zip
cd $BUILD_ROOT/local
unzip $BUILD_ROOT/dl/grails-$GRAILSVERS.zip
fi
fi
export GRAILS_HOME_111=$BUILD_ROOT/local/grails-$GRAILSVERS
# begin checkout of sources
cd $BUILD_ROOT
#determine version
if [ -z "$VERS" ] ; then
export VERS=$( grep version.number= $BASEDIR/version.properties | cut -d= -f 2 )
fi
echo "VERS=$VERS"
if [ -z "$RELNUM" ] ; then
export RELNUM=$( grep version.release.number= $BASEDIR/version.properties | cut -d= -f 2 )
fi
if [ -z "$RELNUM" ] ; then
export RELNUM="0"
fi
echo "RELNUM=$RELNUM"
# do release increment if necessary
if [ "$DO_RELEASE_INCREMENT" = "true" ] ; then
do_release_increment
fi
}
build_rundeck_core(){
#########################
#
# RUN build
#
# NOTE: if $HOME/.ssh/id_dsa does not exist, run ssh-keygen:
# ssh-keygen -t dsa
cd $BASEDIR/core
echo maven.repo.depslocal = $LOCALDEPSREPOURL > $BASEDIR/core/build.properties
MAVEN_HOME=$BASEDIR/maven
cd $BASEDIR/core && $MAVEN_HOME/bin/maven clean rdeck:zip
if [ 0 != $? ]
then
echo "RUN build failed"
exit 2
fi
#remove previous build artifacts from maven repository
rm -rf $BASEDIR/maven/repository/rundeck-core
rm -rf $LOCALREPO/rundeck-core
mkdir -p $LOCALREPO/rundeck-core/jars
cp target/rundeck-core-$VERS.jar $LOCALREPO/rundeck-core/jars/rundeck-core-$VERS.jar
if [ 0 != $? ]
then
echo "RUN build failed: cannot copy target/rundeck-core-$VERS.jar"
exit 2
fi
mkdir -p $LOCALREPO/rundeck-core/zips
cp target/dist/zips/rundeck-core-$VERS.zip $LOCALREPO/rundeck-core/zips/rundeck-core-$VERS.zip
if [ 0 != $? ]
then
echo "RUN build failed: cannot copy target/dist/zips/rundeck-core-$VERS.zip"
exit 2
fi
mkdir -p $LOCALREPO/rundeck-core/tgzs
cp target/dist/tgzs/rundeck-core-$VERS.tgz $LOCALREPO/rundeck-core/tgzs/rundeck-core-$VERS.tgz
if [ 0 != $? ]
then
echo "RUN build failed: cannot copy target/dist/tgzs/rundeck-core-$VERS.tgz"
exit 2
fi
mkdir -p $MAVEN_HOME/repository/rundeck-core/jars
cp target/rundeck-core-$VERS.jar $MAVEN_HOME/repository/rundeck-core/jars/rundeck-core-$VERS.jar
if [ 0 != $? ]
then
echo "RUN build failed: cannot copy target/rundeck-core-$VERS.jar"
exit 2
fi
}
build_rundeckapp(){
#####################
#
# Run Deck build
#
cd $BASEDIR/rundeckapp
# copy the dependencies into the lib directory
cp $LOCALREPO/rundeck-core/jars/rundeck-core-$VERS.jar lib/
MYPATH=$PATH
export GRAILS_HOME=$GRAILS_HOME_111
echo GRAILS_HOME=$GRAILS_HOME
export PATH=$PATH:$GRAILS_HOME/bin
GWORKDIR=$BASEDIR/rundeckapp/work
#echo 'y' to the command to quell y/n prompt on second time running it:
#echo -e "y\n" | $GRAILS_HOME/bin/grails install-plugin jetty
yes | $GRAILS_HOME/bin/grails -Dgrails.project.work.dir=$GWORKDIR install-plugin jetty
if [ 0 != $? ]
then
echo "failed to install jetty plugin"
exit 2
fi
#echo 'y' to the command to quell y/n prompt on second time running it:
#yes | $GRAILS_HOME/bin/grails install-plugin $BASEDIR/rundeckapp/plugins/grails-webrealms-0.2.zip
#if [ 0 != $? ]
#then
#echo "failed to install webrealms plugin"
#exit 2
#fi
# run clean and test
$GRAILS_HOME/bin/grails -Dgrails.project.work.dir=$GWORKDIR clean
if [ 0 != $? ]
then
echo "Run Deck clean failed"
exit 2
fi
$GRAILS_HOME/bin/grails -Dgrails.project.work.dir=$GWORKDIR test-app
if [ 0 != $? ]
then
echo "Run Deck tests failed"
exit 2
fi
#run war phase
yes | $GRAILS_HOME/bin/grails -Dgrails.project.work.dir=$GWORKDIR prod build-launcher
if [ 0 != $? ]
then
echo "Run Deck build failed"
exit 2
fi
# artifacts: rundeck-X.war
mkdir -p $LOCALREPO/rundeck/wars
cp target/rundeck-$VERS.war $LOCALREPO/rundeck/wars/rundeck-$VERS.war
if [ 0 != $? ]
then
echo "Rundeck build failed: cannot copy target/rundeck-$VERS.war"
exit 2
fi
# artifacts: rundeck-launcher-X.jar
mkdir -p $LOCALREPO/rundeck-launcher/jars/
cp target/rundeck-launcher-$VERS.jar $LOCALREPO/rundeck-launcher/jars/rundeck-launcher-$VERS.jar
if [ 0 != $? ]
then
echo "Rundeck build failed: cannot copy target/rundeck-launcher-$VERS.jar"
exit 2
fi
export PATH=$MYPATH
export GRAILS_HOME=
}
do_clean(){
echo "Cleaning..."
#clean localrepo of build artifacts
rm -r $BUILD_ROOT/localrepo/rundeck*
#remove rundeckapp lib dir which may contain previously built jars
rm $BUILD_ROOT/rundeckapp/lib/rundeck*.jar
#clean build target dirs
rm -rf $BASEDIR/core/target
rm -r $BASEDIR/rundeckapp/target
#clean intermediate maven repo dirs of build artifacts
rm -r $BASEDIR/maven/repository/rundeck*
echo "Cleaned local build artifacts and targets."
}
do_release_increment(){
RELNUM=$(($RELNUM + 1))
grep -q version.release.number $BASEDIR/version.properties
if [ $? != 0 ] ; then
echo "version.release.number=$RELNUM">> $BASEDIR/version.properties
echo "Added release number to $BASEDIR/version.properties"
else
perl -i'.orig' -p -e "s#^version\.release\.number\s*=.*\$#version.release.number=$RELNUM#" $BASEDIR/version.properties || (echo "Failed to commit release number increment: $!" && exit 2)
echo "Updated release number in $BASEDIR/version.properties"
fi
svn ci -m "Update Release number to $RELNUM" $BASEDIR/version.properties || (echo "Failed to commit release number increment: $!" && exit 2)
echo "Update release number to $RELNUM"
}
if [ "$1" = "-clean" ] ; then
shift
do_clean
fi
DO_RELEASE_INCREMENT=false
if [ "$1" = "-release" ] ; then
shift
#do_release_increment
DO_RELEASE_INCREMENT=true
fi
if [ -z "$*" ] ; then
prepare_build
build_rundeck_core
build_rundeckapp
else
prepare_build
for i in $* ; do
case "$i" in
rundeck_core)
build_rundeck_core
;;
rundeckapp)
build_rundeckapp
;;
server_rpm)
build_server_rpm
;;
*)
echo unknown action: ${i}
exit 1
;;
esac
done
exit 0
fi