Annotation of pkgsrc/pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh, revision 1.22

1.1       gdt         1: #!/bin/sh
                      2: 
1.22    ! sno         3: # $NetBSD: pkg_rolling-replace.sh,v 1.21 2009/06/17 08:12:18 tnn 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@"
                     95: test -z "$PKG_INFO" && PKG_INFO="@PKG_INFO_CMD@"
1.1       gdt        96: 
1.19      apb        97: export PKGSRCDIR
                     98: 
1.1       gdt        99: unset PKG_PATH || true  #or pkgsrc makefiles will complain
                    100: 
                    101: usage()
                    102: {
                    103:     echo "Usage: pkg_rolling-replace [opts]
                    104:         -h         This help
1.22    ! sno       105:         -F         Fetch sources (including depends) only, don't build
        !           106:         -k         Keep running, even on error
1.1       gdt       107:         -n         Don't actually do make replace
1.13      tnn       108:         -r         Just replace, don't create binary packages
                    109:         -s         Replace even if the ABIs are still compatible ("strict")
1.17      apb       110:         -u         Update outdated packages
1.1       gdt       111:         -v         Verbose
1.22    ! sno       112:         -L <path>  Log to path (<path>/pkgdir/pkg)
1.20      wiz       113:         -X <pkg>   exclude <pkg> from being rebuilt
1.17      apb       114:         -x <pkg>   exclude <pkg> from outdated check
1.1       gdt       115: 
                    116: pkg_rolling-replace does 'make replace' on one package at a time,
                    117: tsorting the packages being replaced according to their
                    118: interdependencies, which avoids most duplicate rebuilds.
                    119: 
                    120: pkg_rolling-replace can be used in one of two ways:
                    121: 
                    122:     - 'make replace' is unsafe in that, if the replaced package's ABI
                    123:       changes, its dependent packages may break.  If this happens, run
                    124:       'pkg_rolling-replace' (no arguments) to rebuild them against the
                    125:       new version.
                    126: 
                    127:     - 'pkg_chk -u' will delete all your mismatched (outdated)
                    128:       packages, then reinstall them one at a time, leaving you without
                    129:       those packages in the meantime.  'pkg_rolling-replace -u' will
                    130:       instead upgrade them in place, allowing you to keep using your
                    131:       system in the meantime (maybe...if you're lucky...because
                    132:       pkg_rolling-replace replaces the \"deepest\" dependency first,
                    133:       things could still break if that happens to be a fundamental
                    134:       library whose ABI has changed).
                    135: "
                    136:     exit 1
                    137: }
                    138: 
                    139: # pkg_rolling-replace's output is intermingled with pkgsrc make
                    140: # output.  Thus, we use a different prefix.  pkgsrc uses '===>' for
                    141: # major steps, and '=>' for minor ones.  Thus, we use 'RR>'.
                    142: 
                    143: OPI='RR>'
                    144: OPC='rr>' # continuation
                    145: 
                    146: 
                    147: # Echo the names of packages needing updates, versions stripped.  This
                    148: # has been tested with pkg_chk 1.76.  Older versions are not
                    149: # supported.  Newer versions may or may not work (patches welcome).
                    150: check_packages_mismatched()
                    151: {
1.12      tnn       152:     ${PKG_CHK} -u -q | while read line; do
1.1       gdt       153:         # duplicate output of pkg_chk to stderr (bypass $(...) or `...`)
1.11      tnn       154:         echo "${OPC} $line" 1>&2
1.1       gdt       155:        # Look for the first thing that looks like pkg-version rather
                    156:        # than category/pkg and remove the version.
                    157:         for word in $line; do
1.5       tnn       158:             if [ "$(echo $word | egrep '^[^/]+-[0-9][^-/]*$')" ]; then
                    159:                 echo $word | sed 's/-[0-9][^-]*$//'
1.1       gdt       160:                 break  #done with this line
                    161:             fi
                    162:         done
                    163:     done
                    164: }
                    165: 
                    166: # usage: check_packages_w_flag flag
                    167: # echo packages with flag=YES
                    168: check_packages_w_flag()
                    169: {
                    170:     _flag=$1; shift
1.12      tnn       171:     for pkgver in $(${PKG_INFO} -e '*'); do
                    172:         if ${PKG_INFO} -Bq $pkgver \
1.1       gdt       173:                 | egrep "^$_flag=[Yy][Ee][Ss]" > /dev/null; then
1.5       tnn       174:             echo $pkgver | sed 's/-[0-9][^-]*$//'
1.1       gdt       175:         fi
                    176:     done
                    177: }
                    178: 
                    179: # echo dep->pkg edges for all installed packages
                    180: depgraph_installed()
                    181: {
1.15      tnn       182:        ${PKG_INFO} -N '*' | ${AWK} '                                   \
                    183:                /^Information for/ {                                    \
                    184:                        pkg=$3; sub("-[0-9][^-]*:$", "", pkg);          \
                    185:                        print pkg" "pkg;                                \
                    186:                        state=1;                                        \
                    187:                }                                                       \
1.16      gdt       188:                /^\** PACKAGE MAY NOT BE DELETED \**$/ { state=3; }     \
1.15      tnn       189:                /^./ {                                                  \
                    190:                        if (state == 2) {                               \
                    191:                                dep=$1; sub("-[0-9][^-]*$", "", dep);   \
                    192:                                print dep" "pkg;                        \
                    193:                        }                                               \
                    194:                }                                                       \
                    195:                /^Built using/ {                                        \
                    196:                        state=2                                         \
                    197:                }                                                       \
                    198:        '
1.1       gdt       199: }
                    200: 
                    201: # usage: who_requires pkg --in-graph DEPGRAPH
                    202: who_requires()
                    203: {
                    204:     _target=$1; shift
                    205:     test "$1" = '--in-graph' && shift || return $((false))
                    206: 
                    207:     while [ $# -gt 0 ]; do
                    208:         _dep=$1; _pkg=$2; shift 2;
                    209:         if [ $_dep = $_target -a $_dep != $_pkg ]; then
                    210:             echo $_pkg
                    211:         fi
                    212:     done
                    213: }
                    214: 
                    215: # usage: is_member x list
                    216: # return true (0) if x appears in list, false (1) otherwise
                    217: is_member()
                    218: {
                    219:     _x="$1"; shift;
                    220:     while [ $# -gt 0 -a "$1" != "$_x" ]; do
                    221:         shift
                    222:     done
                    223: 
                    224:     test $# -gt 0
                    225: }
                    226: 
                    227: # usage: exclude list1 --from list2
                    228: # echo list2 with items from list1 excluded
                    229: exclude()
                    230: {
                    231:     _excl=
                    232:     while [ $# -gt 0 -a $1 != "--from" ]; do
                    233:         _excl="$_excl $1"
                    234:         shift
                    235:     done
                    236:     if [ $# -gt 0 ]; then
                    237:         shift  #discard '--from'
                    238:     fi
                    239:     while [ $# -gt 0 ]; do
                    240:         is_member $1 $_excl || echo $1
                    241:         shift
                    242:     done
                    243: }
                    244: 
                    245: # usage: uniquify list
                    246: # just does sort -u on list (equiv. to sort | uniq)
                    247: # CAUTION: reorders list
                    248: uniqify()
                    249: {
                    250:     for _x in $*; do echo $_x; done | sort -u
                    251: }
                    252: 
                    253: verbose()
                    254: {
                    255:     if [ -n "$opt_v" ]; then
                    256:         echo "$@"
                    257:     fi
                    258: }
                    259: 
                    260: vsleep()
                    261: {
                    262:     if [ -n "$opt_v" ]; then
                    263:         sleep $1
                    264:     fi
                    265: }
                    266: 
1.22    ! sno       267: report()
        !           268: {
        !           269:     for a in $SUCCESSED; do
        !           270:         verbose "+ $a"
        !           271:     done
        !           272: 
        !           273:     for a in $FAILED; do
        !           274:         verbose "- $a"
        !           275:     done
        !           276: }
        !           277: 
1.13      tnn       278: abort()
                    279: {
                    280:        echo "*** $1"
                    281:        echo "*** Please read the errors listed above, fix the problem,"
                    282:        echo "*** then re-run pkg_rolling-replace to continue."
1.22    ! sno       283:         report
1.13      tnn       284:        exit 1
                    285: }
                    286: 
1.22    ! sno       287: todo()
        !           288: {
        !           289:     if [ -z "$opt_F" ]; then
        !           290:         verbose "${OPI} Packages to rebuild:"
        !           291:         verbose "${OPC} MISMATCH_TODO=[$(echo $MISMATCH_TODO)]"  #strip newlines
        !           292:         verbose "${OPC} REBUILD_TODO=[$(echo $REBUILD_TODO)]"
        !           293:         verbose "${OPC} UNSAFE_TODO=[$(echo $UNSAFE_TODO)]"
        !           294:         REPLACE_TODO=$(uniqify $MISMATCH_TODO $REBUILD_TODO $UNSAFE_TODO)
        !           295:     else
        !           296:         REPLACE_TODO=$(uniqify $MISMATCH_TODO)
        !           297:         verbose "${OPI} Packages to fetch:"
        !           298:         verbose "${OPC} MISMATCH_TODO=[$(echo $MISMATCH_TODO)]"  #strip newlines
        !           299:     fi
        !           300:     REPLACE_TODO=$(exclude $REALLYEXCLUDE --from $REPLACE_TODO)
        !           301:     if [ -n "$FAILED" ]; then
        !           302:         REPLACE_TODO=$(exclude $FAILED --from $REPLACE_TODO)
        !           303:     fi
        !           304:     vsleep 2
        !           305: }
        !           306: 
1.1       gdt       307: ######################################################################
                    308: ##
                    309: ## main()
                    310: ##
                    311: 
                    312: EXCLUDE=
                    313: 
1.22    ! sno       314: args=$(getopt Fhknursvx:X:L: $*)
1.1       gdt       315: if [ $? -ne 0 ]; then
                    316:     opt_h=1
                    317: fi
                    318: set -- $args
                    319: while [ $# -gt 0 ]; do
                    320:     case "$1" in
1.22    ! sno       321:         -F) opt_F=1 ;;
1.1       gdt       322:         -h) opt_h=1 ;;
1.22    ! sno       323:         -k) opt_k=1 ;;
1.1       gdt       324:         -n) opt_n=1 ;;
1.13      tnn       325:         -r) opt_r=1 ;;
                    326:         -s) opt_s=1 ;;
