-
Notifications
You must be signed in to change notification settings - Fork 173
/
makerpm
executable file
·295 lines (261 loc) · 9.07 KB
/
makerpm
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
#!/bin/bash
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# Common script to make any one the xcat rpms. To build locally, run in the top dir of local svn repository, for example:
# ./makerpm xCAT-server
# ./makerpm xCAT x86_64
# If you want verbose output: export VERBOSE=1
# set -x
function xcat_probe_copy {
# xCAT-probe uses some functions shipped with xCAT, copying for the following reasons:
# 1. make xCAT-probe code be self-contained
# 2. do not maintain two files for each script
RPMNAME=${1}
if [ $RPMNAME = "xCAT-probe" ]; then
mkdir -p ${RPMNAME}/lib/perl/xCAT/
files=("NetworkUtils.pm" "GlobalDef.pm" "ServiceNodeUtils.pm")
for f in "${files[@]}"; do
cp perl-xCAT/xCAT/$f ${RPMNAME}/lib/perl/xCAT/
done
fi
}
function xcat_probe_cleanup {
RPMNAME=${1}
if [ $RPMNAME = "xCAT-probe" ]; then
rm -rf ${RPMNAME}/lib/perl/xCAT/
fi
}
# Make the noarch rpms
function makenoarch {
RPMNAME=$1
if [ "$OSNAME" = "AIX" ]; then
echo '.svn' > /tmp/xcat-excludes
tar -X /tmp/xcat-excludes -cf $RPMROOT/SOURCES/$RPMNAME-$VER.tar $RPMNAME
gzip -f $RPMROOT/SOURCES/$RPMNAME-$VER.tar
rm -f $RPMROOT/SRPMS/$RPMNAME-$VER*rpm $RPMROOT/RPMS/ppc/$RPMNAME-$VER*rpm
echo "Building $RPMROOT/RPMS/ppc/$RPMNAME-$VER-snap*.ppc.rpm $EMBEDTXT..."
rpm $QUIET -ba $RPMNAME/$RPMNAME.spec
RC=$?
else # linux
echo "Building $RPMROOT/RPMS/noarch/$RPMNAME-$VER-snap*.noarch.rpm $EMBEDTXT..."
# TODO: should fix this up, this is a hack for the new build machine
if [ $RPMNAME = "xCAT-UI" ]; then
# Only if the old compiler.jar file does not exist.....
if [ ! -e /xcat2/build/tools/compiler.jar ]; then
# look for the dynamic location of the compiler.jar file
DIRNAME=`dirname $(readlink -f $0)`
COMPILER_JAR=`echo "${DIRNAME%%linux_rpm/*}tools/compiler.jar"`
if [ -f $COMPILER_JAR ]; then
sed -i "s#/xcat2/build/tools/compiler.jar#${COMPILER_JAR}#g" xCAT-UI/xCAT-UI.spec
else
# In c910, if using the old buildxcat scripts...
COMPILER_JAR=`echo "${DIRNAME%%old/*}xcat2/tools/compiler.jar"`
if [ -f $COMPILER_JAR ]; then
sed -i "s#/xcat2/build/tools/compiler.jar#${COMPILER_JAR}#g" xCAT-UI/xCAT-UI.spec
fi
fi
fi
fi
xcat_probe_copy ${RPMNAME}
tar --exclude .svn -czf $RPMROOT/SOURCES/$RPMNAME-$VER.tar.gz $RPMNAME
rm -f $RPMROOT/SRPMS/$RPMNAME-$VER*rpm $RPMROOT/RPMS/noarch/$RPMNAME-$VER*rpm
rpmbuild $QUIET -ta $RPMROOT/SOURCES/$RPMNAME-$VER.tar.gz --define "version $VER" $REL "$EASE"
RC=$?
if [ $RPMNAME = "xCAT-UI" ]; then
# undo the modifications above to leave the sandbox prestine on the build machine
git checkout xCAT-UI/xCAT-UI.spec
fi
xcat_probe_cleanup ${RPMNAME}
fi
}
# Make one of the following rpms: xCAT, xCATsn, xCAT-buildkit, xCAT-OpenStack
function makexcat {
if [ "$OSNAME" != "AIX" -a "$1" != "xCAT-buildkit" -a -z "$2" ]; then
echo 'Usage: makerpm <RPMname> <arch> [<embedded-system>]'
exit 1
fi
RPMNAME="$1"
if [ "$OSNAME" = "AIX" ]; then
source=/opt/freeware/src/packages
cd `dirname $0`/$RPMNAME
echo '.svn' > /tmp/xcat-excludes
echo 'upflag' >> /tmp/xcat-excludes
if [ "$RPMNAME" = "xCAT" ]; then
tar -X /tmp/xcat-excludes -cf $RPMROOT/SOURCES/postscripts.tar postscripts LICENSE.html
gzip -f $RPMROOT/SOURCES/postscripts.tar
tar -X /tmp/xcat-excludes -cf $RPMROOT/SOURCES/templates.tar templates
gzip -f $RPMROOT/SOURCES/templates.tar
cp xcat.conf $RPMROOT/SOURCES
cp xcat.conf.apach24 $RPMROOT/SOURCES
cp xCATMN $RPMROOT/SOURCES
else # xCATsn
tar -X /tmp/xcat-excludes -cf $RPMROOT/SOURCES/license.tar LICENSE.html
gzip -f $RPMROOT/SOURCES/license.tar
cp xCATSN $RPMROOT/SOURCES
fi
rm -f $RPMROOT/SRPMS/$RPMNAME-$VER*rpm $RPMROOT/RPMS/ppc/$RPMNAME-$VER*rpm
cd - >/dev/null
echo "Building $RPMROOT/RPMS/ppc/$RPMNAME-$VER-snap*.ppc.rpm $EMBEDTXT..."
rpm $QUIET -ba $RPMNAME/$RPMNAME.spec
RC=$?
else # linux
ARCH="$2"
TARGET="--target $ARCH"
if [ "$RPMNAME" = "xCAT" ]; then
cd `dirname $0`/
# shipping bmcsetup and getipmi scripts as part of postscripts
files=("bmcsetup" "getipmi")
for f in "${files[@]}"; do
cp "xCAT-genesis-scripts/usr/bin/"$f ${RPMNAME}/postscripts/$f
sed -i "s/xcat.genesis.$f/$f/g" ${RPMNAME}/postscripts/$f
done
cd `dirname $0`/$RPMNAME
tar --exclude .svn --exclude upflag -czf $RPMROOT/SOURCES/postscripts.tar.gz postscripts LICENSE.html
tar --exclude .svn -czf $RPMROOT/SOURCES/prescripts.tar.gz prescripts
tar --exclude .svn -czf $RPMROOT/SOURCES/templates.tar.gz templates
tar --exclude .svn -czf $RPMROOT/SOURCES/winpostscripts.tar.gz winpostscripts
tar --exclude .svn -czf $RPMROOT/SOURCES/etc.tar.gz etc
cp xcat.conf $RPMROOT/SOURCES
cp xcat.conf.apach24 $RPMROOT/SOURCES
cp xCATMN $RPMROOT/SOURCES
cd - >/dev/null
elif [ "$RPMNAME" = "xCATsn" ]; then
cd `dirname $0`/$RPMNAME
tar --exclude .svn -czf $RPMROOT/SOURCES/license.tar.gz LICENSE.html
cp xcat.conf $RPMROOT/SOURCES
cp xcat.conf.apach24 $RPMROOT/SOURCES
cp xCATSN $RPMROOT/SOURCES
cp -a ../xCAT/etc/rsyslog.d $RPMROOT/
cp -a ../xCAT/etc/logrotate.d $RPMROOT/
cd - >/dev/null
elif [ "$RPMNAME" = "xCAT-buildkit" ]; then
ARCH="noarch"
TARGET=""
tar --exclude .svn --exclude xCAT-buildkit.spec -czf $RPMROOT/SOURCES/$RPMNAME-$VER.tar.gz $RPMNAME
elif [ "$RPMNAME" = "xCAT-OpenStack" ]; then
tar --exclude .svn --exclude xCAT-OpenStack.spec -czf $RPMROOT/SOURCES/$RPMNAME-$VER.tar.gz $RPMNAME
else # do not recognize rpm
echo "Unrecognized rpm: $RPMNAME"
exit 2
fi
rm -f $RPMROOT/SRPMS/$RPMNAME-$VER*rpm $RPMROOT/RPMS/$ARCH/$RPMNAME-$VER*rpm
echo "Building $RPMROOT/RPMS/$ARCH/$RPMNAME-$VER-snap*.$ARCH.rpm $EMBEDTXT..."
rpmbuild $QUIET -ba $RPMNAME/$RPMNAME.spec $TARGET --define "version $VER" $REL "$EASE"
RC=$?
if [ "$RPMNAME" = "xCAT" ]; then
files=("bmcsetup" "getipmi")
for f in "${files[@]}"; do
rm -f `dirname $0`/${RPMNAME}/postscripts/$f
done
fi
fi
}
# make ironic rpm for ironic baremetal driver
function makeironic {
RPMNAME="$1"
ARCH="$2"
cd `dirname $0`/$RPMNAME
cp -rf ironic_baremetal /tmp/
cd /tmp/ironic_baremetal
git init
git add *
git commit -a -m "generate rpm"
python setup.py bdist_rpm
rm -rf $RPMROOT/RPMS/$ARCH/
mkdir -p $RPMROOT/RPMS/$ARCH/
cp -rf dist/*.rpm $RPMROOT/RPMS/$ARCH/
rm -rf /tmp/ironic_baremetal
}
# Make the xCAT-genesis rpm
function makegenesis {
DIR="xCAT-genesis-builder"
SPEC_FILE="xCAT-genesis-base.spec"
RPMNAME="$1"
cd `dirname $0`/$DIR
sed -i s/%%REPLACE_CURRENT_VERSION%%/${VER}/g ${SPEC_FILE}
tar --exclude .svn -cjf $RPMROOT/SOURCES/$RPMNAME.tar.bz2 .
# undo the changes from the SED command above so it's not tracked by Git
git checkout ${SPEC_FILE}
cp LICENSE.html $RPMROOT/BUILD
cp $RPMNAME.spec $RPMROOT/SOURCES
cd - >/dev/null
rm -f $RPMROOT/SRPMS/$RPMNAME-$VER*rpm $RPMROOT/RPMS/noarch/$RPMNAME-$VER*rpm
echo "Building $RPMROOT/RPMS/noarch/$RPMNAME-$VER-snap*.noarch.rpm $EMBEDTXT..."
rpmbuild $QUIET -ba $DIR/$RPMNAME.spec --define "version $VER" $REL "$EASE"
}
function makegenesisscripts {
DIR="xCAT-genesis-scripts"
if [ -z "$2" ]; then
echo 'Usage: makerpm xCAT-genesis-scripts <arch> [<embedded-system>]'
exit 1
fi
RPMNAME="$1"
ARCH="$2"
TARGET="--target $ARCH"
cd `dirname $0`/
tar --exclude .svn -cjf $RPMROOT/SOURCES/$RPMNAME.tar.bz2 $DIR
cp $DIR/LICENSE.html $RPMROOT/BUILD
cp $DIR/$RPMNAME.spec $RPMROOT/SOURCES
cd - >/dev/null
rm -f $RPMROOT/SRPMS/$RPMNAME-$ARCH-$VER*rpm $RPMROOT/RPMS/noarch/$RPMNAME-$ARCH-$VER*rpm
echo "Building $RPMROOT/RPMS/noarch/$RPMNAME-$ARCH-$VER-snap*.noarch.rpm $EMBEDTXT..."
rpmbuild $QUIET -ba $DIR/$RPMNAME.spec $TARGET --define "version $VER" $REL "$EASE"
}
# Export the name of the embedded system we are building for
function exportEmbed {
if [ -n "$1" ]; then
export "$1=1"
EMBEDTXT="for $1 "
else
EMBEDTXT=""
fi
}
# Main code....
if [ -z "$1" ]; then
echo 'Usage: makerpm <RPMname> [<arch>] [<embedded-system>]'
exit 1
fi
OSNAME=$(uname)
if [ -z "$XCATVER" ] ; then
VER=`cat Version`
REL="--define"
EASE='usedate 1'
else
VER=$XCATVER
REL="--define"
EASE='release 1'
fi
if [ "$VERBOSE" = "1" -o "$VERBOSE" = "yes" ];then
QUIET=""
else
QUIET="--quiet"
fi
if [ "$OSNAME" = "AIX" ]; then
RPMROOT=/opt/freeware/src/packages
else # linux
rpmbuild --version > /dev/null
if [ $? -gt 0 ]; then
echo "Error: rpmbuild does not appear to be installed or working."
exit 2
fi
RPMROOT=`rpmbuild --eval '%_topdir' xCATsn/xCATsn.spec`
if [ $? -gt 0 ]; then
echo "Error: Could not determine rpmbuild's root directory."
exit 2
fi
fi
if [ "$1" = "xCAT" -o "$1" = "xCATsn" -o "$1" = "xCAT-buildkit" -o "$1" = "xCAT-OpenStack" ]; then
exportEmbed $3
makexcat $1 $2
elif [ "$1" = "xCAT-genesis-builder" ]; then
exportEmbed $2
makegenesis $1
elif [ "$1" = "xCAT-genesis-scripts" ]; then
exportEmbed $3
makegenesisscripts $1 $2
elif [ "$1" = "xCAT-OpenStack-ironic" ]; then
makeironic $1 $2
else # must be one of the noarch rpms
exportEmbed $2
makenoarch $1
fi
exit $RC