Thu, 19 Apr 2018 08:51:17 +0000
Merge
mduigou@1142 | 1 | #!/bin/sh |
ohrstrom@538 | 2 | # |
mduigou@1149 | 3 | # Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
ohrstrom@538 | 4 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohrstrom@538 | 5 | # |
ohrstrom@538 | 6 | # This code is free software; you can redistribute it and/or modify it |
ohrstrom@538 | 7 | # under the terms of the GNU General Public License version 2 only, as |
ohrstrom@538 | 8 | # published by the Free Software Foundation. |
ohrstrom@538 | 9 | # |
ohrstrom@538 | 10 | # This code is distributed in the hope that it will be useful, but WITHOUT |
ohrstrom@538 | 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohrstrom@538 | 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohrstrom@538 | 13 | # version 2 for more details (a copy is included in the LICENSE file that |
ohrstrom@538 | 14 | # accompanied this code). |
ohrstrom@538 | 15 | # |
ohrstrom@538 | 16 | # You should have received a copy of the GNU General Public License version |
ohrstrom@538 | 17 | # 2 along with this work; if not, write to the Free Software Foundation, |
ohrstrom@538 | 18 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohrstrom@538 | 19 | # |
ohrstrom@538 | 20 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohrstrom@538 | 21 | # or visit www.oracle.com if you need additional information or have any |
ohrstrom@538 | 22 | # questions. |
ohrstrom@538 | 23 | # |
ohrstrom@538 | 24 | |
mduigou@1148 | 25 | # Shell script for a fast parallel forest/trees command |
ohrstrom@538 | 26 | |
mduigou@1148 | 27 | usage() { |
mduigou@1148 | 28 | echo "usage: $0 [-h|--help] [-q|--quiet] [-v|--verbose] [-s|--sequential] [--] <command> [commands...]" > ${status_output} |
mduigou@1148 | 29 | echo "Environment variables which modify behaviour:" |
mduigou@1148 | 30 | echo " HGFOREST_QUIET : (boolean) If 'true' then standard output is redirected to /dev/null" |
mduigou@1148 | 31 | echo " HGFOREST_VERBOSE : (boolean) If 'true' then Mercurial asked to produce verbose output" |
mduigou@1148 | 32 | echo " HGFOREST_SEQUENTIAL : (boolean) If 'true' then repos are processed sequentially. Disables concurrency" |
mduigou@1148 | 33 | echo " HGFOREST_GLOBALOPTS : (string, must begin with space) Additional Mercurial global options" |
mduigou@1148 | 34 | echo " HGFOREST_REDIRECT : (file path) Redirect standard output to specified file" |
mduigou@1148 | 35 | echo " HGFOREST_FIFOS : (boolean) Default behaviour for FIFO detection. Does not override FIFOs disabled" |
mduigou@1148 | 36 | echo " HGFOREST_CONCURRENCY: (positive integer) Number of repos to process concurrently" |
mduigou@1148 | 37 | echo " HGFOREST_DEBUG : (boolean) If 'true' then temp files are retained" |
mduigou@1148 | 38 | exit 1 |
mduigou@1148 | 39 | } |
mduigou@1148 | 40 | |
mduigou@1148 | 41 | global_opts="${HGFOREST_GLOBALOPTS:-}" |
mduigou@1148 | 42 | status_output="${HGFOREST_REDIRECT:-/dev/stdout}" |
mduigou@1148 | 43 | qflag="${HGFOREST_QUIET:-false}" |
mduigou@1148 | 44 | vflag="${HGFOREST_VERBOSE:-false}" |
mduigou@1148 | 45 | sflag="${HGFOREST_SEQUENTIAL:-false}" |
mduigou@1141 | 46 | while [ $# -gt 0 ] |
mduigou@1141 | 47 | do |
mduigou@1141 | 48 | case $1 in |
mduigou@1148 | 49 | -h | --help ) |
mduigou@1148 | 50 | usage |
mduigou@1148 | 51 | ;; |
mduigou@1148 | 52 | |
mduigou@1141 | 53 | -q | --quiet ) |
mduigou@1141 | 54 | qflag="true" |
mduigou@1141 | 55 | ;; |
mduigou@1141 | 56 | |
mduigou@1141 | 57 | -v | --verbose ) |
mduigou@1141 | 58 | vflag="true" |
mduigou@1141 | 59 | ;; |
mduigou@1141 | 60 | |
chegar@1143 | 61 | -s | --sequential ) |
chegar@1143 | 62 | sflag="true" |
chegar@1143 | 63 | ;; |
chegar@1143 | 64 | |
mduigou@1141 | 65 | '--' ) # no more options |
mduigou@1141 | 66 | shift; break |
mduigou@1141 | 67 | ;; |
mduigou@1141 | 68 | |
mduigou@1141 | 69 | -*) # bad option |
mduigou@1141 | 70 | usage |
mduigou@1141 | 71 | ;; |
mduigou@1141 | 72 | |
mduigou@1141 | 73 | * ) # non option |
mduigou@1141 | 74 | break |
mduigou@1141 | 75 | ;; |
mduigou@1141 | 76 | esac |
mduigou@1141 | 77 | shift |
mduigou@1141 | 78 | done |
mduigou@1141 | 79 | |
mduigou@1148 | 80 | # silence standard output? |
mduigou@1148 | 81 | if [ ${qflag} = "true" ] ; then |
mduigou@1148 | 82 | global_opts="${global_opts} -q" |
mduigou@1148 | 83 | status_output="/dev/null" |
mduigou@1148 | 84 | fi |
mduigou@1141 | 85 | |
mduigou@1148 | 86 | # verbose output? |
mduigou@1148 | 87 | if [ ${vflag} = "true" ] ; then |
mduigou@1148 | 88 | global_opts="${global_opts} -v" |
mduigou@1148 | 89 | fi |
mduigou@1141 | 90 | |
mduigou@1148 | 91 | # Make sure we have a command. |
mduigou@1148 | 92 | if [ $# -lt 1 -o -z "${1:-}" ] ; then |
mduigou@1141 | 93 | echo "ERROR: No command to hg supplied!" |
mduigou@1141 | 94 | usage |
ohrstrom@538 | 95 | fi |
ohrstrom@538 | 96 | |
mduigou@1148 | 97 | command="$1"; shift |
mduigou@1148 | 98 | command_args="${@:-}" |
mduigou@1144 | 99 | |
ohrstrom@538 | 100 | # Clean out the temporary directory that stores the pid files. |
ohrstrom@538 | 101 | tmp=/tmp/forest.$$ |
ohrstrom@538 | 102 | rm -f -r ${tmp} |
ohrstrom@538 | 103 | mkdir -p ${tmp} |
ohrstrom@538 | 104 | |
mduigou@1148 | 105 | |
mduigou@1148 | 106 | if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then |
mduigou@1148 | 107 | echo "DEBUG: temp files are in: ${tmp}" |
mduigou@1148 | 108 | fi |
mduigou@1148 | 109 | |
mduigou@1148 | 110 | # Check if we can use fifos for monitoring sub-process completion. |
mduigou@1148 | 111 | echo "1" > ${tmp}/read |
mduigou@1148 | 112 | while_subshell=1 |
mduigou@1148 | 113 | while read line; do |
mduigou@1148 | 114 | while_subshell=0 |
mduigou@1148 | 115 | break; |
mduigou@1148 | 116 | done < ${tmp}/read |
mduigou@1148 | 117 | rm ${tmp}/read |
mduigou@1148 | 118 | |
mduigou@1148 | 119 | on_windows=`uname -s | egrep -ic -e 'cygwin|msys'` |
mduigou@1148 | 120 | |
mduigou@1148 | 121 | if [ ${while_subshell} = "1" -o ${on_windows} = "1" ]; then |
mduigou@1148 | 122 | # cygwin has (2014-04-18) broken (single writer only) FIFOs |
mduigou@1148 | 123 | # msys has (2014-04-18) no FIFOs. |
mduigou@1148 | 124 | # older shells create a sub-shell for redirect to while |
mduigou@1148 | 125 | have_fifos="false" |
mduigou@1148 | 126 | else |
mduigou@1148 | 127 | have_fifos="${HGFOREST_FIFOS:-true}" |
mduigou@1148 | 128 | fi |
mduigou@1148 | 129 | |
ohrstrom@538 | 130 | safe_interrupt () { |
chegar@615 | 131 | if [ -d ${tmp} ]; then |
chegar@615 | 132 | if [ "`ls ${tmp}/*.pid`" != "" ]; then |
mduigou@1148 | 133 | echo "Waiting for processes ( `cat ${tmp}/.*.pid ${tmp}/*.pid 2> /dev/null | tr '\n' ' '`) to terminate nicely!" > ${status_output} |
ohrstrom@538 | 134 | sleep 1 |
ohrstrom@538 | 135 | # Pipe stderr to dev/null to silence kill, that complains when trying to kill |
ohrstrom@538 | 136 | # a subprocess that has already exited. |
chegar@615 | 137 | kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null |
chegar@615 | 138 | wait |
mduigou@1141 | 139 | echo "Interrupt complete!" > ${status_output} |
chegar@615 | 140 | fi |
mduigou@1141 | 141 | rm -f -r ${tmp} |
ohrstrom@538 | 142 | fi |
mduigou@1141 | 143 | exit 130 |
ohrstrom@538 | 144 | } |
ohrstrom@538 | 145 | |
ohrstrom@538 | 146 | nice_exit () { |
chegar@615 | 147 | if [ -d ${tmp} ]; then |
mduigou@1148 | 148 | if [ "`ls -A ${tmp} 2> /dev/null`" != "" ]; then |
chegar@615 | 149 | wait |
chegar@615 | 150 | fi |
mduigou@1148 | 151 | if [ "${HGFOREST_DEBUG:-false}" != "true" ] ; then |
mduigou@1148 | 152 | rm -f -r ${tmp} |
mduigou@1148 | 153 | fi |
ohrstrom@538 | 154 | fi |
ohrstrom@538 | 155 | } |
ohrstrom@538 | 156 | |
ohrstrom@538 | 157 | trap 'safe_interrupt' INT QUIT |
ohrstrom@538 | 158 | trap 'nice_exit' EXIT |
chegar@615 | 159 | |
mduigou@1141 | 160 | subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" |
mduigou@1141 | 161 | subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" |
mduigou@1141 | 162 | |
ohrstrom@538 | 163 | # Only look in specific locations for possible forests (avoids long searches) |
ohrstrom@538 | 164 | pull_default="" |
ohrstrom@538 | 165 | repos="" |
ohrstrom@538 | 166 | repos_extra="" |
mduigou@1142 | 167 | if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then |
mduigou@1148 | 168 | # we must be a clone |
mduigou@1142 | 169 | if [ ! -f .hg/hgrc ] ; then |
mduigou@1141 | 170 | echo "ERROR: Need initial repository to use this script" > ${status_output} |
ohrstrom@538 | 171 | exit 1 |
ohrstrom@538 | 172 | fi |
mduigou@1142 | 173 | |
mduigou@1148 | 174 | # the clone must know where it came from (have a default pull path). |
mduigou@1142 | 175 | pull_default=`hg paths default` |
mduigou@1142 | 176 | if [ "${pull_default}" = "" ] ; then |
mduigou@1142 | 177 | echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output} |
mduigou@1142 | 178 | exit 1 |
mduigou@1142 | 179 | fi |
mduigou@1142 | 180 | |
mduigou@1148 | 181 | # determine which sub repos need to be cloned. |
ohrstrom@538 | 182 | for i in ${subrepos} ; do |
ohrstrom@538 | 183 | if [ ! -f ${i}/.hg/hgrc ] ; then |
ohrstrom@538 | 184 | repos="${repos} ${i}" |
ohrstrom@538 | 185 | fi |
ohrstrom@538 | 186 | done |
mduigou@1145 | 187 | |
mduigou@1145 | 188 | pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` |
mduigou@1145 | 189 | |
mduigou@1148 | 190 | if [ -n "${command_args}" ] ; then |
mduigou@1148 | 191 | # if there is an "extra sources" path then reparent "extra" repos to that path |
mduigou@1142 | 192 | if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then |
mduigou@1142 | 193 | echo "ERROR: Need initial clone from non-local source" > ${status_output} |
mduigou@1142 | 194 | exit 1 |
mduigou@1142 | 195 | fi |
mduigou@1142 | 196 | pull_extra="${command_args}/${pull_default_tail}" |
mduigou@1148 | 197 | |
mduigou@1148 | 198 | # determine which extra subrepos need to be cloned. |
ohrstrom@538 | 199 | for i in ${subrepos_extra} ; do |
ohrstrom@538 | 200 | if [ ! -f ${i}/.hg/hgrc ] ; then |
ohrstrom@538 | 201 | repos_extra="${repos_extra} ${i}" |
ohrstrom@538 | 202 | fi |
ohrstrom@538 | 203 | done |
mduigou@1145 | 204 | else |
mduigou@1145 | 205 | if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then |
mduigou@1148 | 206 | # local source repo. Clone the "extra" subrepos that exist there. |
mduigou@1145 | 207 | for i in ${subrepos_extra} ; do |
mduigou@1145 | 208 | if [ -f ${pull_default}/${i}/.hg/hgrc -a ! -f ${i}/.hg/hgrc ] ; then |
mduigou@1145 | 209 | # sub-repo there in source but not here |
mduigou@1145 | 210 | repos_extra="${repos_extra} ${i}" |
mduigou@1145 | 211 | fi |
mduigou@1145 | 212 | done |
mduigou@1145 | 213 | fi |
ohrstrom@538 | 214 | fi |
mduigou@1148 | 215 | |
ohrstrom@538 | 216 | # Any repos to deal with? |
ohrstrom@538 | 217 | if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then |
mduigou@1141 | 218 | echo "No repositories to process." > ${status_output} |
ohrstrom@538 | 219 | exit |
ohrstrom@538 | 220 | fi |
mduigou@1148 | 221 | |
mduigou@1148 | 222 | # Repos to process concurrently. Clone does better with low concurrency. |
mduigou@1148 | 223 | at_a_time="${HGFOREST_CONCURRENCY:-2}" |
ohrstrom@538 | 224 | else |
mduigou@1148 | 225 | # Process command for all of the present repos |
mduigou@1141 | 226 | for i in . ${subrepos} ${subrepos_extra} ; do |
mduigou@1141 | 227 | if [ -d ${i}/.hg ] ; then |
mduigou@1141 | 228 | repos="${repos} ${i}" |
mduigou@1141 | 229 | fi |
ohrstrom@538 | 230 | done |
mduigou@1141 | 231 | |
mduigou@1141 | 232 | # Any repos to deal with? |
mduigou@1141 | 233 | if [ "${repos}" = "" ] ; then |
mduigou@1141 | 234 | echo "No repositories to process." > ${status_output} |
mduigou@1141 | 235 | exit |
mduigou@1141 | 236 | fi |
mduigou@1141 | 237 | |
mduigou@1141 | 238 | # any of the repos locked? |
mduigou@1148 | 239 | locked="" |
ohrstrom@538 | 240 | for i in ${repos} ; do |
ohrstrom@538 | 241 | if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then |
ohrstrom@538 | 242 | locked="${i} ${locked}" |
ohrstrom@538 | 243 | fi |
ohrstrom@538 | 244 | done |
mduigou@1141 | 245 | if [ "${locked}" != "" ] ; then |
mduigou@1141 | 246 | echo "ERROR: These repositories are locked: ${locked}" > ${status_output} |
mduigou@1141 | 247 | exit 1 |
mduigou@1141 | 248 | fi |
mduigou@1148 | 249 | |
mduigou@1148 | 250 | # Repos to process concurrently. |
mduigou@1148 | 251 | at_a_time="${HGFOREST_CONCURRENCY:-8}" |
ohrstrom@538 | 252 | fi |
ohrstrom@538 | 253 | |
ohrstrom@538 | 254 | # Echo out what repositories we do a command on. |
mduigou@1141 | 255 | echo "# Repositories: ${repos} ${repos_extra}" > ${status_output} |
ohrstrom@538 | 256 | |
mduigou@1141 | 257 | if [ "${command}" = "serve" ] ; then |
mduigou@1148 | 258 | # "serve" is run for all the repos as one command. |
mduigou@1141 | 259 | ( |
mduigou@1141 | 260 | ( |
mduigou@1148 | 261 | cwd=`pwd` |
mduigou@1148 | 262 | serving=`basename ${cwd}` |
mduigou@1141 | 263 | ( |
mduigou@1141 | 264 | echo "[web]" |
mduigou@1148 | 265 | echo "description = ${serving}" |
mduigou@1141 | 266 | echo "allow_push = *" |
mduigou@1141 | 267 | echo "push_ssl = False" |
mduigou@1141 | 268 | |
mduigou@1141 | 269 | echo "[paths]" |
mduigou@1148 | 270 | for i in ${repos} ; do |
mduigou@1141 | 271 | if [ "${i}" != "." ] ; then |
mduigou@1148 | 272 | echo "/${serving}/${i} = ${i}" |
mduigou@1141 | 273 | else |
mduigou@1148 | 274 | echo "/${serving} = ${cwd}" |
mduigou@1141 | 275 | fi |
mduigou@1141 | 276 | done |
mduigou@1141 | 277 | ) > ${tmp}/serve.web-conf |
mduigou@1141 | 278 | |
mduigou@1148 | 279 | echo "serving root repo ${serving}" > ${status_output} |
mduigou@1141 | 280 | |
mduigou@1148 | 281 | echo "hg${global_opts} serve" > ${status_output} |
mduigou@1141 | 282 | (PYTHONUNBUFFERED=true hg${global_opts} serve -A ${status_output} -E ${status_output} --pid-file ${tmp}/serve.pid --web-conf ${tmp}/serve.web-conf; echo "$?" > ${tmp}/serve.pid.rc ) 2>&1 & |
mduigou@1141 | 283 | ) 2>&1 | sed -e "s@^@serve: @" > ${status_output} |
mduigou@1141 | 284 | ) & |
mduigou@1141 | 285 | else |
mduigou@1141 | 286 | # Run the supplied command on all repos in parallel. |
mduigou@1144 | 287 | |
mduigou@1144 | 288 | # n is the number of subprocess started or which might still be running. |
mduigou@1141 | 289 | n=0 |
mduigou@1148 | 290 | if [ ${have_fifos} = "true" ]; then |
mduigou@1144 | 291 | # if we have fifos use them to detect command completion. |
mduigou@1144 | 292 | mkfifo ${tmp}/fifo |
mduigou@1144 | 293 | exec 3<>${tmp}/fifo |
mduigou@1144 | 294 | fi |
mduigou@1144 | 295 | |
mduigou@1148 | 296 | # iterate over all of the subrepos. |
mduigou@1141 | 297 | for i in ${repos} ${repos_extra} ; do |
mduigou@1141 | 298 | n=`expr ${n} '+' 1` |
mduigou@1141 | 299 | repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` |
mduigou@1141 | 300 | reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` |
mduigou@1141 | 301 | pull_base="${pull_default}" |
mduigou@1148 | 302 | |
mduigou@1148 | 303 | # regular repo or "extra" repo? |
mduigou@1148 | 304 | for j in ${repos_extra} ; do |
mduigou@1148 | 305 | if [ "${i}" = "${j}" ] ; then |
mduigou@1148 | 306 | # it's an "extra" |
mduigou@1148 | 307 | pull_base="${pull_extra}" |
ohrstrom@538 | 308 | fi |
mduigou@1141 | 309 | done |
mduigou@1148 | 310 | |
mduigou@1148 | 311 | # remove trailing slash |
mduigou@1144 | 312 | pull_base="`echo ${pull_base} | sed -e 's@[/]*$@@'`" |
mduigou@1148 | 313 | |
mduigou@1148 | 314 | # execute the command on the subrepo |
mduigou@1141 | 315 | ( |
mduigou@1141 | 316 | ( |
mduigou@1142 | 317 | if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then |
mduigou@1148 | 318 | # some form of clone |
mduigou@1148 | 319 | clone_newrepo="${pull_base}/${i}" |
mduigou@1148 | 320 | parent_path="`dirname ${i}`" |
mduigou@1148 | 321 | if [ "${parent_path}" != "." ] ; then |
mduigou@1141 | 322 | times=0 |
mduigou@1148 | 323 | while [ ! -d "${parent_path}" ] ; do ## nested repo, ensure containing dir exists |
mduigou@1148 | 324 | if [ "${sflag}" = "true" ] ; then |
mduigou@1148 | 325 | # Missing parent is fatal during sequential operation. |
mduigou@1148 | 326 | echo "ERROR: Missing parent path: ${parent_path}" > ${status_output} |
mduigou@1148 | 327 | exit 1 |
mduigou@1148 | 328 | fi |
mduigou@1149 | 329 | times=`expr ${times} '+' 1` |
mduigou@1141 | 330 | if [ `expr ${times} '%' 10` -eq 0 ] ; then |
mduigou@1148 | 331 | echo "${parent_path} still not created, waiting..." > ${status_output} |
mduigou@1141 | 332 | fi |
mduigou@1141 | 333 | sleep 5 |
mduigou@1141 | 334 | done |
mduigou@1141 | 335 | fi |
mduigou@1148 | 336 | # run the clone command. |
mduigou@1148 | 337 | echo "hg${global_opts} clone ${clone_newrepo} ${i}" > ${status_output} |
mduigou@1148 | 338 | (PYTHONUNBUFFERED=true hg${global_opts} clone ${clone_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 & |
mduigou@1141 | 339 | else |
mduigou@1148 | 340 | # run the command. |
mduigou@1142 | 341 | echo "cd ${i} && hg${global_opts} ${command} ${command_args}" > ${status_output} |
mduigou@1142 | 342 | cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_args}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 & |
mduigou@1141 | 343 | fi |
mduigou@1141 | 344 | |
mduigou@1141 | 345 | echo $! > ${tmp}/${repopidfile}.pid |
mduigou@1141 | 346 | ) 2>&1 | sed -e "s@^@${reponame}: @" > ${status_output} |
mduigou@1148 | 347 | # tell the fifo waiter that this subprocess is done. |
mduigou@1148 | 348 | if [ ${have_fifos} = "true" ]; then |
mduigou@1148 | 349 | echo "${i}" >&3 |
mduigou@1144 | 350 | fi |
mduigou@1141 | 351 | ) & |
mduigou@1141 | 352 | |
mduigou@1148 | 353 | if [ "${sflag}" = "true" ] ; then |
mduigou@1148 | 354 | # complete this task before starting another. |
mduigou@1148 | 355 | wait |
mduigou@1144 | 356 | else |
mduigou@1148 | 357 | if [ "${have_fifos}" = "true" ]; then |
mduigou@1148 | 358 | # check on count of running subprocesses and possibly wait for completion |
mduigou@1148 | 359 | if [ ${n} -ge ${at_a_time} ] ; then |
mduigou@1148 | 360 | # read will block until there are completed subprocesses |
mduigou@1148 | 361 | while read repo_done; do |
mduigou@1148 | 362 | n=`expr ${n} '-' 1` |
mduigou@1148 | 363 | if [ ${n} -lt ${at_a_time} ] ; then |
mduigou@1148 | 364 | # we should start more subprocesses |
mduigou@1148 | 365 | break; |
mduigou@1148 | 366 | fi |
mduigou@1148 | 367 | done <&3 |
mduigou@1148 | 368 | fi |
mduigou@1148 | 369 | else |
mduigou@1144 | 370 | # Compare completions to starts |
mduigou@1148 | 371 | completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`" |
mduigou@1148 | 372 | while [ `expr ${n} '-' ${completed}` -ge ${at_a_time} ] ; do |
mduigou@1144 | 373 | # sleep a short time to give time for something to complete |
mduigou@1144 | 374 | sleep 1 |
mduigou@1148 | 375 | completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`" |
mduigou@1144 | 376 | done |
mduigou@1144 | 377 | fi |
chegar@1143 | 378 | fi |
ohrstrom@538 | 379 | done |
mduigou@1141 | 380 | fi |
chegar@615 | 381 | |
mduigou@1144 | 382 | # Wait for all subprocesses to complete |
ohrstrom@538 | 383 | wait |
ohrstrom@538 | 384 | |
chegar@615 | 385 | # Terminate with exit 0 only if all subprocesses were successful |
chegar@615 | 386 | ec=0 |
chegar@615 | 387 | if [ -d ${tmp} ]; then |
mduigou@1148 | 388 | rcfiles="`(ls -a ${tmp}/*.pid.rc 2> /dev/null) || echo ''`" |
mduigou@1148 | 389 | for rc in ${rcfiles} ; do |
chegar@615 | 390 | exit_code=`cat ${rc} | tr -d ' \n\r'` |
chegar@615 | 391 | if [ "${exit_code}" != "0" ] ; then |
mduigou@1148 | 392 | repo="`echo ${rc} | sed -e 's@^'${tmp}'@@' -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`" |
mduigou@1148 | 393 | echo "WARNING: ${repo} exited abnormally (${exit_code})" > ${status_output} |
chegar@615 | 394 | ec=1 |
chegar@615 | 395 | fi |
chegar@615 | 396 | done |
chegar@615 | 397 | fi |
chegar@615 | 398 | exit ${ec} |