1.1       gdt       327:         -u) opt_u=1 ;;
                    328:         -v) opt_v=1 ;;
                    329:         -x) EXCLUDE="$EXCLUDE $(echo $2 | sed 's/,/ /g')" ; shift ;;
1.17      apb       330:         -X) REALLYEXCLUDE="$REALLYEXCLUDE $(echo $2 | sed 's/,/ /g')" ; shift ;;
1.22    ! sno       331:         -L) LOGPATH="$2"; shift ;;
1.1       gdt       332:         --) shift; break ;;
                    333:     esac
                    334:     shift
                    335: done
                    336: 
                    337: if [ -n "$opt_h" ]; then
                    338:     usage
                    339: fi
                    340: 
1.13      tnn       341: if [ -n "$opt_s" ]; then
                    342:     UNSAFE_VAR=unsafe_depends_strict
                    343: else
                    344:     UNSAFE_VAR=unsafe_depends
                    345: fi
                    346: 
1.22    ! sno       347: SUCCESSED=""
        !           348: SUCCESSEDSEP=""
        !           349: FAILED=""
        !           350: FAILEDSEP=""
        !           351: 
1.1       gdt       352: MISMATCH_TODO=
1.22    ! sno       353: if [ -n "$opt_u" -o -n "$opt_F" ]; then
1.1       gdt       354:     echo "${OPI} Checking for mismatched installed packages using pkg_chk"
                    355:     MISMATCH_TODO=$(check_packages_mismatched)
                    356:     echo "${OPI} Excluding the following mismatched packages:"
                    357:     echo "${OPC} EXCLUDE=[$EXCLUDE]"
                    358:     MISMATCH_TODO=$(exclude $EXCLUDE --from $MISMATCH_TODO)
                    359: fi
                    360: 
