[BACK]Return to fw_install.sh CVS log [TXT][DIR] Up to [local] / openbsd / fw_update

Annotation of openbsd/fw_update/fw_install.sh, Revision 1.149

1.1       afresh1     1: #!/bin/ksh
1.36      afresh1     2: #      $OpenBSD$
1.50      afresh1     3: #
1.38      afresh1     4: # Copyright (c) 2021 Andrew Hewus Fresh <afresh1@openbsd.org>
                      5: #
                      6: # Permission to use, copy, modify, and distribute this software for any
                      7: # purpose with or without fee is hereby granted, provided that the above
                      8: # copyright notice and this permission notice appear in all copies.
                      9: #
                     10: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:
1.95      afresh1    18: set -o errexit -o pipefail -o nounset -o noclobber -o noglob
1.85      afresh1    19: set +o monitor
1.77      afresh1    20: export PATH=/usr/bin:/bin:/usr/sbin:/sbin
1.50      afresh1    21:
                     22: CFILE=SHA256.sig
                     23: DESTDIR=${DESTDIR:-}
                     24: FWPATTERNS="${DESTDIR}/usr/share/misc/firmware_patterns"
                     25:
                     26: VNAME=${VNAME:-$(sysctl -n kern.osrelease)}
                     27: VERSION=${VERSION:-"${VNAME%.*}${VNAME#*.}"}
                     28:
                     29: HTTP_FWDIR="$VNAME"
1.52      afresh1    30: VTYPE=$( sed -n "/^OpenBSD $VNAME\([^ ]*\).*$/s//\1/p" \
                     31:     /var/run/dmesg.boot | sed '$!d' )
1.50      afresh1    32: [[ $VTYPE == -!(stable) ]] && HTTP_FWDIR=snapshots
1.22      afresh1    33:
1.50      afresh1    34: FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR}
                     35: FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub
1.8       afresh1    36:
1.131     afresh1    37: DRYRUN=false
1.138     afresh1    38: VERBOSE=0
1.111     afresh1    39: DELETE=false
1.144     afresh1    40: DOWNLOAD=true
1.87      afresh1    41: INSTALL=true
1.69      afresh1    42: LOCALSRC=
                     43:
1.126     afresh1    44: unset FTPPID
1.129     afresh1    45: unset FWPKGTMP
1.126     afresh1    46: REMOVE_LOCALSRC=false
                     47: cleanup() {
1.127     afresh1    48:        set +o errexit # ignore errors from killing ftp
1.128     afresh1    49:        [ "${FTPPID:-}" ] && kill -TERM -"$FTPPID" 2>/dev/null
1.129     afresh1    50:        [ "${FWPKGTMP:-}" ] && rm -rf "$FWPKGTMP"
1.126     afresh1    51:        "$REMOVE_LOCALSRC" && rm -rf "$LOCALSRC"
                     52: }
                     53: trap cleanup EXIT
                     54:
1.8       afresh1    55: tmpdir() {
                     56:        local _i=1 _dir
                     57:
1.149   ! afresh1    58:        # The installer lacks mktemp(1), do it by hand
1.50      afresh1    59:        if [ -x /usr/bin/mktemp ]; then
                     60:                _dir=$( mktemp -d "${1}-XXXXXXXXX" )
1.44      afresh1    61:        else
1.50      afresh1    62:                until _dir="${1}.$_i.$RANDOM" && mkdir -- "$_dir" 2>/dev/null; do
1.44      afresh1    63:                    ((++_i < 10000)) || return 1
                     64:                done
                     65:        fi
1.50      afresh1    66:
1.8       afresh1    67:        echo "$_dir"
                     68: }
1.6       afresh1    69:
1.50      afresh1    70: fetch() {
1.126     afresh1    71:        local _src="${FWURL}/${1##*/}" _dst=$1 _user=_file _exit _error=''
1.6       afresh1    72:
1.149   ! afresh1    73:        # The installer uses a limited doas(1) as a tiny su(1)
1.85      afresh1    74:        set -o monitor # make sure ftp gets its own process group
                     75:        (
1.138     afresh1    76:        _flags=-vm
                     77:        case "$VERBOSE" in
                     78:                0|1) _flags=-VM ;;
                     79:                  2) _flags=-Vm ;;
                     80:        esac
