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