1.22    ! sno       361: if [ -z "$opt_F" ]; then
        !           362:     echo "${OPI} Checking for rebuild-requested installed packages (rebuild=YES)"
        !           363:     REBUILD_TODO=$(check_packages_w_flag 'rebuild')
1.1       gdt       364: 
1.22    ! sno       365:     echo "${OPI} Checking for unsafe installed packages (${UNSAFE_VAR}=YES)"
        !           366:     UNSAFE_TODO=$(check_packages_w_flag ${UNSAFE_VAR})
        !           367: fi
1.1       gdt       368: 
                    369: # DEPGRAPH_INSTALLED is rebuilt each round.  DEPGRAPH_SRC will collect
                    370: # edges that we discover using 'make show-depends', but that weren't
                    371: # listed as depends by the installed version of a package, and
                    372: # DEPENDS_CHECKED lists packages for which we've already done that
                    373: # check.
                    374: DEPGRAPH_INSTALLED=
                    375: DEPGRAPH_SRC=
                    376: DEPENDS_CHECKED=
                    377: 
1.22    ! sno       378: todo
1.1       gdt       379: 
                    380: depgraph_built=0
                    381: 
                    382: while [ -n "$REPLACE_TODO" ]; do
1.22    ! sno       383:     fail=
        !           384: 