1.53      afresh1    81:        if [ -x /usr/bin/su ]; then
1.85      afresh1    82:                exec /usr/bin/su -s /bin/ksh "$_user" -c \
1.138     afresh1    83:                    "/usr/bin/ftp -N '${0##/}' -D 'Get/Verify' $_flags -o- '$_src'" > "$_dst"
1.42      afresh1    84:        else
1.85      afresh1    85:                exec /usr/bin/doas -u "$_user" \
1.138     afresh1    86:                    /usr/bin/ftp -N "${0##/}" -D 'Get/Verify' $_flags -o- "$_src" > "$_dst"
1.42      afresh1    87:        fi
1.126     afresh1    88:        ) & FTPPID=$!
1.85      afresh1    89:        set +o monitor
                     90:
                     91:        SECONDS=0
                     92:        _last=0
1.126     afresh1    93:        while kill -0 -"$FTPPID" 2>/dev/null; do
1.85      afresh1    94:                if [[ $SECONDS -gt 12 ]]; then
                     95:                        set -- $( ls -ln "$_dst" 2>/dev/null )
                     96:                        if [[ $_last -ne $5 ]]; then
                     97:                                _last=$5
                     98:                                SECONDS=0
                     99:                                sleep 1
                    100:                        else
1.137     afresh1   101:                                kill -INT -"$FTPPID" 2>/dev/null
1.92      afresh1   102:                                _error=" (timed out)"
1.85      afresh1   103:                        fi
                    104:                else
                    105:                        sleep 1
                    106:                fi
                    107:        done
                    108:
                    109:        set +o errexit
1.126     afresh1   110:        wait "$FTPPID"
1.85      afresh1   111:        _exit=$?
                    112:        set -o errexit
                    113:
1.126     afresh1   114:        unset FTPPID
1.6       afresh1   115:
1.50      afresh1   116:        if [ "$_exit" -ne 0 ]; then
1.69      afresh1   117:                rm -f "$_dst"
1.92      afresh1   118:                echo "Cannot fetch $_src$_error" >&2
1.50      afresh1   119:                return 1
                    120:        fi
1.146     afresh1   121:
                    122:        return 0
1.6       afresh1   123: }
                    124:
1.144     afresh1   125: fetch_cfile() {
                    126:        if "$DOWNLOAD"; then
                    127:                set +o noclobber # we want to get the latest CFILE
                    128:                fetch "$CFILE" || return 1
                    129:                set -o noclobber
                    130:                ! signify -qVep "$FWPUB_KEY" -x "$CFILE" -m "$CFILE" &&
                    131:                    echo "Signature check of SHA256.sig failed" >&2 && return 1
                    132:        elif [ ! -e "$CFILE" ]; then
                    133:                echo "${0##*/}: $CFILE: No such file or directory" >&2
                    134:                return 2
                    135:        fi
1.146     afresh1   136:
                    137:        return 0
1.144     afresh1   138: }
                    139:
1.50      afresh1   140: verify() {
1.146     afresh1   141:        [ -e "$CFILE" ] || fetch_cfile || return 1
1.149   ! afresh1   142:        # The installer sha256 lacks -C, do it by hand
1.69      afresh1   143:        if ! fgrep -qx "SHA256 (${1##*/}) = $( /bin/sha256 -qb "$1" )" "$CFILE"; then
                    144:                echo "Checksum test for ${1##*/} failed." >&2
1.50      afresh1   145:                return 1
                    146:        fi
1.146     afresh1   147:
                    148:        return 0
1.6       afresh1   149: }
                    150:
