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