1.1       gdt       385:     # don't rebuild depgraph if we continued from new-depends step below
                    386:     if [ "$depgraph_built" -eq 0 ]; then
                    387:         echo "${OPI} Building dependency graph for installed packages"
                    388:         DEPGRAPH_INSTALLED=$(depgraph_installed)
                    389:         depgraph_built=1
                    390:     fi
                    391: 
                    392:     echo "${OPI} Tsorting dependency graph"
                    393:     TSORTED=$(echo $DEPGRAPH_INSTALLED $DEPGRAPH_SRC | tsort)
                    394:     for pkg in $TSORTED; do
                    395:         if is_member $pkg $REPLACE_TODO; then
                    396:             break;
                    397:         fi
                    398:     done
1.21      tnn       399:     pkgdir=$(${PKG_INFO} -Q PKGPATH $pkg)
1.1       gdt       400:     echo "${OPI} Selecting $pkg ($pkgdir) as next package to replace"
                    401:     sleep 1
                    402: 
                    403:     # Newer versions in pkgsrc sometimes have more depends than are
                    404:     # recorded for the installed version (this is entirely to be
                    405:     # expected as packages are split, renamed, and add new features).
                    406:     # When this happens, add the new edges to the graph and re-tsort.
                    407:     # Don't re-tsort if the new edges were already installed once
                    408:     # (otherwise we'll go into a loop).
                    409: 
                    410:     # XXX I'm not sure that DEPENDS_CHECKED is necessary, or whether
                    411:     # simply ignoring new deps that aren't in $REPLACE_TODO would have
                    412:     # been sufficient.  The DEPENDS_CHECKED approach causes one extra
                    413:     # tsort in some cases, which isn't overly expensive.
                    414: 
                    415:     # XXX After tsorting and choosing what to 'make replace', we
                    416:     # filter out packages that aren't already installed and marked for
                    417:     # replacement.  This is safe, since uninstalled depends will be
                    418:     # pulled in automatically by 'make replace'; but in rare cases it
                    419:     # might be non-optimal, leading to a duplicate rebuild that we
                    420:     # would have avoided had we selected the uninstalled package in
                    421:     # tsorted order and run 'make install' on it.  This seems like
                    422:     # such a rare case that the added complexity isn't worth it.
                    423: 
                    424:     if ! is_member $pkg $DEPENDS_CHECKED; then
                    425:        echo "${OPI} Checking if $pkg has new depends..."
1.12      tnn       426:        OLD_DEPENDS=$(${PKG_INFO} -Nq $pkg | sed 's/-[0-9][^-]*$//')
1.1       gdt       427:        NEW_DEPENDS=
                    428:        cd "$PKGSRCDIR/$pkgdir"
                    429:        bdeps=$(${MAKE} show-depends VARNAME=BUILD_DEPENDS)
                    430:        rdeps=$(${MAKE} show-depends)
                    431:        for depver in $bdeps $rdeps; do
