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