1.124     afresh1   151: firmware_in_dmesg() {
1.90      afresh1   152:        local _d _m _line _dmesgtail _last='' _nl=$( echo )
1.1       afresh1   153:
1.149   ! afresh1   154:        # The dmesg can contain multiple boots, only look in the last one
1.133     afresh1   155:        _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot )"
1.50      afresh1   156:
1.89      afresh1   157:        grep -v '^[[:space:]]*#' "$FWPATTERNS" |
                    158:            while read -r _d _m; do
                    159:                [ "$_d" = "$_last" ] && continue
1.90      afresh1   160:                [ "$_m" ]             || _m="${_nl}${_d}[0-9] at "
                    161:                [ "$_m" = "${_m#^}" ] || _m="${_nl}${_m#^}"
1.83      afresh1   162:
1.89      afresh1   163:                if [[ $_dmesgtail = *$_m* ]]; then
                    164:                        echo "$_d"
                    165:                        _last="$_d"
                    166:                fi
                    167:            done
1.50      afresh1   168: }
1.14      afresh1   169:
1.50      afresh1   170: firmware_filename() {
1.56      afresh1   171:        local _f
1.146     afresh1   172:        [ -e "$CFILE" ] || fetch_cfile || return 1
1.56      afresh1   173:        _f="$( sed -n "s/.*(\($1-firmware-.*\.tgz\)).*/\1/p" "$CFILE" | sed '$!d' )"
                    174:        ! [ "$_f" ] && echo "Unable to find firmware for $1" >&2 && return 1
                    175:        echo "$_f"
1.50      afresh1   176: }
1.7       afresh1   177:
1.57      afresh1   178: firmware_devicename() {
                    179:        local _d="${1##*/}"
                    180:        _d="${_d%-firmware-*}"
                    181:        echo "$_d"
                    182: }
                    183:
1.50      afresh1   184: installed_firmware() {
1.110     afresh1   185:        local _pre="$1" _match="$2" _post="$3" _firmware
1.123     afresh1   186:        set -sA _firmware -- $(
1.109     afresh1   187:            set +o noglob
                    188:            grep -Fxl '@option firmware' \
1.110     afresh1   189:                "${DESTDIR}/var/db/pkg/"$_pre"$_match"$_post"/+CONTENTS" \
1.109     afresh1   190:                2>/dev/null || true
                    191:            set -o noglob
                    192:        )
                    193:
                    194:        [ "${_firmware[*]:-}" ] || return 0
                    195:        for fw in "${_firmware[@]}"; do
                    196:                fw="${fw%/+CONTENTS}"
1.50      afresh1   197:                echo "${fw##*/}"
                    198:        done
                    199: }
1.1       afresh1   200:
1.124     afresh1   201: detect_firmware() {
                    202:        local _devices _last='' _d
                    203:
                    204:        set -sA _devices -- $(
                    205:            firmware_in_dmesg
                    206:            for _d in $( installed_firmware '*' '-firmware-' '*' ); do
1.135     afresh1   207:                firmware_devicename "$_d"
1.124     afresh1   208:            done
                    209:        )
                    210:
                    211:        [ "${_devices[*]:-}" ] || return 0
                    212:        for _d in "${_devices[@]}"; do
1.135     afresh1   213:                [ "$_last" = "$_d" ] && continue
                    214:                echo "$_d"
1.124     afresh1   215:                _last="$_d"
                    216:        done
                    217: }
                    218:
1.50      afresh1   219: add_firmware () {
1.139     afresh1   220:        local _f="${1##*/}" _m="${2:-Install}" _pkgname
1.129     afresh1   221:        FWPKGTMP="$( tmpdir "${DESTDIR}/var/db/pkg/.firmware" )"
1.138     afresh1   222:        local _flags=-vm
                    223:        case "$VERBOSE" in
                    224:                0|1) _flags=-VM ;;
                    225:                2|3) _flags=-Vm ;;
                    226:        esac
                    227:
1.139     afresh1   228:        ftp -N "${0##/}" -D "$_m" "$_flags" -o- "file:${1}" |
1.129     afresh1   229:                tar -s ",^\+,${FWPKGTMP}/+," \
1.69      afresh1   230:                    -s ",^firmware,${DESTDIR}/etc/firmware," \
                    231:                    -C / -zxphf - "+*" "firmware/*"