1.10      tnn       432:            dep=$(echo $depver | sed -e 's/[:[].*$/0/' -e 's/[<>]=/-/' \
                    433:                -e 's/-[0-9][^-]*$//')
1.1       gdt       434:            if ! is_member $dep $OLD_DEPENDS $NEW_DEPENDS; then
                    435:                NEW_DEPENDS="$NEW_DEPENDS $dep"
                    436:                DEPGRAPH_SRC="$DEPGRAPH_SRC $dep $pkg"
                    437:            fi
                    438:        done
                    439:        DEPENDS_CHECKED="$DEPENDS_CHECKED $pkg"
                    440:        if [ -n "$NEW_DEPENDS" ]; then
                    441:            echo "${OPI} $pkg has the following new depends (need to re-tsort):"
                    442:            echo "${OPC} [$(echo $NEW_DEPENDS)]"
                    443:            sleep 2
                    444:            continue
                    445:        fi
                    446:     fi
                    447: 
1.22    ! sno       448:     pkgname=$(${PKG_INFO} -e $pkg)
        !           449:     if [ -n "$LOGPATH" ]; then
        !           450:         logdir="$LOGPATH/`dirname $pkgdir`"
        !           451:         logfile="$logdir/$pkgname"
        !           452:         @MKDIR@ "$logdir" || abort "mkdir -p '$logdir' failed"
        !           453:         exec 3>"$logfile"
        !           454:         tail -f "$logfile" &
        !           455:         TAILPID=$!
        !           456:     fi
        !           457: 
1.1       gdt       458:     # Do make replace, with clean before, and package and clean afterwards.
1.13      tnn       459:     fail=
1.22    ! sno       460:     cd "$PKGSRCDIR/$pkgdir";
        !           461:     if [ -z "$opt_F" ]; then
        !           462:         echo "${OPI} Replacing $pkgname"
        !           463:         cmd="${MAKE} clean || fail=1"
        !           464:         if [ -n "$opt_n" ]; then
        !           465:             echo "${OPI} Would run: $cmd"
        !           466:         else
        !           467:             if [ -n "$logfile" ]; then
        !           468:                 eval "$cmd" >&3 2>&3
        !           469:             else
        !           470:                 eval "$cmd"
        !           471:             fi
        !           472:             if [ -n "$fail" ]; then
        !           473:                 FAILED="$FAILED$FAILEDSEP$pkg"
        !           474:                 FAILEDSEP=" "
        !           475:                 [ -n "$opt_k" ] || abort "'make clean' failed for package $pkg."
        !           476:             fi
        !           477:         fi
        !           478:         cmd="${MAKE} replace || fail=1" # XXX OLDNAME= support? xmlrpc-c -> xmlrpc-c-ss
        !           479:     else
        !           480:         echo "${OPI} Fetching $pkgname"
        !           481:         cmd="${MAKE} fetch depends-fetch || fail=1"
        !           482:     fi
        !           483:     if [ -n "$opt_n" -a -z "$fail" ]; then
1.13      tnn       484:        echo "${OPI} Would run: $cmd"
1.22    ! sno       485:     elif [ -z "$fail" ]; then
        !           486:         if [ -n "$logfile" ]; then
        !           487:             eval "$cmd" >&3 2>&3
        !           488:         else
        !           489:             eval "$cmd"
        !           490:         fi
        !           491:        if [ -n "$fail" ]; then
        !           492:             FAILED="$FAILED$FAILEDSEP$pkg"
        !           493:             FAILEDSEP=" "
        !           494:             [ -n "$opt_k" ] || abort "'make replace' failed for package $pkg."
        !           495:         fi
1.13      tnn       496:     fi
1.22    ! sno       497:     if [ -z "$opt_n" -a -z "$opt_k" -a -z "$opt_F" ]; then
1.13      tnn       498:        [ -z "$(${PKG_INFO} -Q unsafe_depends_strict $pkg)" ] || \
                    499:            abort "package $pkg still has unsafe_depends_strict."
                    500:        [ -z "$(${PKG_INFO} -Q unsafe_depends $pkg)" ] || \
                    501:            abort "package $pkg still has unsafe_depends."
                    502:        [ -z "$(${PKG_INFO} -Q rebuild $pkg)" ] || \
                    503:            abort "package $pkg is still requested to be rebuilt."
