1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # rpmbuild-bot.sh: RPM Build Bot version 1.1.0.
|
---|
5 | #
|
---|
6 | # Author: Dmitriy Kuminov <coding@dmik.org>
|
---|
7 | #
|
---|
8 | # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
9 | # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
10 | #
|
---|
11 | # Synopsis
|
---|
12 | # --------
|
---|
13 | #
|
---|
14 | # This script performs a build of RPM packages from a given .spec file in
|
---|
15 | # controlled environment to guarantee consistent results when building RPMs
|
---|
16 | # different machines. It uses a separate file rpmbuild-bot-env.sh located
|
---|
17 | # in the same directory to set up the environment and control the build
|
---|
18 | # process. The main purpose of this script is to build RPM packages for a
|
---|
19 | # specific distribution channel maintaining distribution-specific rules.
|
---|
20 | #
|
---|
21 | # Usage
|
---|
22 | # -----
|
---|
23 | #
|
---|
24 | # > rpmbuild-bot.sh [-l] SPEC[=VERSION]
|
---|
25 | # > [ upload[=REPO] | test[=MODE] | clean[=test] |
|
---|
26 | # > move[=FROM_REPO=TO_REPO] | remove[=REPO] ]
|
---|
27 | # > [-f]
|
---|
28 | #
|
---|
29 | # SPEC is the name of the RPM package spec file (extension is optional,
|
---|
30 | # .spec is assumed). The spec file is searched in the SPECS directory of the
|
---|
31 | # rpmbuild tree (usually $USER/rpmbuild/SPECS, rpmbuild --eval='%_specdir'
|
---|
32 | # will show the exact location). This may be overridden by giving a spec file
|
---|
33 | # with a path specification.
|
---|
34 | #
|
---|
35 | # The second argument defines the command to perform. The default command is
|
---|
36 | # "build". The following sections will describe each command.
|
---|
37 | #
|
---|
38 | # Global options:
|
---|
39 | #
|
---|
40 | # -l -- Log output of the rpmbuild command to screen in addition to putting it
|
---|
41 | # to a dedicated log file.
|
---|
42 | #
|
---|
43 | # Building packages
|
---|
44 | # -----------------
|
---|
45 | #
|
---|
46 | # The "build" is the main command which is used to generate packages for
|
---|
47 | # distribution. This command does the following:
|
---|
48 | #
|
---|
49 | # 1. Build all RPM packages for all architectures specified in
|
---|
50 | # $RPMBUILD_BOT_ARCH_LIST. The packages are stored in the RPMS
|
---|
51 | # directory of the rpmbuild tree.
|
---|
52 | # 2. Build the source RPM. Stored in the SRPMS directory.
|
---|
53 | # 3. Create a ZIP package from the RPMs for the architecture specified
|
---|
54 | # last in $RPMBUILD_BOT_ARCH_LIST.
|
---|
55 | #
|
---|
56 | # The build process for each architecture is stored in a log file in the logs
|
---|
57 | # directory of the rpmbuild tree (`rpmbuild --eval='%_topdir'/logs`). Creation
|
---|
58 | # of the source RPM and ZIP files is also logged, into separate log files.
|
---|
59 | #
|
---|
60 | # The "build" command will fail if the log directory contains files from a
|
---|
61 | # successful run of another "build" command for this package. This is to
|
---|
62 | # prevent overwriting successfully built packages that are not yet uploaded to
|
---|
63 | # the distribution repository (see the "upload" command). You should either
|
---|
64 | # run the "upload" command or use the -f option to force removal of these
|
---|
65 | # log files and the corresponding package files if you are absolutely sure they
|
---|
66 | # should be discarded.
|
---|
67 | #
|
---|
68 | # The "build" command will also check if there is a directory named SPEC in the
|
---|
69 | # same directory where the given .spec file resides. If such a directory
|
---|
70 | # exists, all files in it are assumed to be auxiliary source files used by the
|
---|
71 | # .spec file via SourceN: directives. These files will be automatically copied
|
---|
72 | # to the SOURCES directory in the rpmbuild tree before starting the build
|
---|
73 | # process.
|
---|
74 | #
|
---|
75 | # Doing test builds
|
---|
76 | # -----------------
|
---|
77 | #
|
---|
78 | # The "test" command is used to build packages for one architecture for testing
|
---|
79 | # purposes. In this more, neither the source RPM nor the ZIP file is created.
|
---|
80 | # Also, a special option is automatically passed to rpmbuild to clear the %dist
|
---|
81 | # variable to indicate that this is a local, non-distribution build. Such
|
---|
82 | # packages will always be "older" than the corresponding builds with %dist
|
---|
83 | # so that they will be automatically updated on the next yum update to the
|
---|
84 | # %dist ones. The packages built in "test" mode are NOT intended for
|
---|
85 | # distribution, they are meant only for local testing before performing the
|
---|
86 | # full build of everything.
|
---|
87 | #
|
---|
88 | # It is possible to configure which steps of the build to perform using the MODE
|
---|
89 | # parameter to the "test" command which may take one of the following values:
|
---|
90 | #
|
---|
91 | # prep Execute the %prep section of the spec file only.
|
---|
92 | # build Execute the %build section only (requires %prep to be executed
|
---|
93 | # before). May be run multiple times.
|
---|
94 | # install Execute the %install section only (requires "prep" and "build"
|
---|
95 | # to be executed before). May be run multiple times.
|
---|
96 | # pack Create the RPM packages (requires "prep", "build" and "install"
|
---|
97 | # to be executed before). Note that this step will also execute
|
---|
98 | # the %clean section so that a new "install" execution is
|
---|
99 | # necessary for "pack" to succeed.
|
---|
100 | #
|
---|
101 | # When no MODE parameter is given, all steps are executed in a proper order.
|
---|
102 | #
|
---|
103 | # The results of the "test" command are stored in a log file in the logs/test
|
---|
104 | # directory of the rpmbuild tree. The previous log file, if any, is given a .bak
|
---|
105 | # extension (the previous .bak file will be deleted).
|
---|
106 | #
|
---|
107 | # The "test" command will copy auxiliary source files for the .spec file, if any,
|
---|
108 | # to the proper location before rpmbuild execution -- the same way the "build"
|
---|
109 | # command does it.
|
---|
110 | #
|
---|
111 | # Uploading packages
|
---|
112 | # ------------------
|
---|
113 | #
|
---|
114 | # The "upload" command will upload the packages built with the "build"
|
---|
115 | # command to the official distribution channel configured in
|
---|
116 | # rpmbuild-bot-env.sh. The REPO parameter specifies one of the configured
|
---|
117 | # repositories. When REPO is not given, the default repository is used
|
---|
118 | # (usually experimental or similar).
|
---|
119 | #
|
---|
120 | # The upload command also requires the spec file to be under SVN version control
|
---|
121 | # and will try to commit it after uploading the RPMs to the repository with the
|
---|
122 | # automatic commit message that says "spec: PROJECT: Release version VERSION."
|
---|
123 | # (where PROJECT is the spec file name and VERSION is the full version,
|
---|
124 | # excluding the distribution mark, as specified by the spec file).This to ensure
|
---|
125 | # that the spec file is published at the same time the RPMs are published - to
|
---|
126 | # guarantee their consistency and simplify further maintenance. Note that the
|
---|
127 | # auxiliary source directory named SPEC and located near the spec file (see the
|
---|
128 | # "build" command), if it exists, will also be committed. If the spec file is
|
---|
129 | # not under version control, the "upload" command will fail.
|
---|
130 | #
|
---|
131 | # Note that the "upload" command needs log files from the "build" command
|
---|
132 | # and will fail otherwise.
|
---|
133 | #
|
---|
134 | # Upon successful completion, the "upload" command will remove all uploaded
|
---|
135 | # RPM and ZIP packages and will move all "build" log files to logs/archive.
|
---|
136 | #
|
---|
137 | # Cleaning packages
|
---|
138 | # -----------------
|
---|
139 | #
|
---|
140 | # The "clean" command will delete packages built with the "build" command
|
---|
141 | # and their log files without uploading them to a repository. This is useful
|
---|
142 | # when the successful build needs to be canceled for some reason (wrong source
|
---|
143 | # tree state, wrong patches etc.). Note that normally you don't need to use
|
---|
144 | # this command; it's an emergency-only tool.
|
---|
145 | #
|
---|
146 | # The "clean" command needs log files from the "build" command and will fail
|
---|
147 | # otherwise.
|
---|
148 | #
|
---|
149 | # If the "clean" command is given a "test" parameter, it will clean up the
|
---|
150 | # results of the "test" command instead of "build". The log file from the
|
---|
151 | # "test" command needs to be present or the command will fail.
|
---|
152 | #
|
---|
153 | # Moving packages between repositories
|
---|
154 | # ------------------------------------
|
---|
155 | #
|
---|
156 | # The "move" command allows to move a particular version of the packages
|
---|
157 | # built with the "build" command and uploaded with the "upload" command from one
|
---|
158 | # repository to another one. The "move" command is normally used to move
|
---|
159 | # packages from a test repository to a production one when they are ready for
|
---|
160 | # wide distribution.
|
---|
161 | #
|
---|
162 | # The "move" command needs log files from the "build" and "upload" commands
|
---|
163 | # and will fail otherwise. It also requires the VERSION parameter for the SPEC
|
---|
164 | # argument to be given (to specify the version of the packages to remove) and
|
---|
165 | # requires the FROM_REPO=TO_REPO parameter itself to specify the source
|
---|
166 | # repository and the target repository, respectively.
|
---|
167 | #
|
---|
168 | # The log files from the "build" and "upload" commands are not removed by the
|
---|
169 | # "move" command so it may be performed multiple times. The current location
|
---|
170 | # of the packages is not tracked in the log files so the command will fail
|
---|
171 | # if the source repository doesn't have the package files or if the target
|
---|
172 | # repository already has them.
|
---|
173 | #
|
---|
174 | # Removing packages
|
---|
175 | # -----------------
|
---|
176 | #
|
---|
177 | # The "remove" command allows to remove a particular version of the packages
|
---|
178 | # built with the "build" command and uploaded with the "upload" command from a
|
---|
179 | # repository. This is useful when the successful build needs to be canceled for
|
---|
180 | # some reason (wrong source tree state, wrong patches etc.). Note that normally
|
---|
181 | # you don't need to use this command; it's an emergency-only tool.
|
---|
182 | #
|
---|
183 | # The "remove" command needs log files from the "build" and "upload" commands
|
---|
184 | # and will fail otherwise. It also requires the VERSION parameter for the SPEC
|
---|
185 | # argument to be given (to specify the version of the packages to remove) and
|
---|
186 | # accepts the REPO parameter itself just like the "upload" command does (to
|
---|
187 | # specify a repository to remove the packages from).
|
---|
188 | #
|
---|
189 | # Note that the log files from the "build" and "upload" commands are also
|
---|
190 | # removed by this command upon successful package removal.
|
---|
191 | #
|
---|
192 | # Return value
|
---|
193 | # ------------
|
---|
194 | #
|
---|
195 | # The rpmbuild-bot.sh script will return a zero exit code upon successful
|
---|
196 | # completion and non-zero otherwise. The script output and log files should be
|
---|
197 | # inspected to check for a reason of the failure.
|
---|
198 | #
|
---|
199 |
|
---|
200 | #
|
---|
201 | # Helpers.
|
---|
202 | #
|
---|
203 |
|
---|
204 | print_elapsed()
|
---|
205 | {
|
---|
206 | # $1 = start timestamp, in seconds (as returned by `date +%s`)
|
---|
207 | # $2 = string containg \$e (will be replaced with the elapsed time)
|
---|
208 |
|
---|
209 | [ -z "$1" -o -z "$2" ] && return
|
---|
210 |
|
---|
211 | local e=$(($(date +%s) - $1))
|
---|
212 | local e_min=$(($e / 60))
|
---|
213 | local e_sec=$(($e % 60))
|
---|
214 | local e_hrs=$((e_min / 60))
|
---|
215 | e_min=$((e_min % 60))
|
---|
216 | e="${e_hrs}h ${e_min}m ${e_sec}s"
|
---|
217 |
|
---|
218 | eval "echo \"$2\""
|
---|
219 | }
|
---|
220 |
|
---|
221 | quit()
|
---|
222 | {
|
---|
223 | if [ -n "$start_time" ] ; then
|
---|
224 | echo "Build ended on $(date -R)."
|
---|
225 | if [ $1 = 0 ] ; then
|
---|
226 | print_elapsed start_time "Build succeeded (took \$e)."
|
---|
227 | else
|
---|
228 | print_elapsed start_time "Build failed (took \$e)."
|
---|
229 | fi
|
---|
230 | fi
|
---|
231 | exit $1
|
---|
232 | }
|
---|
233 |
|
---|
234 | run()
|
---|
235 | {
|
---|
236 | "$@"
|
---|
237 | local rc=$?
|
---|
238 | if test $rc != 0 ; then
|
---|
239 | echo "ERROR: The following command failed with error code $rc:"
|
---|
240 | echo $@
|
---|
241 | quit $rc
|
---|
242 | fi
|
---|
243 | }
|
---|
244 |
|
---|
245 | log()
|
---|
246 | {
|
---|
247 | echo $@
|
---|
248 | }
|
---|
249 |
|
---|
250 | log_run()
|
---|
251 | {
|
---|
252 | log="$1"
|
---|
253 | shift
|
---|
254 | rm -f "$log"
|
---|
255 | if [ -n "$log_to_console" ] ; then
|
---|
256 | # Do some magic redirection to preserve original error code
|
---|
257 | # (https://stackoverflow.com/questions/1221833/pipe-output-and-capture-exit-status-in-bash)
|
---|
258 | exec 4>&1
|
---|
259 | local rc=`{ { "$@" 2>&1 3>&-; printf $? 1>&3; } 4>&- | tee "$log" 1>&4; } 3>&1`
|
---|
260 | exec 4>&-
|
---|
261 | else
|
---|
262 | "$@" >"$log" 2>&1
|
---|
263 | local rc=$?
|
---|
264 | fi
|
---|
265 | if [ $rc != 0 ] ; then
|
---|
266 | log "ERROR: The following command failed with error code $rc:"
|
---|
267 | log $@
|
---|
268 | log "You will find more information in file '$log'."
|
---|
269 | if [ -z "$log_to_console" ] ; then
|
---|
270 | # Note: echo instead of log to avoid putting this to the main log file.
|
---|
271 | echo "Here are the last 10 lines of the command output:"
|
---|
272 | echo "------------------------------------------------------------------------------"
|
---|
273 | tail "$log" -n 10
|
---|
274 | echo "------------------------------------------------------------------------------"
|
---|
275 | fi
|
---|
276 | quit $rc
|
---|
277 | fi
|
---|
278 | }
|
---|
279 |
|
---|
280 | warn()
|
---|
281 | {
|
---|
282 | echo "WARNING: $1"
|
---|
283 | }
|
---|
284 |
|
---|
285 | die()
|
---|
286 | {
|
---|
287 | echo "ERROR: $1"
|
---|
288 | quit 1
|
---|
289 | }
|
---|
290 |
|
---|
291 | check_dir_var()
|
---|
292 | {
|
---|
293 | eval local val="\$$1"
|
---|
294 | [ -n "$val" ] || die "$1 is empty."
|
---|
295 | [ -d "$val" ] || die "$1 is '$val', not a valid directory."
|
---|
296 | }
|
---|
297 |
|
---|
298 | read_file_list()
|
---|
299 | {
|
---|
300 | # $1 = file list filename
|
---|
301 | # $2 = var name where to save the list of read file names (optional)
|
---|
302 | # $3 = function name to call for each file (optional), it may assign a new
|
---|
303 | # file name to $file and also set $file_pre and $file_post that will
|
---|
304 | # be prepended and appended to $file when saving it to the list in $2
|
---|
305 | # (but not when checking for file existence and timestamp)
|
---|
306 |
|
---|
307 | local list="$1"
|
---|
308 | local _read_file_list_ret=
|
---|
309 |
|
---|
310 | # Check timestamps.
|
---|
311 | while read l; do
|
---|
312 | local file_pre=
|
---|
313 | local file_post=
|
---|
314 | local file="${l#*|}"
|
---|
315 | local ts="${l%%|*}"
|
---|
316 | [ "$file" = "$ts" ] && die "Line '$l' in '$list' does not contain timestamps."
|
---|
317 | [ -n "$3" ] && eval $3
|
---|
318 | [ -f "$file" ] || die "File '$file' is not found."
|
---|
319 | echo "Checking timestamp of $file..."
|
---|
320 | local act_ts=`stat -c '%Y' "$file"`
|
---|
321 | # Drop fractional part of seconds reported by older coreutils
|
---|
322 | ts="${ts%%.*}"
|
---|
323 | act_ts="${act_ts%%.*}"
|
---|
324 | if [ "$ts" != "$act_ts" ] ; then
|
---|
325 | die "Recorded timestamp $ts doesn't match actual timestamp $act_ts for '$file'."
|
---|
326 | fi
|
---|
327 | _read_file_list_ret="$_read_file_list_ret${_read_file_list_ret:+ }$file_pre$file$file_post"
|
---|
328 | done < "$list"
|
---|
329 | # Return the files (if requested).
|
---|
330 | [ -n "$2" ] && eval "$2=\$_read_file_list_ret"
|
---|
331 | }
|
---|
332 |
|
---|
333 | usage()
|
---|
334 | {
|
---|
335 | echo "Usage:"
|
---|
336 | sed -n -e "s/rpmbuild-bot.sh/${0##*/}/g" -e 's/^# > / /p' < "$0"
|
---|
337 | quit 255
|
---|
338 | }
|
---|
339 |
|
---|
340 | sync_aux_src()
|
---|
341 | {
|
---|
342 | [ -n "$src_dir" ] || die "src_dir is empty."
|
---|
343 | [ -n "$spec_full" ] || die "spec_full is empty."
|
---|
344 |
|
---|
345 | # Aux source dir is expected along the .spec file.
|
---|
346 | local aux_src_dir="${spec_full%.spec}"
|
---|
347 |
|
---|
348 | # Return early if there is no aux source dir.
|
---|
349 | [ -d "$aux_src_dir" ] || return
|
---|
350 |
|
---|
351 | echo "Copying auxiliary sources for '$spec' to $src_dir..."
|
---|
352 |
|
---|
353 | for f in "$aux_src_dir"/* ; do
|
---|
354 | local ts=`stat -c '%Y' "$f"`
|
---|
355 | local trg_ts=
|
---|
356 | local trg_f="$src_dir/${f##*/}"
|
---|
357 | [ -f "$trg_f" ] && trg_ts=`stat -c '%Y' "$trg_f"`
|
---|
358 | if [ "$ts" != "$trg_ts" ] ; then
|
---|
359 | echo "Copying $f..."
|
---|
360 | run cp -p "$f" "$trg_f"
|
---|
361 | fi
|
---|
362 | done
|
---|
363 | }
|
---|
364 |
|
---|
365 | get_legacy_runtime()
|
---|
366 | {
|
---|
367 | [ -n "$src_dir" ] || die "src_dir is empty."
|
---|
368 | [ -n "$RPMBUILD_BOT_UPLOAD_REPO_STABLE" ] || die "RPMBUILD_BOT_UPLOAD_REPO_STABLE is empty."
|
---|
369 |
|
---|
370 | local spec_name_=`echo "${spec_name}" | tr - _`
|
---|
371 | eval local arch_list="\${RPMBUILD_BOT_ARCH_LIST_${spec_name_}}"
|
---|
372 | [ -z "$arch_list" ] && arch_list="${RPMBUILD_BOT_ARCH_LIST}"
|
---|
373 |
|
---|
374 | eval local rpm_list=\"\${RPMBUILD_BOT_LEGACY_${spec_name_}}\"
|
---|
375 | [ -z "$rpm_list" ] && return # nothing to do
|
---|
376 |
|
---|
377 | eval local base="\$RPMBUILD_BOT_UPLOAD_${RPMBUILD_BOT_UPLOAD_REPO_STABLE}_DIR"
|
---|
378 |
|
---|
379 | local abi_list=
|
---|
380 |
|
---|
381 | for rpm_spec in $rpm_list ; do
|
---|
382 | local abi name ver mask legacy_arch
|
---|
383 | IFS='|' read abi name ver mask legacy_arch <<EOF
|
---|
384 | ${rpm_spec}
|
---|
385 | EOF
|
---|
386 | [ -z "$abi" -o -z "$name" -o -z "$ver" ] && die "Value '${rpm_spec}' in RPMBUILD_BOT_LEGACY_${spec_name_} is invalid."
|
---|
387 | [ -z "$mask" ] && mask="*.dll"
|
---|
388 |
|
---|
389 | # add the dist suffix, if any, to ver (to make it consistent)
|
---|
390 | ver="$ver$dist_mark"
|
---|
391 |
|
---|
392 | abi_list="$abi_list${abi_list:+ }$abi"
|
---|
393 |
|
---|
394 | # Enumerate RPMs for all archs and extract them
|
---|
395 | echo "Getting legacy runtime ($mask) for ABI '$abi'..."
|
---|
396 | for arch in ${legacy_arch:-${arch_list}} ; do
|
---|
397 | eval local rpm="$RPMBUILD_BOT_UPLOAD_REPO_LAYOUT_rpm/$name-$ver.$arch.rpm"
|
---|
398 | local tgt_dir="$src_dir/$spec_name-legacy/$abi/$arch"
|
---|
399 | # Check filenames and timestamps
|
---|
400 | echo "Checking package $rpm..."
|
---|
401 | [ -f "$rpm" ] || die "File '$rpm' is not found."
|
---|
402 | local old_ts old_rpm old_name old_ver
|
---|
403 | [ -f "$tgt_dir.list" ] && IFS='|' read old_ts old_rpm old_name old_ver < "$tgt_dir.list"
|
---|
404 | local ts=`stat -c '%Y' "$rpm"`
|
---|
405 | # Drop fractional part of seconds reported by older coreutils
|
---|
406 | ts="${ts%%.*}"
|
---|
407 | old_ts="${old_ts%%.*}"
|
---|
408 | if [ "$old_rpm" != "$rpm" -o "$ts" != "$old_ts" -o "$name" != "$old_name" -o "$ver" != "$old_ver" ] ; then
|
---|
409 | echo "Extracting to $tgt_dir..."
|
---|
410 | run rm -f "$tgt_dir.list" && rm -rf "$tgt_dir"
|
---|
411 | (run mkdir -p "$tgt_dir" && cd "$tgt_dir"; run rpm2cpio "$rpm" | eval cpio -idm $mask)
|
---|
412 | # save the list for later use
|
---|
413 | find "$tgt_dir" -type f -printf '/%P\n' > "$tgt_dir.files.list"
|
---|
414 | # now try to locate the debuginfo package and extract *.dbg from it
|
---|
415 | eval local debug_rpm="$RPMBUILD_BOT_UPLOAD_REPO_LAYOUT_rpm/$name-debuginfo-$ver.$arch.rpm"
|
---|
416 | [ ! -f "$debug_rpm" ] && eval debug_rpm="$RPMBUILD_BOT_UPLOAD_REPO_LAYOUT_rpm/$name-debug-$ver.$arch.rpm"
|
---|
417 | if [ -f "$debug_rpm" ] ; then
|
---|
418 | echo "Found debug info package $debug_rpm, extracting..."
|
---|
419 | local dbgfilelist="$tgt_dir.debugfiles.list"
|
---|
420 | run rm -rf "$dbgfilelist"
|
---|
421 | local masks=
|
---|
422 | local f
|
---|
423 | while read -r f ; do
|
---|
424 | f="${f%.*}.dbg"
|
---|
425 | masks="$masks${masks:+ }'*$f'"
|
---|
426 | # Save the file for later inclusion into debugfiles.list (%debug_package magic in brp-strip-os2)
|
---|
427 | run echo "$f" >> "$dbgfilelist"
|
---|
428 | done < "$tgt_dir.files.list"
|
---|
429 | (run cd "$tgt_dir"; run rpm2cpio "$debug_rpm" | eval cpio -idm $masks)
|
---|
430 | fi
|
---|
431 | # put the 'done' mark
|
---|
432 | run echo "$ts|$rpm|$name|$ver" > "$tgt_dir.list"
|
---|
433 | fi
|
---|
434 | done
|
---|
435 | done
|
---|
436 |
|
---|
437 | run echo "$abi_list" > "$src_dir/$spec_name-legacy/abi.list"
|
---|
438 | }
|
---|
439 |
|
---|
440 | build_prepare()
|
---|
441 | {
|
---|
442 | sync_aux_src
|
---|
443 | get_legacy_runtime
|
---|
444 | }
|
---|
445 |
|
---|
446 | build_cmd()
|
---|
447 | {
|
---|
448 | local spec_name_=`echo "${spec_name}" | tr - _`
|
---|
449 | eval local arch_list="\${RPMBUILD_BOT_ARCH_LIST_${spec_name_}}"
|
---|
450 | [ -z "$arch_list" ] && arch_list="${RPMBUILD_BOT_ARCH_LIST}"
|
---|
451 |
|
---|
452 | local base_arch="${arch_list##* }"
|
---|
453 |
|
---|
454 | echo "Spec file: $spec_full"
|
---|
455 | echo "Targets: $arch_list + SRPM + ZIP ($base_arch)"
|
---|
456 |
|
---|
457 | build_prepare
|
---|
458 |
|
---|
459 | if [ -f "$spec_list" ] ; then
|
---|
460 | if [ -z "$force" ] ; then
|
---|
461 | die "File '$spec_list' already exists.
|
---|
462 | This file indicates a successful build that was not yet uploaded.
|
---|
463 | Either run the '"'upload'"' command to upload the generated RPM and ZIP
|
---|
464 | packages to the distribution repository or use the -f option to
|
---|
465 | force their removal if you are sure they should be discarded."
|
---|
466 | fi
|
---|
467 |
|
---|
468 | echo "Detected successful build in $spec_list, cleaning up due to -f option..."
|
---|
469 | local files=
|
---|
470 | read_file_list "$spec_list" files
|
---|
471 | for f in $files; do
|
---|
472 | echo "Removing $f..."
|
---|
473 | run rm -f "$f"
|
---|
474 | done
|
---|
475 | unset files
|
---|
476 |
|
---|
477 | echo "Removing $log_base.*.log and .list files..."
|
---|
478 | rm -f "$log_base".*.log "$log_base".*.list "$log_base".list
|
---|
479 | fi
|
---|
480 |
|
---|
481 | local noarch_only=
|
---|
482 | local start_time=
|
---|
483 |
|
---|
484 | # Generate RPMs (note that base_arch always goes first).
|
---|
485 | for arch in $base_arch ${arch_list%${base_arch}} ; do
|
---|
486 | echo "Creating RPMs for '$arch' target (logging to $log_base.$arch.log)..."
|
---|
487 | start_time=$(date +%s)
|
---|
488 | log_run "$log_base.$arch.log" rpmbuild.exe --target=$arch -bb "$spec_full"
|
---|
489 | print_elapsed start_time "Completed in \$e."
|
---|
490 | if ! grep -a -q "^Wrote: \+.*\.$arch\.rpm$" "$log_base.$arch.log" ; then
|
---|
491 | if ! grep -a -q "^Wrote: \+.*\.noarch\.rpm$" "$log_base.$arch.log" ; then
|
---|
492 | die "Target '$arch' did not produce any RPMs."
|
---|
493 | fi
|
---|
494 | noarch_only=1
|
---|
495 | echo "Skipping other targets because '$arch' produced only 'noarch' RPMs."
|
---|
496 | break
|
---|
497 | fi
|
---|
498 | done
|
---|
499 |
|
---|
500 | # Generate SRPM.
|
---|
501 | echo "Creating SRPM (logging to $log_base.srpm.log)..."
|
---|
502 | start_time=$(date +%s)
|
---|
503 | log_run "$log_base.srpm.log" rpmbuild -bs "$spec_full"
|
---|
504 | print_elapsed start_time "Completed in \$e."
|
---|
505 |
|
---|
506 | # Find SRPM file name in the log.
|
---|
507 | local src_rpm=`grep -a "^Wrote: \+.*\.src\.rpm$" "$log_base.srpm.log" | sed -e "s#^Wrote: \+##g"`
|
---|
508 | [ -n "$src_rpm" ] || die "Cannot find .src.rpm file name in '$log_base.srpm.log'."
|
---|
509 |
|
---|
510 | # Find package version.
|
---|
511 | local ver_full="${src_rpm%.src.rpm}"
|
---|
512 | ver_full="${ver_full##*/}"
|
---|
513 | [ "${ver_full%%-[0-9]*}" = "$spec_name" ] || die \
|
---|
514 | "SRPM name '${src_rpm##*/}' does not match .spec name ('$spec_name').
|
---|
515 | Either rename '$spec_name.spec' to '${ver_full%%-[0-9]*}.spec' or set 'Name:' tag to '$spec_name'."
|
---|
516 | ver_full="${ver_full#${spec_name}-}"
|
---|
517 | [ -n "$ver_full" ] || die "Cannot deduce package version from '$src_rpm'."
|
---|
518 |
|
---|
519 | # Find all RPM packages for the base arch (note the quotes around `` - it's to preserve multi-line result).
|
---|
520 | local rpms="`grep -a "^Wrote: \+.*\.\($base_arch\.rpm\|noarch\.rpm\)$" "$log_base.$base_arch.log" | sed -e "s#^Wrote: \+##g"`"
|
---|
521 | [ -n "$rpms" ] || die "Cannot find .$base_arch.rpm/.noarch.rpm file names in '$log_base.base_arch.log'."
|
---|
522 |
|
---|
523 | local ver_full_zip=`echo $ver_full | tr . _`
|
---|
524 | local zip="$zip_dir/$spec_name-$ver_full_zip.zip"
|
---|
525 |
|
---|
526 | # Generate ZIP.
|
---|
527 | echo "Creating ZIP (logging to $log_base.zip.log)..."
|
---|
528 | start_time=$(date +%s)
|
---|
529 | create_zip()
|
---|
530 | {(
|
---|
531 | run cd "$zip_dir"
|
---|
532 | rm -r "@unixroot" 2> /dev/null
|
---|
533 | for f in $rpms ; do
|
---|
534 | echo "Unpacking $f..."
|
---|
535 | run rpm2cpio "$f" | cpio -idm
|
---|
536 | done
|
---|
537 | rm -f "$zip" 2> /dev/null
|
---|
538 | echo "Creating '$zip'..."
|
---|
539 | run zip -mry9 "$zip" "@unixroot"
|
---|
540 | )}
|
---|
541 | log_run "$log_base.zip.log" create_zip
|
---|
542 | print_elapsed start_time "Completed in \$e."
|
---|
543 |
|
---|
544 | local ver_list="$log_base.$ver_full.list"
|
---|
545 |
|
---|
546 | # Generate list of all generated packages for further reference.
|
---|
547 | echo "Creating list file ($ver_list)..."
|
---|
548 | rm -f "$ver_list"
|
---|
549 | echo `stat -c '%Y' "$src_rpm"`"|$src_rpm" > "$ver_list"
|
---|
550 | echo `stat -c '%Y' "$zip"`"|$zip" >> "$ver_list"
|
---|
551 | # Save base arch RPMs.
|
---|
552 | for f in $rpms ; do
|
---|
553 | echo `stat -c '%Y' "$f"`"|$f" >> "$ver_list"
|
---|
554 | done
|
---|
555 | # Save other arch RPMs (only if there is anything but noarch).
|
---|
556 | if [ -z "$noarch_only" ] ; then
|
---|
557 | for arch in ${arch_list%${base_arch}} ; do
|
---|
558 | rpms="`grep -a "^Wrote: \+.*\.$arch\.rpm$" "$log_base.$arch.log" | sed -e "s#^Wrote: \+##g"`"
|
---|
559 | [ -n "$rpms" ] || die "Cannot find .$arch.rpm file names in '$log_base.arch.log'."
|
---|
560 | for f in $rpms ; do
|
---|
561 | echo `stat -c '%Y' "$f"`"|$f" >> "$ver_list"
|
---|
562 | done
|
---|
563 | done
|
---|
564 | fi
|
---|
565 |
|
---|
566 | # Everything succeeded. Symlink the list file so that "upload" can find it.
|
---|
567 | run ln -s "${ver_list##*/}" "$log_base.list"
|
---|
568 | }
|
---|
569 |
|
---|
570 | test_cmd()
|
---|
571 | {
|
---|
572 | echo "Spec file: $spec_full"
|
---|
573 |
|
---|
574 | local base_arch="${RPMBUILD_BOT_ARCH_LIST##* }"
|
---|
575 | local cmds=
|
---|
576 |
|
---|
577 | [ -z "$command_arg" ] && command_arg="all"
|
---|
578 |
|
---|
579 | case "$command_arg" in
|
---|
580 | all)
|
---|
581 | build_prepare
|
---|
582 | cmds="$cmds -bb"
|
---|
583 | ;;
|
---|
584 | prep)
|
---|
585 | cmds="$cmds -bp --short-circuit"
|
---|
586 | ;;
|
---|
587 | build)
|
---|
588 | cmds="$cmds -bc --short-circuit"
|
---|
589 | ;;
|
---|
590 | install)
|
---|
591 | cmds="$cmds -bi --short-circuit"
|
---|
592 | ;;
|
---|
593 | pack)
|
---|
594 | cmds="$cmds -bb --short-circuit"
|
---|
595 | ;;
|
---|
596 | *)
|
---|
597 | die "Invalid test build sub-command '$command_arg'."
|
---|
598 | ;;
|
---|
599 | esac
|
---|
600 |
|
---|
601 | local log_file="$log_dir/test/$spec_name.log"
|
---|
602 |
|
---|
603 | if [ -f "$log_file" ] ; then
|
---|
604 | rm -f "$log_file.bak"
|
---|
605 | run mv "$log_file" "$log_file.bak"
|
---|
606 | fi
|
---|
607 |
|
---|
608 | echo "Doing test RPM build for '$base_arch' target (logging to $log_file)..."
|
---|
609 | log_run "$log_file" rpmbuild.exe "--define=dist %nil" --target=$base_arch $cmds $spec_full
|
---|
610 |
|
---|
611 | # Show the generated RPMs when appropriate.
|
---|
612 | if [ "$command_arg" = "all" -o "$command_arg" = "pack" ] ; then
|
---|
613 | # Find all RPM packages for the base arch (note the quotes around `` - it's to preserve multi-line result).
|
---|
614 | local rpms="`grep -a "^Wrote: \+.*\.\($base_arch\.rpm\|noarch\.rpm\)$" "$log_file" | sed -e "s#^Wrote: \+##g"`"
|
---|
615 | if [ -n "$rpms" ] ; then
|
---|
616 | echo "Successfully generated the following RPMs:"
|
---|
617 | for f in $rpms; do
|
---|
618 | echo "$f"
|
---|
619 | done
|
---|
620 | else
|
---|
621 | warn "Cannot find .$base_arch.rpm/.noarch.rpm file names in '$log_file'."
|
---|
622 | fi
|
---|
623 | fi
|
---|
624 | }
|
---|
625 |
|
---|
626 | repo_dir_for_file()
|
---|
627 | {
|
---|
628 | # $1 = input file name
|
---|
629 | # $2 = var name to save dir to
|
---|
630 |
|
---|
631 | [ -n "$1" -a -n "$2" ] || die "Invalid arguments."
|
---|
632 |
|
---|
633 | local _repo_dir_for_file_ret=
|
---|
634 | case "$1" in
|
---|
635 | *.src.rpm)
|
---|
636 | eval _repo_dir_for_file_ret="$RPMBUILD_BOT_UPLOAD_REPO_LAYOUT_srpm"
|
---|
637 | ;;
|
---|
638 | *.*.rpm)
|
---|
639 | local arch="${1%.rpm}"
|
---|
640 | arch="${arch##*.}"
|
---|
641 | [ -n "$arch" ] || die "No arch spec in file name '$1'."
|
---|
642 | eval _repo_dir_for_file_ret="$RPMBUILD_BOT_UPLOAD_REPO_LAYOUT_rpm"
|
---|
643 | ;;
|
---|
644 | *.zip)
|
---|
645 | eval _repo_dir_for_file_ret="$RPMBUILD_BOT_UPLOAD_REPO_LAYOUT_zip"
|
---|
646 | ;;
|
---|
647 | esac
|
---|
648 |
|
---|
649 | eval "$2=\$_repo_dir_for_file_ret"
|
---|
650 | }
|
---|
651 |
|
---|
652 | upload_cmd()
|
---|
653 | {
|
---|
654 | # Check settings.
|
---|
655 | test -n "$RPMBUILD_BOT_UPLOAD_REPO_LIST" || die "RPMBUILD_BOT_UPLOAD_REPO_LIST is empty."
|
---|
656 |
|
---|
657 | local repo="$command_arg"
|
---|
658 | [ -z "$repo" ] && repo="${RPMBUILD_BOT_UPLOAD_REPO_LIST%% *}"
|
---|
659 |
|
---|
660 | check_dir_var "RPMBUILD_BOT_UPLOAD_${repo}_DIR"
|
---|
661 |
|
---|
662 | eval local base="\$RPMBUILD_BOT_UPLOAD_${repo}_DIR"
|
---|
663 |
|
---|
664 | [ -f "$spec_list" ] || die \
|
---|
665 | "File '$spec_list' is not found.
|
---|
666 | You may need to build the packages using the 'build' command."
|
---|
667 |
|
---|
668 | # Prepare for committing the SPEC and auxiliary source files.
|
---|
669 | local ver_list=
|
---|
670 | [ -L "$spec_list" ] && ver_list=`readlink "$spec_list"`
|
---|
671 | [ -z "$ver_list" ] && die "File '$spec_list' is not a valid symbolic link."
|
---|
672 |
|
---|
673 | local ver_full="${ver_list#${spec_name}.}"
|
---|
674 | ver_full="${ver_full%.*}"
|
---|
675 | [ -n "$dist_mark" ] && ver_full="${ver_full%${dist_mark}}"
|
---|
676 |
|
---|
677 | [ -n "$ver_full" ] || die "Full version string is empty."
|
---|
678 |
|
---|
679 | local commit_items="$spec_full"
|
---|
680 | # Commit the auxiliary source directory, if any, as well.
|
---|
681 | [ -d "${spec_full%.spec}" ] && commit_items="$commit_items ${spec_full%.spec}"
|
---|
682 |
|
---|
683 | local commit_msg="spec: $spec_name: Release version $ver_full."
|
---|
684 |
|
---|
685 | echo \
|
---|
686 | "Uploading requires the following items to be committed to SPEC repository:
|
---|
687 | $commit_items
|
---|
688 | With the following commit message:
|
---|
689 | $commit_msg
|
---|
690 | The repository will be updated now and then you will get a diff for careful
|
---|
691 | inspection. Press Enter to continue."
|
---|
692 |
|
---|
693 | local answer=
|
---|
694 | read answer
|
---|
695 | local pager=`which less`
|
---|
696 | if [ ! -x "$pager" ] ; then
|
---|
697 | pager="more"
|
---|
698 | # OS/2 more doesn't understand LF, feed it through sed.
|
---|
699 | [ -x `which sed` ] && pager="sed -e '' | $pager"
|
---|
700 | fi
|
---|
701 | run svn up "$spec_dir"
|
---|
702 | echo
|
---|
703 | svn diff $commit_items | "$pager"
|
---|
704 | echo "
|
---|
705 | Type YES if the diff is okay to be committed."
|
---|
706 | read answer
|
---|
707 |
|
---|
708 | [ "$answer" = "YES" ] || die "Your answer is not YES, upload is aborted."
|
---|
709 |
|
---|
710 | # First, copy RPM files over to the repository.
|
---|
711 | local files=
|
---|
712 | read_file_list "$spec_list" files
|
---|
713 | for f in $files; do
|
---|
714 | local d=
|
---|
715 | repo_dir_for_file "$f" d
|
---|
716 | [ -n "$d" ] || die "Unsupported file name '$f' in '$spec_list'."
|
---|
717 | [ -d "$d" ] || die "'$d' is not a directory."
|
---|
718 | [ -f "$d/${f##*/}" -a -z "$force" ] && die \
|
---|
719 | "File '$d/${f##*/}' already exists.
|
---|
720 | Use the -f option to force uploading if you are sure the existing
|
---|
721 | packages in the repository should be discarded."
|
---|
722 | echo "Copying $f to $d..."
|
---|
723 | run cp -p "$f" "$d"
|
---|
724 | done
|
---|
725 |
|
---|
726 | # On success, delete the uploaded packages and archive log files.
|
---|
727 | for f in $files; do
|
---|
728 | echo "Removing $f..."
|
---|
729 | run rm -f "$f"
|
---|
730 | done
|
---|
731 |
|
---|
732 | # And finally commit the SPEC file.
|
---|
733 | run svn commit $commit_items -m "$commit_msg"
|
---|
734 |
|
---|
735 | # Note: versioned .list file will remain in archive forever (for further reference).
|
---|
736 | echo "Removing old '$spec_name' logs from $log_dir/archive..."
|
---|
737 | rm -f "$log_dir/archive/$spec_name".*.log "$log_dir/archive/$spec_name".list
|
---|
738 | echo "Moving '$spec_name' logs to $log_dir/archive..."
|
---|
739 | run mv "$log_base".*.log "$log_base".*.list "$log_base".list "$log_dir/archive/"
|
---|
740 | }
|
---|
741 |
|
---|
742 | clean_cmd()
|
---|
743 | {
|
---|
744 | if [ "$command_arg" = "test" ] ; then
|
---|
745 | # Cleanup after "test" command.
|
---|
746 | local base_arch="${RPMBUILD_BOT_ARCH_LIST##* }"
|
---|
747 | local log_file="$log_dir/test/$spec_name.log"
|
---|
748 |
|
---|
749 | [ -f "$log_file" ] || die "File '$test_log' is not found."
|
---|
750 |
|
---|
751 | # Find all RPM packages for the base arch (note the quotes around `` - it's to preserve multi-line result).
|
---|
752 | local rpms="`grep -a "^Wrote: \+.*\.\($base_arch\.rpm\|noarch\.rpm\)$" "$log_file" | sed -e "s#^Wrote: \+##g"`"
|
---|
753 | if [ -n "$rpms" ] ; then
|
---|
754 | for f in $rpms; do
|
---|
755 | echo "Removing $f..."
|
---|
756 | run rm -f "$f"
|
---|
757 | done
|
---|
758 | echo "Removing $log_file[.bak]..."
|
---|
759 | run rm -f "$log_file" "$log_file".bak
|
---|
760 | else
|
---|
761 | die "Cannot find .$base_arch.rpm/.noarch.rpm file names in '$log_file'."
|
---|
762 | fi
|
---|
763 |
|
---|
764 | return
|
---|
765 | fi
|
---|
766 |
|
---|
767 | # Cleanup after "build command".
|
---|
768 | [ -f "$spec_list" ] || die \
|
---|
769 | "File '$spec_list' is not found.
|
---|
770 | You man need to build the packages using the 'build' command."
|
---|
771 |
|
---|
772 | local files=
|
---|
773 | read_file_list "$spec_list" files
|
---|
774 |
|
---|
775 | for f in $files; do
|
---|
776 | echo "Removing $f..."
|
---|
777 | run rm -f "$f"
|
---|
778 | done
|
---|
779 |
|
---|
780 | echo "Removing '$spec_name' logs from $log_dir..."
|
---|
781 | rm -f "$log_base".*.log "$log_base".*.list "$log_base".list
|
---|
782 | }
|
---|
783 |
|
---|
784 | move_cmd()
|
---|
785 | {
|
---|
786 | # Check settings.
|
---|
787 | [ -n "$spec_ver" ] || die "SPEC parameter lacks version specification."
|
---|
788 |
|
---|
789 | test -n "$RPMBUILD_BOT_UPLOAD_REPO_LIST" || die "RPMBUILD_BOT_UPLOAD_REPO_LIST is empty."
|
---|
790 |
|
---|
791 | local from_repo="${command_arg%%=*}"
|
---|
792 | local to_repo="${command_arg#*=}"
|
---|
793 |
|
---|
794 | [ -n "$from_repo" ] || die "FROM_REPO parameter is missing."
|
---|
795 | [ "$from_repo" = "$to_repo" ] && die "TO_REPO parameter is missing (or equals to FROM_REPO)."
|
---|
796 |
|
---|
797 | check_dir_var "RPMBUILD_BOT_UPLOAD_${from_repo}_DIR"
|
---|
798 | check_dir_var "RPMBUILD_BOT_UPLOAD_${to_repo}_DIR"
|
---|
799 |
|
---|
800 | local ver_list="$log_dir/archive/$spec_name.$spec_ver.list"
|
---|
801 | [ -f "$ver_list" ] || die "File '$ver_list' is not found."
|
---|
802 |
|
---|
803 | eval local from_base="\$RPMBUILD_BOT_UPLOAD_${from_repo}_DIR"
|
---|
804 | eval local to_base="\$RPMBUILD_BOT_UPLOAD_${to_repo}_DIR"
|
---|
805 |
|
---|
806 | local files=
|
---|
807 | read_file_list "$ver_list" files '
|
---|
808 | local dir=
|
---|
809 | local base="$from_base"; repo_dir_for_file "$file" dir; file="${dir}/${file##*/}"
|
---|
810 | base="$to_base"; repo_dir_for_file "$file" dir; file_post=">${dir}"
|
---|
811 | '
|
---|
812 | for f in $files; do
|
---|
813 | local from="${f%%>*}"
|
---|
814 | local to="${f#*>}"
|
---|
815 | echo "Moving $from to $to/..."
|
---|
816 | run mv "$from" "$to/"
|
---|
817 | done
|
---|
818 | }
|
---|
819 |
|
---|
820 | remove_cmd()
|
---|
821 | {
|
---|
822 | # Check settings.
|
---|
823 | [ -n "$spec_ver" ] || die "SPEC parameter lacks version specification."
|
---|
824 |
|
---|
825 | test -n "$RPMBUILD_BOT_UPLOAD_REPO_LIST" || die "RPMBUILD_BOT_UPLOAD_REPO_LIST is empty."
|
---|
826 |
|
---|
827 | local repo="$command_arg"
|
---|
828 | [ -z "$repo" ] && repo="${RPMBUILD_BOT_UPLOAD_REPO_LIST%% *}"
|
---|
829 |
|
---|
830 | check_dir_var "RPMBUILD_BOT_UPLOAD_${repo}_DIR"
|
---|
831 |
|
---|
832 | local ver_list="$log_dir/archive/$spec_name.$spec_ver.list"
|
---|
833 | [ -f "$ver_list" ] || die "File '$ver_list' is not found."
|
---|
834 |
|
---|
835 | eval local base="\$RPMBUILD_BOT_UPLOAD_${repo}_DIR"
|
---|
836 |
|
---|
837 | local files=
|
---|
838 | read_file_list "$ver_list" files 'local dir=; repo_dir_for_file $file dir; file="${dir}/${file##*/}"'
|
---|
839 |
|
---|
840 | for f in $files; do
|
---|
841 | echo "Removing $f..."
|
---|
842 | run rm -f "$f"
|
---|
843 | done
|
---|
844 |
|
---|
845 | echo "Removing $ver_list..."
|
---|
846 | run rm -f "$ver_list"
|
---|
847 |
|
---|
848 | # Also remove the logs of last "build" if we are removing the last "build" package.
|
---|
849 | if [ -L "$log_dir/archive/$spec_name.list" -a \
|
---|
850 | `readlink "$log_dir/archive/$spec_name.list"` = "$spec_name.$spec_ver.list" ] ; then
|
---|
851 | echo "Removing '$spec_name' logs from $log_dir/archive..."
|
---|
852 | rm -f "$log_dir/archive/$spec_name".*.log "$log_dir/archive/$spec_name".list
|
---|
853 | fi
|
---|
854 | }
|
---|
855 |
|
---|
856 | #
|
---|
857 | # Main.
|
---|
858 | #
|
---|
859 |
|
---|
860 | # Parse command line.
|
---|
861 | while [ -n "$1" ] ; do
|
---|
862 | case "$1" in
|
---|
863 | -*)
|
---|
864 | if [ -z "$command" ] ; then
|
---|
865 | # Global options
|
---|
866 | case "$1" in
|
---|
867 | -l) log_to_console="$1"
|
---|
868 | ;;
|
---|
869 | *) usage
|
---|
870 | ;;
|
---|
871 | esac
|
---|
872 | else
|
---|
873 | # Command's options
|
---|
874 | options="$*"
|
---|
875 | while [ -n "$1" ] ; do
|
---|
876 | case "$1" in
|
---|
877 | -f) force="$1"
|
---|
878 | ;;
|
---|
879 | -l) log_to_console="$1"
|
---|
880 | ;;
|
---|
881 | *) usage
|
---|
882 | ;;
|
---|
883 | esac
|
---|
884 | shift
|
---|
885 | done
|
---|
886 | break
|
---|
887 | fi
|
---|
888 | ;;
|
---|
889 | *)
|
---|
890 | if [ -z "$spec" ] ; then
|
---|
891 | spec="$1"
|
---|
892 | else
|
---|
893 | command="$1"
|
---|
894 | fi
|
---|
895 | ;;
|
---|
896 | esac
|
---|
897 | shift
|
---|
898 | done
|
---|
899 |
|
---|
900 | [ -n "$spec" ] || usage
|
---|
901 | [ -z "$command" ] && command="build"
|
---|
902 |
|
---|
903 | spec_ver="${spec#*=}"
|
---|
904 | spec="${spec%=*}"
|
---|
905 | [ "$spec" = "$spec_ver" ] && spec_ver=
|
---|
906 |
|
---|
907 | command_name="${command%%=*}"
|
---|
908 | command_arg="${command#*=}"
|
---|
909 | [ "$command_name" = "$command_arg" ] && command_arg=
|
---|
910 |
|
---|
911 | need_spec_file=
|
---|
912 |
|
---|
913 | # Validate commands.
|
---|
914 | case "$command_name" in
|
---|
915 | build|test)
|
---|
916 | need_spec_file=1
|
---|
917 | ;;
|
---|
918 | upload|clean|move|remove)
|
---|
919 | ;;
|
---|
920 | *) usage
|
---|
921 | ;;
|
---|
922 | esac
|
---|
923 |
|
---|
924 | # Set up the rpmbuild-bot environment.
|
---|
925 | . "${0%%.sh}-env.sh"
|
---|
926 |
|
---|
927 | # Check common env settings.
|
---|
928 | test -n "$RPMBUILD_BOT_ARCH_LIST" || die "RPMBUILD_BOT_ARCH_LIST is empty."
|
---|
929 |
|
---|
930 | # Query all rpmbuild macros in a single run as it may be slow.
|
---|
931 | eval `rpmbuild.exe --eval='rpmbuild_dir="%_topdir" ; spec_dir="%_specdir" ; src_dir="%_sourcedir" ; dist_mark="%dist"' | tr '\\\' /`
|
---|
932 |
|
---|
933 | [ -n "$rpmbuild_dir" -a -d "$rpmbuild_dir" ] || die "Falied to get %_topdir from rpmbuild or not directory ($rpmbuild_dir)."
|
---|
934 | [ -n "$spec_dir" -a -d "$spec_dir" ] || die "Falied to get %_specdir from rpmbuild or not directory ($spec_dir)."
|
---|
935 | [ -n "$src_dir" -a -d "$src_dir" ] || die "Falied to get %_sourcedir from rpmbuild or not directory ($src_dir)."
|
---|
936 | [ -n "$dist_mark" -a -d "$src_dir" ] || die "Falied to get %dist from rpmbuild, build command wouldn't differ from test."
|
---|
937 |
|
---|
938 | # RPMBUILD_BOT_SPEC_DIR overrides %_specdir
|
---|
939 | if [ -n "$RPMBUILD_BOT_SPEC_DIR" ] ; then
|
---|
940 | [ -d "$RPMBUILD_BOT_SPEC_DIR" ] || die "RPMBUILD_BOT_SPEC_DIR is not directory ($RPMBUILD_BOT_SPEC_DIR)."
|
---|
941 | spec_dir="$RPMBUILD_BOT_SPEC_DIR"
|
---|
942 | fi
|
---|
943 |
|
---|
944 | log_dir="$rpmbuild_dir/logs"
|
---|
945 | zip_dir="$rpmbuild_dir/zip"
|
---|
946 |
|
---|
947 | spec=`echo $spec | tr '\\\' /`
|
---|
948 |
|
---|
949 | spec_name="${spec##*/}"
|
---|
950 |
|
---|
951 | if [ "$spec_name" = "$spec" ] ; then
|
---|
952 | # No path information, use SPECS
|
---|
953 | spec_full="$spec_dir/${spec_name%.spec}.spec"
|
---|
954 | else
|
---|
955 | # Has some path, use it.
|
---|
956 | spec_full="${spec%.spec}.spec"
|
---|
957 | fi
|
---|
958 |
|
---|
959 | spec_name="${spec_name%.spec}"
|
---|
960 |
|
---|
961 | [ -z "$need_spec_file" -o -f "$spec_full" ] || die "Spec file '$spec_full' is not found."
|
---|
962 |
|
---|
963 | # Prepare some (non-rpmbuild-standard) directories.
|
---|
964 | run mkdir -p "$log_dir"
|
---|
965 | run mkdir -p "$log_dir/archive"
|
---|
966 | run mkdir -p "$log_dir/test"
|
---|
967 | run mkdir -p "$zip_dir"
|
---|
968 |
|
---|
969 | log_base="$log_dir/$spec_name"
|
---|
970 | spec_list="$log_base.list"
|
---|
971 |
|
---|
972 | start_time=$(date +%s)
|
---|
973 |
|
---|
974 | echo "Build started on $(date -R)."
|
---|
975 | echo "Package: $spec_name"
|
---|
976 | echo "Command: $command $options"
|
---|
977 |
|
---|
978 | run eval "${command_name}_cmd"
|
---|
979 |
|
---|
980 | quit 0
|
---|