1.1       afresh1   232:
1.129     afresh1   233:        _pkgname="$( sed -n '/^@name /{s///p;q;}' "${FWPKGTMP}/+CONTENTS" )"
1.106     afresh1   234:        if [ ! "$_pkgname" ]; then
                    235:                echo "Failed to extract name from $1, partial install" 2>&1
1.129     afresh1   236:                rm -rf "$FWPKGTMP"
                    237:                unset FWPKGTMP
1.106     afresh1   238:                return 1
                    239:        fi
                    240:
1.129     afresh1   241:        ed -s "${FWPKGTMP}/+CONTENTS" <<EOL
1.50      afresh1   242: /^@comment pkgpath/ -1a
                    243: @option manual-installation
                    244: @option firmware
                    245: @comment install-script
                    246: .
                    247: w
                    248: EOL
1.106     afresh1   249:
1.129     afresh1   250:        chmod 755 "$FWPKGTMP"
                    251:        mv "$FWPKGTMP" "${DESTDIR}/var/db/pkg/${_pkgname}"
                    252:        unset FWPKGTMP
1.50      afresh1   253: }
1.22      afresh1   254:
1.50      afresh1   255: delete_firmware() {
1.51      afresh1   256:        local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg"
1.22      afresh1   257:
1.50      afresh1   258:        # TODO: Check hash for files before deleting
1.140     afresh1   259:        [ "$VERBOSE" -gt 2 ] && echo -n "Uninstall $_pkg ..."
1.51      afresh1   260:        _cwd="${_pkgdir}/$_pkg"
1.50      afresh1   261:
1.107     afresh1   262:        if [ ! -e "$_cwd/+CONTENTS" ] ||
                    263:            ! grep -Fxq '@option firmware' "$_cwd/+CONTENTS"; then
                    264:                echo "${0##*/}: $_pkg does not appear to be firmware" >&2
                    265:                return 2
                    266:        fi
                    267:
1.51      afresh1   268:        set -A _remove -- "${_cwd}/+CONTENTS" "${_cwd}"
1.50      afresh1   269:
                    270:        while read -r c g; do
                    271:                case $c in
1.51      afresh1   272:                @cwd) _cwd="${DESTDIR}$g"
1.50      afresh1   273:                  ;;
                    274:                @*) continue
                    275:                  ;;
1.52      afresh1   276:                *) set -A _remove -- "$_cwd/$c" "${_remove[@]}"
1.50      afresh1   277:                  ;;
                    278:                esac
                    279:        done < "${_pkgdir}/${_pkg}/+CONTENTS"
                    280:
1.149   ! afresh1   281:        # Use rm -f, not removing files/dirs is probably not worth failing over
1.50      afresh1   282:        for _r in "${_remove[@]}" ; do
                    283:                if [ -d "$_r" ]; then
1.149   ! afresh1   284:                        # The installer lacks rmdir,
        !           285:                        # but we only want to remove empty directories.
1.95      afresh1   286:                        set +o noglob
1.50      afresh1   287:                        [ "$_r/*" = "$( echo "$_r"/* )" ] && rm -rf "$_r"
1.95      afresh1   288:                        set -o noglob
1.50      afresh1   289:                else
                    290:                        rm -f "$_r"
1.22      afresh1   291:                fi
                    292:        done
1.138     afresh1   293:
1.140     afresh1   294:        [ "$VERBOSE" -gt 2 ] && echo " done."
1.139     afresh1   295:
                    296:        return 0
1.50      afresh1   297: }
1.1       afresh1   298:
1.59      afresh1   299: usage() {
1.147     afresh1   300:        echo "usage: ${0##*/} [-d | -F] [-av] [-p path] [driver | file ...]"
1.59      afresh1   301:        exit 2
                    302: }
                    303:
1.113     afresh1   304: ALL=false
1.142     afresh1   305: OPT_F=
                    306: while getopts :adFnp:v name