1.1       gdt       504:     fi
1.18      gdt       505:     # If -r not given, make a binary package.
1.22    ! sno       506:     if [ -z "$opt_r" -a -z "$fail" -a -z "$opt_F" ]; then
1.13      tnn       507:        echo "${OPI} Packaging $(${PKG_INFO} -e $pkg)"
1.22    ! sno       508:         cmd="${MAKE} package || fail=1"
        !           509:        if [ -n "$opt_n" -a -z "$fail" ]; then
1.13      tnn       510:            echo "${OPI} Would run: $cmd"
1.22    ! sno       511:        elif [ -z "$fail" ]; then
        !           512:             if [ -n "$logfile" ]; then
        !           513:                 eval "$cmd" >&3 2>&3
        !           514:             else
        !           515:                 eval "$cmd"
        !           516:             fi
        !           517:             if [ -n "$fail" ]; then
        !           518:                 FAILED="$FAILED$FAILEDSEP$pkg"
        !           519:                 FAILEDSEP=" "
        !           520:                 [ -n "$opt_k" ] || abort "'make package' failed for package $pkg."
        !           521:             fi
1.13      tnn       522:        fi
1.1       gdt       523:     fi
1.18      gdt       524:     # Clean
1.22    ! sno       525:     if [ -z "$opt_n" -a -z "$fail" -a -z "$opt_F" ]; then
        !           526:         cmd="${MAKE} clean || fail=1"
        !           527:         if [ -n "$logfile" ]; then
        !           528:             eval "$cmd" >&3 2>&3
        !           529:         else
        !           530:             eval "$cmd"
        !           531:         fi
        !           532:        if [ -n "$fail" ]; then
        !           533:             FAILED="$FAILED$FAILEDSEP$pkg"
        !           534:             FAILEDSEP=" "
        !           535:             [ -n "$opt_k" ] || abort "'make clean' failed for package $pkg."
        !           536:         fi
        !           537:     fi
        !           538: 
        !           539:     if [ -z "$fail" ]; then
        !           540:         SUCCESSED="$SUCCESSED$SUCCESSEDSEP$pkg"
        !           541:         SUCCESSEDSEP=" "
1.18      gdt       542:     fi
                    543: 
1.1       gdt       544:     sleep 1
                    545: 
                    546:     # remove just-replaced package from all *_TODO lists
                    547:     MISMATCH_TODO=$(exclude $pkg --from $MISMATCH_TODO)
                    548:     REBUILD_TODO=$(exclude $pkg --from $REBUILD_TODO)
                    549:     UNSAFE_TODO=$(exclude $pkg --from $UNSAFE_TODO)
                    550: 
1.13      tnn       551:     echo "${OPI} Re-checking for unsafe installed packages (${UNSAFE_VAR}=YES)"
1.1       gdt       552:     if [ -n "$opt_n" ]; then
                    553:        # With -n, the replace didn't happen, and thus the packages that would
                    554:        # have been marked unsafe_depends=YES were not.  Add the set that
                    555:        # would have been marked so we can watch what pkg_rolling-replace
                    556:        # would have done (approximately).
                    557:         UNSAFE_TODO=$(uniqify $UNSAFE_TODO \
                    558:             $(who_requires $pkg --in-graph $DEPGRAPH_INSTALLED))
                    559:         sleep 1
                    560:     else
1.13      tnn       561:         UNSAFE_TODO=$(check_packages_w_flag ${UNSAFE_VAR})
1.1       gdt       562:     fi
                    563: 
1.22    ! sno       564:     depgraph_built=0
        !           565: 
        !           566:     todo
        !           567:     vsleep 2
1.1       gdt       568: 
1.22    ! sno       569:     if [ -n "$logfile" ]; then
        !           570:         exec 3>&-
        !           571:         kill $TAILPID
        !           572:     fi
1.1       gdt       573: done
                    574: 
                    575: echo "${OPI} No more packages to replace; done."
1.22    ! sno       576: 
        !           577: report

CVSweb <webmaster@jp.NetBSD.org>