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