1.59      afresh1   307: do
1.145     afresh1   308:        case "$name" in
                    309:        a) ALL=true ;;
                    310:        d) DELETE=true ;;
                    311:        F) OPT_F=true ;;
                    312:        n) DRYRUN=true ;;
                    313:        p) LOCALSRC="$OPTARG" ;;
                    314:        v) VERBOSE=$(( VERBOSE + 1 )) ;;
                    315:        :)
                    316:            echo "${0##*/}: option requires an argument -- -$OPTARG" >&2
                    317:            usage 2
                    318:            ;;
                    319:        ?)
                    320:            echo "${0##*/}: unknown option -- -$OPTARG" >&2
                    321:            usage 2
                    322:            ;;
                    323:        esac
1.59      afresh1   324: done
                    325: shift $((OPTIND - 1))
                    326:
1.121     afresh1   327: if [ "$LOCALSRC" ]; then
                    328:        if [[ $LOCALSRC = @(ftp|http?(s))://* ]]; then
                    329:                FWURL="${LOCALSRC}"
                    330:                LOCALSRC=
                    331:        else
                    332:                LOCALSRC="${LOCALSRC:#file:}"
                    333:                ! [ -d "$LOCALSRC" ] &&
                    334:                    echo "The path must be a URL or an existing directory" >&2 &&
                    335:                    exit 2
                    336:        fi
                    337: fi
                    338:
1.122     afresh1   339: # "Download only" means local dir and don't install
1.142     afresh1   340: if [ "$OPT_F" ]; then
1.87      afresh1   341:        INSTALL=false
1.121     afresh1   342:        LOCALSRC="${LOCALSRC:-.}"
1.144     afresh1   343:
                    344:        # Always check for latest CFILE and so latest firmware
                    345:        if [ -e "$LOCALSRC/$CFILE" ]; then
                    346:                mv "$LOCALSRC/$CFILE" "$LOCALSRC/$CFILE-OLD"
                    347:                if fetch_cfile; then
                    348:                        rm -f "$LOCALSRC/$CFILE-OLD"
                    349:                else
                    350:                        mv "$LOCALSRC/$CFILE-OLD" "$LOCALSRC/$CFILE"
                    351:                        echo "Using existing $CFILE" >&2
                    352:                fi
                    353:        fi
1.130     afresh1   354: elif [ "$LOCALSRC" ]; then
                    355:        DOWNLOAD=false
1.87      afresh1   356: fi
1.64      afresh1   357:
1.118     afresh1   358: if [ -x /usr/bin/id ] && [ "$(/usr/bin/id -u)" != 0 ]; then
                    359:        echo "need root privileges" >&2
                    360:        exit 1
1.94      afresh1   361: fi
                    362:
1.123     afresh1   363: set -sA devices -- "$@"
1.111     afresh1   364:
                    365: if "$DELETE"; then
1.142     afresh1   366:        [ "$OPT_F" ] && usage 22
1.111     afresh1   367:
1.139     afresh1   368:        # Show the "Uninstalling" message when just deleting not upgrading
1.141     afresh1   369:        [ "$VERBOSE" -gt 0 ] && VERBOSE=3
1.139     afresh1   370:
1.113     afresh1   371:        set -A installed
                    372:        if [ "${devices[*]:-}" ]; then
                    373:                "$ALL" && usage 22
                    374:
                    375:                set -A installed -- $(
                    376:                    for d in "${devices[@]}"; do
                    377:                        f="${d##*/}"  # only care about the name
                    378:                        f="${f%.tgz}" # allow specifying the package name
                    379:                        [ "$( firmware_devicename "$f" )" = "$f" ] && f="$f-firmware"
                    380:
                    381:                        set -A i -- $( installed_firmware '' "$f-" '*' )
                    382:
                    383:                        if [ "${i[*]:-}" ]; then
                    384:                                echo "${i[@]}"
                    385:                        else
                    386:                                echo "No firmware found for '$d'" >&2
                    387:                        fi
                    388:                    done
                    389:                )
                    390:        elif "$ALL"; then
                    391:                set -A installed -- $( installed_firmware '*' '-firmware-' '*' )
                    392:        fi
1.111     afresh1   393:
                    394:        deleted=''
1.113     afresh1   395:        if [ "${installed:-}" ]; then
1.111     afresh1   396:                for fw in "${installed[@]}"; do
1.131     afresh1   397:                        if "$DRYRUN"; then
1.138     afresh1   398:                                [ "$VERBOSE" -gt 0 ] && echo "Delete $fw"
1.131     afresh1   399:                        else
                    400:                                delete_firmware "$fw" || continue
                    401:                        fi
1.112     afresh1   402:                        deleted="$deleted,$( firmware_devicename "$fw" )"
1.111     afresh1   403:                done
1.113     afresh1   404:        fi
1.111     afresh1   405:
1.139     afresh1   406:        deleted="${deleted#,}"
1.111     afresh1   407:        echo "${0:##*/}: deleted ${deleted:-none}";
                    408:
                    409:        exit
                    410: fi
1.125     afresh1   411:
                    412: if [ ! "$LOCALSRC" ]; then
1.145     afresh1   413:        LOCALSRC="$( tmpdir "${DESTDIR}/tmp/${0##*/}" )"
                    414:        REMOVE_LOCALSRC=true
1.125     afresh1   415: fi
                    416:
1.144     afresh1   417: CFILE="$LOCALSRC/$CFILE"
                    418:
1.113     afresh1   419: if [ "${devices[*]:-}" ]; then
                    420:        "$ALL" && usage 22
                    421: else
1.139     afresh1   422:        [ "$VERBOSE" -gt 1 ] && echo -n "Detect firmware ..."
1.124     afresh1   423:        set -sA devices -- $( detect_firmware )
1.139     afresh1   424:        [ "$VERBOSE" -gt 1 ] &&
1.101     afresh1   425:            { [ "${devices[*]:-}" ] && echo " found." || echo " done." ; }
1.50      afresh1   426: fi
1.91      afresh1   427:
                    428: [ "${devices[*]:-}" ] || exit
1.50      afresh1   429:
1.103     afresh1   430: added=''
                    431: updated=''
1.115     afresh1   432: kept=''
1.70      afresh1   433: for f in "${devices[@]}"; do
                    434:        d="$( firmware_devicename "$f" )"
                    435:
1.148     afresh1   436:        verify_existing=true
1.58      afresh1   437:        if [ "$f" = "$d" ]; then
                    438:                f=$( firmware_filename "$d" || true )
                    439:                [ "$f" ] || continue
1.69      afresh1   440:                f="$LOCALSRC/$f"
1.76      afresh1   441:        elif ! "$INSTALL" && ! grep -Fq "($f)" "$CFILE" ; then
1.70      afresh1   442:                echo "Cannot download local file $f" >&2
                    443:                exit 2
1.146     afresh1   444:        else
1.149   ! afresh1   445:                # Don't verify files specified on the command-line
1.146     afresh1   446:                verify_existing=false
1.58      afresh1   447:        fi
                    448:
1.110     afresh1   449:        set -A installed -- $( installed_firmware '' "$d-firmware-" '*' )
1.50      afresh1   450:
1.68      afresh1   451:        if "$INSTALL" && [ "${installed[*]:-}" ]; then
1.65      afresh1   452:                for i in "${installed[@]}"; do
1.58      afresh1   453:                        if [ "${f##*/}" = "$i.tgz" ]; then
1.139     afresh1   454:                                [ "$VERBOSE" -gt 2 ] && echo "Keep $i"
1.115     afresh1   455:                                kept="$kept,$d"
1.11      afresh1   456:                                continue 2
1.1       afresh1   457:                        fi
                    458:                done
1.50      afresh1   459:        fi
1.1       afresh1   460:
1.148     afresh1   461:        if "$verify_existing" && [ -e "$f" ]; then
                    462:                msg="Keep/Verify"
                    463:                "$INSTALL" && msg="Verify"
                    464:                [ "$VERBOSE" -gt 1 ] && ! "$INSTALL" &&
                    465:                    echo "$msg ${f##*/}"
                    466:
                    467:                if "$DRYRUN" || verify "$f"; then
1.131     afresh1   468:                        "$INSTALL" || kept="$kept,$d"
1.148     afresh1   469:                elif "$DOWNLOAD"; then
                    470:                        [ "$VERBOSE" -gt 0 ] && echo "Refetching $f"
                    471:                        rm -f $f
                    472:                else
                    473:                        continue
1.72      afresh1   474:                fi
1.148     afresh1   475:        fi
                    476:
                    477:        if [ -e "$f" ]; then
                    478:                true # verified above
1.75      afresh1   479:        elif "$DOWNLOAD"; then
1.131     afresh1   480:                if "$DRYRUN"; then
1.138     afresh1   481:                        [ "$VERBOSE" -gt 0 ] && echo "Get/Verify ${f##*/}"
1.131     afresh1   482:                else
1.138     afresh1   483:                        [ "$VERBOSE" -eq 1 ] && echo -n "Get/Verify ${f##*/} ..."
                    484:                        fetch  "$f" &&
                    485:                        verify "$f" ||
                    486:                            { [ "$VERBOSE" -eq 1 ] && echo " failed."; continue; }
1.139     afresh1   487:                        [ "$VERBOSE" -eq 1 ] && ! "$INSTALL" && echo " done."
1.131     afresh1   488:                fi
1.138     afresh1   489:                "$INSTALL" || added="$added,$d"
1.75      afresh1   490:        elif "$INSTALL"; then
1.72      afresh1   491:                echo "Cannot install ${f##*/}, not found" >&2
                    492:                continue
1.58      afresh1   493:        fi
1.60      afresh1   494:
1.68      afresh1   495:        "$INSTALL" || continue
1.11      afresh1   496:
1.139     afresh1   497:        update=''
1.65      afresh1   498:        if [ "${installed[*]:-}" ]; then
1.50      afresh1   499:                for i in "${installed[@]}"; do
1.131     afresh1   500:                        "$DRYRUN" || delete_firmware "$i"
1.139     afresh1   501:                        update="Update"
1.50      afresh1   502:                done
                    503:        fi
1.11      afresh1   504:
1.139     afresh1   505:        "$DRYRUN" || add_firmware "$f" "$update"
1.103     afresh1   506:
1.131     afresh1   507:        f="${f##*/}"
                    508:        f="${f%.tgz}"
1.139     afresh1   509:        if [ "$update" ]; then
1.140     afresh1   510:                if [ "$VERBOSE" -eq 1 ] && "$DOWNLOAD" && ! "$DRYRUN"; then
                    511:                        echo " updated."
1.139     afresh1   512:                elif [ "$VERBOSE" -eq 1 ]; then
1.140     afresh1   513:                        echo "Update $f"
                    514:                elif [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then
                    515:                        echo "Update $f"
1.139     afresh1   516:                fi
1.114     afresh1   517:                updated="$updated,$d"
1.103     afresh1   518:        else
1.140     afresh1   519:                if [ "$VERBOSE" -eq 1 ] && "$DOWNLOAD" && ! "$DRYRUN"; then
                    520:                        echo " installed."
1.139     afresh1   521:                elif [ "$VERBOSE" -eq 1 ]; then
1.140     afresh1   522:                        echo "Install $f"
                    523:                elif [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then
                    524:                        echo "Install $f"
1.139     afresh1   525:                fi
1.114     afresh1   526:                added="$added,$d"
1.103     afresh1   527:        fi
1.50      afresh1   528: done
1.1       afresh1   529:
1.114     afresh1   530: added="${added:#,}"
                    531: updated="${updated:#,}"
1.115     afresh1   532: kept="${kept:#,}"
1.117     afresh1   533: if "$INSTALL"; then
                    534:        echo  "${0##*/}: added ${added:-none}; updated ${updated:-none}; kept ${kept:-none}"
                    535: else
                    536:        echo  "${0##*/}: downloaded ${added:-none}; kept ${kept:-none}"
                    537: fi

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>