Annotation of pkgsrc/pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh, revision 1.42
1.1 gdt 1: #!/bin/sh
2:
1.42 ! tnn 3: # $NetBSD: pkg_rolling-replace.sh,v 1.41 2021/01/09 19:12:46 rhialto Exp $
1.1 gdt 4: #<license>
5: # Copyright (c) 2006 BBN Technologies Corp. All rights reserved.
6: #
7: # Redistribution and use in source and binary forms, with or without
8: # modification, are permitted provided that the following conditions
9: # are met:
10: # 1. Redistributions of source code must retain the above copyright
11: # notice, this list of conditions and the following disclaimer.
12: # 2. Redistributions in binary form must reproduce the above copyright
13: # notice, this list of conditions and the following disclaimer in the
14: # documentation and/or other materials provided with the distribution.
15: # 3. Neither the name of BBN Technologies nor the names of its contributors
16: # may be used to endorse or promote products derived from this software
17: # without specific prior written permission.
18: #
19: # THIS SOFTWARE IS PROVIDED BY BBN TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
20: # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: # ARE DISCLAIMED. IN NO EVENT SHALL BBN TECHNOLOGIES OR CONTRIBUTORS BE
23: # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29: # POSSIBILITY OF SUCH DAMAGE.
30: #
31: # Effort sponsored in part by the Defense Advanced Research Projects
32: # Agency (DARPA) and the Department of the Interior National Business
33: # Center under agreement number NBCHC050166.
34: #</license>
35:
36: # REVIEW NOTATION LEGEND
37: # XXX marks things that are broken/kludgy
38: # TODO marks things that need to be done
39: # FIXED marks items fixed, needs review and deletion of FIXED comment
40:
41: # Items to be completed for initial release:
42:
43: # TODO: move bulk of help into a real man page.
44:
45: # Items for future work (some imply changes in pkgsrc, not necessarily here)
46: #
47: # Make a pass over all packages for build depends, and rememeber
48: # which packages have been so checked. Check newly unsafe packages.
49: # The current lazy evaluation can perhaps fail to do things in the
50: # right order. Alternatively, explain why the current scheme is safe
51: # and preferred.
52: #
53: # Consider expansion to update via binary packages. This raises
54: # interesting questions about ABIs and binary builds
55: #
56: # Deal with conflicts in a smarter way, perhaps more automatically.
57: # This is hard because just removing packages is not ok.
58: #
59: # Handle foo being split into foo and foo-share. Now, make replace
60: # of foo pulls in foo-share which conflicts with foo. This needlessly
61: # loses.
62: #
63:
1.3 tnn 64: # Substituted by pkgsrc at pre-configure time.
1.4 tnn 65: MAKE="@MAKE@"
1.15 tnn 66: AWK="@AWK@"
1.3 tnn 67:
1.19 apb 68: if [ -z "$MAKECONF" ] ; then
69: for mkconf in "@MAKECONF@" "@PREFIX@/etc/mk.conf" /etc/mk.conf ; do
70: if [ -f "$mkconf" ] ; then
71: MAKECONF="$mkconf"
72: break
73: fi
74: done
75: fi
76: if [ -z "$MAKECONF" -o ! -f "$MAKECONF" ] ; then
77: MAKECONF=/dev/null
78: fi
1.7 tnn 79: test -f "$MAKECONF" && test -z "$PKGSRCDIR" && PKGSRCDIR="` \
80: printf '.include "%s"\n_print_pkgsrcdir:\n\t@echo "${PKGSRCDIR}"\n' \
1.8 tnn 81: "$MAKECONF" | "$MAKE" -f - BSD_PKG_MK=1 _print_pkgsrcdir`"
1.19 apb 82: if [ -z "$PKGSRCDIR" ] ; then
83: for dir in . .. ../.. /usr/pkgsrc ; do
84: if [ -f "${dir}/mk/bsd.pkg.mk" ]; then
85: case "${dir}" in
86: /*) PKGSRCDIR="${dir}" ;;
87: *) PKGSRCDIR="$( cd "${dir}" >/dev/null 2>&1 && pwd )" ;;
88: esac
89: break
90: fi
91: done
92: fi
93: test -z "$PKGSRCDIR" && echo >&2 "Please set PKGSRCDIR" && exit 1
1.12 tnn 94: test -z "$PKG_CHK" && PKG_CHK="@PKG_CHK@"
1.42 ! tnn 95: test -z "$PKG_ADMIN" && PKG_ADMIN="@PKG_ADMIN_CMD@"
1.12 tnn 96: test -z "$PKG_INFO" && PKG_INFO="@PKG_INFO_CMD@"
1.1 gdt 97:
1.19 apb 98: export PKGSRCDIR
99:
1.1 gdt 100: unset PKG_PATH || true #or pkgsrc makefiles will complain
101:
102: usage()
103: {
104: echo "Usage: pkg_rolling-replace [opts]
105: -h This help
1.34 abs 106: -B Pass -B to pkg_chk (only applies with -u)
1.22 sno 107: -F Fetch sources (including depends) only, don't build
108: -k Keep running, even on error
1.1 gdt 109: -n Don't actually do make replace
1.13 tnn 110: -r Just replace, don't create binary packages
111: -s Replace even if the ABIs are still compatible ("strict")
1.41 rhialto 112: -u Update mismatched packages
1.1 gdt 113: -v Verbose
1.25 sno 114: -D VAR=VAL Passes given variables and values to make
1.22 sno 115: -L <path> Log to path (<path>/pkgdir/pkg)
1.20 wiz 116: -X <pkg> exclude <pkg> from being rebuilt
1.41 rhialto 117: -x <pkg> exclude <pkg> from mismatch check
1.1 gdt 118:
119: pkg_rolling-replace does 'make replace' on one package at a time,
120: tsorting the packages being replaced according to their
121: interdependencies, which avoids most duplicate rebuilds.
122:
123: pkg_rolling-replace can be used in one of two ways:
124:
125: - 'make replace' is unsafe in that, if the replaced package's ABI
126: changes, its dependent packages may break. If this happens, run
127: 'pkg_rolling-replace' (no arguments) to rebuild them against the
128: new version.
129:
1.41 rhialto 130: - 'pkg_chk -u' will delete all your mismatched packages (where the
131: package version does not match the pkgsrc version), then reinstall
132: them one at a time, leaving you without those packages in the
133: meantime. 'pkg_rolling-replace -u' will instead upgrade them in
134: place, allowing you to keep using your system in the meantime
135: (maybe...if you're lucky...because pkg_rolling-replace replaces
136: the \"deepest\" dependency first, things could still break if that
137: happens to be a fundamental library whose ABI has changed).
1.1 gdt 138: "
139: exit 1
140: }
141:
142: # pkg_rolling-replace's output is intermingled with pkgsrc make
143: # output. Thus, we use a different prefix. pkgsrc uses '===>' for
144: # major steps, and '=>' for minor ones. Thus, we use 'RR>'.
145:
146: OPI='RR>'
147: OPC='rr>' # continuation
148:
149:
150: # Echo the names of packages needing updates, versions stripped. This
151: # has been tested with pkg_chk 1.76. Older versions are not
152: # supported. Newer versions may or may not work (patches welcome).
153: check_packages_mismatched()
154: {
1.39 gdt 155: ${PKG_CHK} -u -q $opt_B | egrep -v missing | while read line; do
1.1 gdt 156: # duplicate output of pkg_chk to stderr (bypass $(...) or `...`)
1.11 tnn 157: echo "${OPC} $line" 1>&2
1.1 gdt 158: # Look for the first thing that looks like pkg-version rather
159: # than category/pkg and remove the version.
160: for word in $line; do
1.5 tnn 161: if [ "$(echo $word | egrep '^[^/]+-[0-9][^-/]*$')" ]; then
1.41 rhialto 162: if [ -z "$opt_F" ]; then
1.42 ! tnn 163: ${PKG_ADMIN} set mismatch=YES "$word" 1>&2
1.41 rhialto 164: fi
1.5 tnn 165: echo $word | sed 's/-[0-9][^-]*$//'
1.1 gdt 166: break #done with this line
167: fi
168: done
169: done
170: }
171:
172: # usage: check_packages_w_flag flag
173: # echo packages with flag=YES
174: check_packages_w_flag()
175: {
176: _flag=$1; shift
1.12 tnn 177: for pkgver in $(${PKG_INFO} -e '*'); do
178: if ${PKG_INFO} -Bq $pkgver \
1.1 gdt 179: | egrep "^$_flag=[Yy][Ee][Ss]" > /dev/null; then
1.5 tnn 180: echo $pkgver | sed 's/-[0-9][^-]*$//'
1.1 gdt 181: fi
182: done
183: }
184:
185: # echo dep->pkg edges for all installed packages
186: depgraph_installed()
187: {
1.15 tnn 188: ${PKG_INFO} -N '*' | ${AWK} ' \
189: /^Information for/ { \
190: pkg=$3; sub("-[0-9][^-]*:$", "", pkg); \
191: print pkg" "pkg; \
192: state=1; \
193: } \
1.16 gdt 194: /^\** PACKAGE MAY NOT BE DELETED \**$/ { state=3; } \
1.15 tnn 195: /^./ { \
196: if (state == 2) { \
197: dep=$1; sub("-[0-9][^-]*$", "", dep); \
198: print dep" "pkg; \
199: } \
200: } \
201: /^Built using/ { \
202: state=2 \
203: } \
204: '
1.1 gdt 205: }
206:
207: # usage: who_requires pkg --in-graph DEPGRAPH
208: who_requires()
209: {
210: _target=$1; shift
211: test "$1" = '--in-graph' && shift || return $((false))
212:
213: while [ $# -gt 0 ]; do
214: _dep=$1; _pkg=$2; shift 2;
215: if [ $_dep = $_target -a $_dep != $_pkg ]; then
216: echo $_pkg
217: fi
218: done
219: }
220:
221: # usage: is_member x list
222: # return true (0) if x appears in list, false (1) otherwise
223: is_member()
224: {
225: _x="$1"; shift;
226: while [ $# -gt 0 -a "$1" != "$_x" ]; do
227: shift
228: done
229:
230: test $# -gt 0
231: }
232:
233: # usage: exclude list1 --from list2
234: # echo list2 with items from list1 excluded
235: exclude()
236: {
237: _excl=
238: while [ $# -gt 0 -a $1 != "--from" ]; do
239: _excl="$_excl $1"
240: shift
241: done
242: if [ $# -gt 0 ]; then
243: shift #discard '--from'
244: fi
245: while [ $# -gt 0 ]; do
246: is_member $1 $_excl || echo $1
247: shift
248: done
249: }
250:
251: # usage: uniquify list
252: # just does sort -u on list (equiv. to sort | uniq)
253: # CAUTION: reorders list
254: uniqify()
255: {
256: for _x in $*; do echo $_x; done | sort -u
257: }
258:
259: verbose()
260: {
261: if [ -n "$opt_v" ]; then
262: echo "$@"
263: fi
264: }
265:
266: vsleep()
267: {
268: if [ -n "$opt_v" ]; then
269: sleep $1
270: fi
271: }
272:
1.22 sno 273: report()
274: {
1.26 tnn 275: for a in $SUCCEEDED; do
1.22 sno 276: verbose "+ $a"
277: done
278:
279: for a in $FAILED; do
280: verbose "- $a"
281: done
282: }
283:
1.13 tnn 284: abort()
285: {
1.26 tnn 286: echo "*** $1"
287: echo "*** Please read the errors listed above, fix the problem,"
288: echo "*** then re-run pkg_rolling-replace to continue."
289: report
290: exit 1
291: }
292:
293: error()
294: {
1.28 tnn 295: if [ -z "$opt_k" ]; then
1.26 tnn 296: abort "$1"
297: fi
298: echo "*** $1"
299: }
300:
301: mark_as_succeeded()
302: {
1.27 tnn 303: SUCCEEDED=$(uniqify $SUCCEEDED $1)
1.26 tnn 304: }
305:
306: mark_as_failed()
307: {
1.27 tnn 308: FAILED=$(uniqify $FAILED $1)
1.13 tnn 309: }
310:
1.22 sno 311: todo()
312: {
313: if [ -z "$opt_F" ]; then
314: verbose "${OPI} Packages to rebuild:"
315: verbose "${OPC} MISMATCH_TODO=[$(echo $MISMATCH_TODO)]" #strip newlines
316: verbose "${OPC} REBUILD_TODO=[$(echo $REBUILD_TODO)]"
317: verbose "${OPC} UNSAFE_TODO=[$(echo $UNSAFE_TODO)]"
318: REPLACE_TODO=$(uniqify $MISMATCH_TODO $REBUILD_TODO $UNSAFE_TODO)
319: else
320: REPLACE_TODO=$(uniqify $MISMATCH_TODO)
321: verbose "${OPI} Packages to fetch:"
322: verbose "${OPC} MISMATCH_TODO=[$(echo $MISMATCH_TODO)]" #strip newlines
323: fi
324: REPLACE_TODO=$(exclude $REALLYEXCLUDE --from $REPLACE_TODO)
325: if [ -n "$FAILED" ]; then
326: REPLACE_TODO=$(exclude $FAILED --from $REPLACE_TODO)
327: fi
328: vsleep 2
329: }
330:
1.1 gdt 331: ######################################################################
332: ##
333: ## main()
334: ##
335:
336: EXCLUDE=
1.25 sno 337: MAKE_VAR="IN_PKG_ROLLING_REPLACE=1"
338: MAKE_VAR_SEP=" "
1.1 gdt 339:
1.34 abs 340: args=$(getopt BFhknursvD:x:X:L: $*)
1.1 gdt 341: if [ $? -ne 0 ]; then
342: opt_h=1
343: fi
344: set -- $args
345: while [ $# -gt 0 ]; do
346: case "$1" in
1.34 abs 347: -B) opt_B=-B ;;
1.22 sno 348: -F) opt_F=1 ;;
1.1 gdt 349: -h) opt_h=1 ;;
1.22 sno 350: -k) opt_k=1 ;;
1.1 gdt 351: -n) opt_n=1 ;;
1.13 tnn 352: -r) opt_r=1 ;;
353: -s) opt_s=1 ;;
1.1 gdt 354: -u) opt_u=1 ;;
355: -v) opt_v=1 ;;
1.25 sno 356: -D) MAKE_VAR="${MAKE_VAR}${MAKE_VAR_SEP}$2"; MAKE_VAR_SEP=" "; shift ;;
1.1 gdt 357: -x) EXCLUDE="$EXCLUDE $(echo $2 | sed 's/,/ /g')" ; shift ;;
1.17 apb 358: -X) REALLYEXCLUDE="$REALLYEXCLUDE $(echo $2 | sed 's/,/ /g')" ; shift ;;
1.22 sno 359: -L) LOGPATH="$2"; shift ;;
1.1 gdt 360: --) shift; break ;;
361: esac
362: shift
363: done
364:
365: if [ -n "$opt_h" ]; then
366: usage
367: fi
368:
1.13 tnn 369: if [ -n "$opt_s" ]; then
370: UNSAFE_VAR=unsafe_depends_strict
371: else
372: UNSAFE_VAR=unsafe_depends
373: fi
374:
1.25 sno 375: MAKE="${MAKE}${MAKE_VAR_SEP}${MAKE_VAR}"
376:
1.26 tnn 377: SUCCEEDED=""
1.22 sno 378: FAILED=""
379:
1.1 gdt 380: MISMATCH_TODO=
1.41 rhialto 381: if [ -n "$opt_u" ]; then
1.1 gdt 382: echo "${OPI} Checking for mismatched installed packages using pkg_chk"
383: MISMATCH_TODO=$(check_packages_mismatched)
1.41 rhialto 384: else
385: echo "${OPI} Checking for mismatched installed packages (mismatch=YES)"
386: MISMATCH_TODO=$(check_packages_w_flag 'mismatch')
1.1 gdt 387: fi
388:
1.41 rhialto 389: echo "${OPI} Excluding the following mismatched packages:"
390: echo "${OPC} EXCLUDE=[$EXCLUDE]"
391: MISMATCH_TODO=$(exclude $EXCLUDE --from $MISMATCH_TODO)
392:
1.22 sno 393: if [ -z "$opt_F" ]; then
394: echo "${OPI} Checking for rebuild-requested installed packages (rebuild=YES)"
395: REBUILD_TODO=$(check_packages_w_flag 'rebuild')
1.1 gdt 396:
1.22 sno 397: echo "${OPI} Checking for unsafe installed packages (${UNSAFE_VAR}=YES)"
398: UNSAFE_TODO=$(check_packages_w_flag ${UNSAFE_VAR})
399: fi
1.1 gdt 400:
401: # DEPGRAPH_INSTALLED is rebuilt each round. DEPGRAPH_SRC will collect
402: # edges that we discover using 'make show-depends', but that weren't
403: # listed as depends by the installed version of a package, and
404: # DEPENDS_CHECKED lists packages for which we've already done that
405: # check.
406: DEPGRAPH_INSTALLED=
407: DEPGRAPH_SRC=
408: DEPENDS_CHECKED=
409:
1.22 sno 410: todo
1.1 gdt 411:
412: depgraph_built=0
413:
414: while [ -n "$REPLACE_TODO" ]; do
1.22 sno 415: fail=
416:
1.1 gdt 417: # don't rebuild depgraph if we continued from new-depends step below
418: if [ "$depgraph_built" -eq 0 ]; then
419: echo "${OPI} Building dependency graph for installed packages"
420: DEPGRAPH_INSTALLED=$(depgraph_installed)
421: depgraph_built=1
422: fi
423:
424: echo "${OPI} Tsorting dependency graph"
425: TSORTED=$(echo $DEPGRAPH_INSTALLED $DEPGRAPH_SRC | tsort)
1.29 gdt 426: pkgdir=
1.1 gdt 427: for pkg in $TSORTED; do
428: if is_member $pkg $REPLACE_TODO; then
1.29 gdt 429: pkgdir=$(${PKG_INFO} -Q PKGPATH $pkg)
1.40 gdt 430: if [ -n "$pkgdir" ]; then
431: break;
432: else
433: error "Couldn't extract PKGPATH from installed package $pkg"
434: fi
1.1 gdt 435: fi
436: done
1.29 gdt 437: # loop should never exit without selecting a package
438: [ -n "$pkgdir" ] || abort "pkg_chk reports the following packages need replacing, but they are not installed: $REPLACE_TODO"
1.26 tnn 439:
1.1 gdt 440: echo "${OPI} Selecting $pkg ($pkgdir) as next package to replace"
441: sleep 1
442:
443: # Newer versions in pkgsrc sometimes have more depends than are
444: # recorded for the installed version (this is entirely to be
445: # expected as packages are split, renamed, and add new features).
446: # When this happens, add the new edges to the graph and re-tsort.
447: # Don't re-tsort if the new edges were already installed once
448: # (otherwise we'll go into a loop).
449:
450: # XXX I'm not sure that DEPENDS_CHECKED is necessary, or whether
451: # simply ignoring new deps that aren't in $REPLACE_TODO would have
452: # been sufficient. The DEPENDS_CHECKED approach causes one extra
453: # tsort in some cases, which isn't overly expensive.
454:
455: # XXX After tsorting and choosing what to 'make replace', we
456: # filter out packages that aren't already installed and marked for
457: # replacement. This is safe, since uninstalled depends will be
458: # pulled in automatically by 'make replace'; but in rare cases it
459: # might be non-optimal, leading to a duplicate rebuild that we
460: # would have avoided had we selected the uninstalled package in
461: # tsorted order and run 'make install' on it. This seems like
462: # such a rare case that the added complexity isn't worth it.
463:
1.30 gdt 464: # Set PKGNAME_REQD to give underlying make processes a chance to
465: # set options derived from the package name. For example,
466: # the appropriate version of Python can be derived from the
1.35 wiz 467: # package name (so, when building py34-foo, use python-3.4,
1.33 wiz 468: # not python-2.7).
1.32 gdt 469: MAKE_SET_VARS="PKGNAME_REQD=${pkg}-*"
1.30 gdt 470:
1.1 gdt 471: if ! is_member $pkg $DEPENDS_CHECKED; then
472: echo "${OPI} Checking if $pkg has new depends..."
1.12 tnn 473: OLD_DEPENDS=$(${PKG_INFO} -Nq $pkg | sed 's/-[0-9][^-]*$//')
1.1 gdt 474: NEW_DEPENDS=
475: cd "$PKGSRCDIR/$pkgdir"
1.31 obache 476: bdeps=$(@SETENV@ ${MAKE_SET_VARS} ${MAKE} show-depends VARNAME=BUILD_DEPENDS)
1.37 gdt 477: tdeps=$(@SETENV@ ${MAKE_SET_VARS} ${MAKE} show-depends VARNAME=TOOL_DEPENDS)
1.31 obache 478: rdeps=$(@SETENV@ ${MAKE_SET_VARS} ${MAKE} show-depends)
1.37 gdt 479: for depver in $bdeps $tdeps $rdeps; do
1.10 tnn 480: dep=$(echo $depver | sed -e 's/[:[].*$/0/' -e 's/[<>]=/-/' \
481: -e 's/-[0-9][^-]*$//')
1.1 gdt 482: if ! is_member $dep $OLD_DEPENDS $NEW_DEPENDS; then
483: NEW_DEPENDS="$NEW_DEPENDS $dep"
484: DEPGRAPH_SRC="$DEPGRAPH_SRC $dep $pkg"
485: fi
486: done
487: DEPENDS_CHECKED="$DEPENDS_CHECKED $pkg"
488: if [ -n "$NEW_DEPENDS" ]; then
489: echo "${OPI} $pkg has the following new depends (need to re-tsort):"
490: echo "${OPC} [$(echo $NEW_DEPENDS)]"
491: sleep 2
492: continue
493: fi
494: fi
495:
1.22 sno 496: pkgname=$(${PKG_INFO} -e $pkg)
497: if [ -n "$LOGPATH" ]; then
498: logdir="$LOGPATH/`dirname $pkgdir`"
499: logfile="$logdir/$pkgname"
500: @MKDIR@ "$logdir" || abort "mkdir -p '$logdir' failed"
501: exec 3>"$logfile"
502: tail -f "$logfile" &
503: TAILPID=$!
504: fi
505:
1.1 gdt 506: # Do make replace, with clean before, and package and clean afterwards.
1.13 tnn 507: fail=
1.23 sno 508: if [ -d "$PKGSRCDIR/$pkgdir" ]; then
509: cd "$PKGSRCDIR/$pkgdir";
1.22 sno 510: else
1.36 gdt 511: fail=1
1.26 tnn 512: mark_as_failed $pkg
513: error "No package directory '$pkgdir' for $pkg."
1.22 sno 514: fi
1.23 sno 515:
516: if [ -z "$fail" ]; then
517: if [ -z "$opt_F" ]; then
518: echo "${OPI} Replacing $pkgname"
1.31 obache 519: cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} clean || fail=1"
1.23 sno 520: if [ -n "$opt_n" ]; then
521: echo "${OPI} Would run: $cmd"
522: else
523: if [ -n "$logfile" ]; then
524: eval "$cmd" >&3 2>&3
525: else
526: eval "$cmd"
527: fi
528: if [ -n "$fail" ]; then
1.26 tnn 529: mark_as_failed $pkg
530: error "'make clean' failed for package $pkg."
1.23 sno 531: fi
532: fi
1.31 obache 533: cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} replace || fail=1" # XXX OLDNAME= support? xmlrpc-c -> xmlrpc-c-ss
1.23 sno 534: else
535: echo "${OPI} Fetching $pkgname"
1.31 obache 536: cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} fetch depends-fetch || fail=1"
1.23 sno 537: fi
538: fi
539:
1.22 sno 540: if [ -n "$opt_n" -a -z "$fail" ]; then
1.13 tnn 541: echo "${OPI} Would run: $cmd"
1.22 sno 542: elif [ -z "$fail" ]; then
543: if [ -n "$logfile" ]; then
544: eval "$cmd" >&3 2>&3
545: else
546: eval "$cmd"
547: fi
548: if [ -n "$fail" ]; then
1.26 tnn 549: mark_as_failed $pkg
550: error "'make replace' failed for package $pkg."
1.22 sno 551: fi
1.13 tnn 552: fi
1.22 sno 553: if [ -z "$opt_n" -a -z "$opt_k" -a -z "$opt_F" ]; then
1.13 tnn 554: [ -z "$(${PKG_INFO} -Q unsafe_depends_strict $pkg)" ] || \
555: abort "package $pkg still has unsafe_depends_strict."
556: [ -z "$(${PKG_INFO} -Q unsafe_depends $pkg)" ] || \
557: abort "package $pkg still has unsafe_depends."
558: [ -z "$(${PKG_INFO} -Q rebuild $pkg)" ] || \
559: abort "package $pkg is still requested to be rebuilt."
1.41 rhialto 560: [ -z "$(${PKG_INFO} -Q mismatch $pkg)" ] || \
561: abort "package $pkg is still a mismatched version."
1.1 gdt 562: fi
1.18 gdt 563: # If -r not given, make a binary package.
1.22 sno 564: if [ -z "$opt_r" -a -z "$fail" -a -z "$opt_F" ]; then
1.13 tnn 565: echo "${OPI} Packaging $(${PKG_INFO} -e $pkg)"
1.31 obache 566: cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} package || fail=1"
1.22 sno 567: if [ -n "$opt_n" -a -z "$fail" ]; then
1.13 tnn 568: echo "${OPI} Would run: $cmd"
1.22 sno 569: elif [ -z "$fail" ]; then
570: if [ -n "$logfile" ]; then
571: eval "$cmd" >&3 2>&3
572: else
573: eval "$cmd"
574: fi
575: if [ -n "$fail" ]; then
1.26 tnn 576: mark_as_failed $pkg
577: error "'make package' failed for package $pkg."
1.22 sno 578: fi
1.13 tnn 579: fi
1.1 gdt 580: fi
1.18 gdt 581: # Clean
1.22 sno 582: if [ -z "$opt_n" -a -z "$fail" -a -z "$opt_F" ]; then
1.31 obache 583: cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} clean || fail=1"
1.22 sno 584: if [ -n "$logfile" ]; then
585: eval "$cmd" >&3 2>&3
586: else
587: eval "$cmd"
588: fi
589: if [ -n "$fail" ]; then
1.26 tnn 590: mark_as_failed $pkg
591: error "'make clean' failed for package $pkg."
1.22 sno 592: fi
593: fi
594:
595: if [ -z "$fail" ]; then
1.26 tnn 596: mark_as_succeeded $pkg
1.18 gdt 597: fi
598:
1.1 gdt 599: sleep 1
600:
601: # remove just-replaced package from all *_TODO lists
602: MISMATCH_TODO=$(exclude $pkg --from $MISMATCH_TODO)
603: REBUILD_TODO=$(exclude $pkg --from $REBUILD_TODO)
604: UNSAFE_TODO=$(exclude $pkg --from $UNSAFE_TODO)
605:
1.13 tnn 606: echo "${OPI} Re-checking for unsafe installed packages (${UNSAFE_VAR}=YES)"
1.1 gdt 607: if [ -n "$opt_n" ]; then
608: # With -n, the replace didn't happen, and thus the packages that would
609: # have been marked unsafe_depends=YES were not. Add the set that
610: # would have been marked so we can watch what pkg_rolling-replace
611: # would have done (approximately).
612: UNSAFE_TODO=$(uniqify $UNSAFE_TODO \
613: $(who_requires $pkg --in-graph $DEPGRAPH_INSTALLED))
614: sleep 1
615: else
1.13 tnn 616: UNSAFE_TODO=$(check_packages_w_flag ${UNSAFE_VAR})
1.1 gdt 617: fi
618:
1.22 sno 619: depgraph_built=0
620:
621: todo
622: vsleep 2
1.1 gdt 623:
1.22 sno 624: if [ -n "$logfile" ]; then
625: exec 3>&-
626: kill $TAILPID
627: fi
1.1 gdt 628: done
629:
630: echo "${OPI} No more packages to replace; done."
1.22 sno 631:
632: report
CVSweb <webmaster@jp.NetBSD.org>