[BACK]Return to update_openbsd CVS log [TXT][DIR] Up to [local] / openbsd / update_openbsd

Annotation of openbsd/update_openbsd/update_openbsd, Revision 1.114

1.1       andrew      1: #!/bin/sh
1.114   ! andrew      2: # $AFresh1: update_openbsd,v 1.113 2018/12/16 20:31:06 andrew Exp $
1.94      andrew      3: #
1.41      andrew      4: # Copyright (c) 2012 Andrew Fresh <andrew@afresh1.com>
                      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.7       andrew     18:
1.2       andrew     19: installed_sets() {
1.5       andrew     20:     local misc=/usr/share/doc/README
1.63      andrew     21:     local man=/usr/share/man/man1/intro.1
1.5       andrew     22:     local comp=/usr/bin/cc
                     23:     local game=/usr/games/
                     24:     local xbase=/usr/X11R6/
                     25:     local xetc=/etc/X11/xinit/xinitrc
                     26:     local xfont=/usr/X11R6/lib/X11/fonts
                     27:     local xserv=/usr/X11R6/bin/X
                     28:     local xshare=/usr/X11R6/bin/startx
                     29:
1.75      andrew     30:     local _nv=`echo $NEW_VER | sed -e 's/\.//'`
1.5       andrew     31:     local _c _d _e
                     32:     echo -n base
1.75      andrew     33:     [ $_nv -lt 57 ] && echo -n ' etc'
1.3       andrew     34:     for _d in misc man comp game xbase xetc xfont xserv xshare; do
1.75      andrew     35:         [ $_d = xetc -a $_nv -ge 57 ] && continue
1.3       andrew     36:         eval _e=\$${_d}
                     37:         _c=`ls $_e 2> /dev/null | wc -l`
                     38:         #echo $_c $_d $_e
                     39:         if [ $_c -ne 0 ]; then
1.5       andrew     40:             echo -n " $_d"
1.2       andrew     41:         fi
                     42:     done
1.19      andrew     43:
1.34      andrew     44:     sendmail -d0.1 --badoption </dev/null 2>/dev/null | grep -q SASL
1.94      andrew     45:     if [ $? == 0 ]; then
1.19      andrew     46:         echo -n ' sendmail-smtp_auth'
                     47:     fi
1.2       andrew     48: }
1.7       andrew     49:
1.39      andrew     50: kernel_file_version() {
                     51:     echo exit | config -e $1 | grep -A1 ^OpenBSD
                     52:     #what $1 | sed -ne 's/[[:blank:]]\{1,\}//p'
                     53: }
                     54:
1.105     andrew     55: kernel_is_multiprocessor() {
                     56:     printf "find cpu*\nexit\n" | config -e $1 2>/dev/null | grep -q "cpu\* at "
                     57: }
                     58:
1.16      andrew     59: version_in() {
1.10      andrew     60:         local _proto=${FTP%%://*}
1.16      andrew     61:         local _file
1.10      andrew     62:
                     63:         if [ X"ftp" == X"${_proto}" ]; then
1.16      andrew     64:             local _list=`echo "ls base*.tgz" | ${FTP_CMD} ${FTP}/`
                     65:             _file=`echo ${_list} | awk '/base[0-9][0-9].tgz/ { print $9 }'`
1.15      andrew     66:
1.87      andrew     67:         elif [ X"http" == X"${_proto}" -o X"https" == X"${_proto}" ]; then
1.96      andrew     68:             _file=`${FTP_CMD} -V -o - ${FTP}/index.txt |
                     69:                sed -ne 's/.*\(base[0-9][0-9].tgz\).*/\1/p'`
1.15      andrew     70:
                     71:         elif [ X"scp" == X"${_proto}" ]; then
                     72:             echo SCP is not yet supported >&2
                     73:             return 2
                     74:
1.96      andrew     75:         else
1.10      andrew     76:             echo Unsupported FTP ${FTP} >&2
1.12      andrew     77:             return 2
1.15      andrew     78:
1.10      andrew     79:         fi
1.16      andrew     80:
                     81:         local _v=${_file##*base}
                     82:         _v=${_v%.tgz*}
                     83:         echo $_v
1.10      andrew     84: }
1.2       andrew     85:
1.98      andrew     86: set_boot_device() {
1.111     andrew     87:        BOOT_DEVICE=$( df -lnP /bsd | sed -ne 's! .*/$!!p' )
1.97      andrew     88:
1.98      andrew     89:        root_disk=$( echo $BOOT_DEVICE |
1.97      andrew     90:            sed -e 's,/dev/\([a-z]*[0-9]\)[a-z].*,\1,' )
                     91:        msdos_partition=$(
                     92:            fdisk $root_disk | grep -q '^*.*FAT32' \
                     93:            && \
                     94:            disklabel $root_disk | sed -ne 's/:.*MSDOS//p' | tr -d ' '
                     95:        )
                     96:
                     97:        [ "$msdos_partition" ] &&
1.98      andrew     98:            BOOT_DEVICE="/dev/$root_disk$msdos_partition"
1.97      andrew     99: }
                    100:
1.99      andrew    101: boot_device_mounted=""
                    102: mount_boot_device() {
1.103     andrew    103:     [ "$boot_device_mounted" ] && return
1.109     andrew    104:     [ "$BOOT_DEVICE" ] || return
1.99      andrew    105:
                    106:     local boot_mount=$( mount |
                    107:            sed -ne "s!^$BOOT_DEVICE on \([^ ]*\).*!\1!p" )
                    108:
                    109:     if [ ! "$boot_mount" ]; then
1.101     andrew    110:         mount $BOOT_DEVICE /mnt
1.102     andrew    111:         boot_device_mounted=1
1.99      andrew    112:     fi
                    113: }
                    114:
                    115: umount_boot_device() {
1.101     andrew    116:     [ "$boot_device_mounted" ] && umount $BOOT_DEVICE
1.99      andrew    117:     boot_device_mounted=""
                    118: }
                    119:
1.104     andrew    120: find_boot_kernel() {
                    121:     local _k=$( ( \
                    122:         echo bsd; \
                    123:         [ -e boot.conf ] && sed -E '/^ *(set +image|boot) +/!d ; \
                    124:             s///; s/^.*://; s/ .*$//' boot.conf \
                    125:     ) | tail -1 )
                    126:     _k=$( follow_symlink $_k )
                    127:
                    128:     local _d=$( dirname $_k )
                    129:     [ "$_d" = "." ] && _d=$PWD
                    130:
                    131:     if [ $_d = . -o $_d = $PWD ]; then
                    132:         basename $_k
                    133:     else
                    134:         echo $_k
                    135:     fi
                    136: }
                    137:
1.2       andrew    138: set_version() {
                    139:     CUR_VER=`uname -r`
1.3       andrew    140:     NEW_VER=`dc -e "$CUR_VER 0.1 + p"`
1.5       andrew    141:     FILE_VER=""
                    142:     FTP=""
1.2       andrew    143:
1.5       andrew    144:     local _cv=`echo $CUR_VER | sed -e 's/\.//'`
                    145:     local _nv=`echo $NEW_VER | sed -e 's/\.//'`
1.111     andrew    146:     local _v _d _pkr
1.5       andrew    147:
1.10      andrew    148:     if [ X"No" != X"$FORCE_DIR" -a -d $FORCE_DIR ]; then
1.5       andrew    149:         _dir=$FORCE_DIR
                    150:         if [ -e ${_dir}/base${_nv}.tgz ]; then
                    151:             _v=$_nv
                    152:         elif [ -e ${_dir}/base${_cv}.tgz ]; then
                    153:             NEW_VER=$CUR_VER
                    154:             _v=$_cv
                    155:         fi
1.2       andrew    156:
1.5       andrew    157:     elif [ -d $CUR_VER ]; then
                    158:         _dir=$CUR_VER
1.2       andrew    159:         NEW_VER=$CUR_VER
1.5       andrew    160:         if [ -e ${_dir}/base${_cv}.tgz ]; then
                    161:             _v=$_cv
                    162:         fi
1.2       andrew    163:
1.5       andrew    164:     elif [ -d $NEW_VER ]; then
                    165:         _dir=$NEW_VER
                    166:         if [ -e ${_dir}/base${_nv}.tgz ]; then
                    167:             _v=$_nv
                    168:         fi
1.2       andrew    169:
                    170:     fi
                    171:
1.17      andrew    172:     if [ X"" != X"${MIRROR}" -a X"" == X"${_v}" ]; then
1.89      andrew    173:         if [ X"No" != X"${FORCE_DIR}" ]; then
                    174:             _dir=${FORCE_DIR}
                    175:         elif sysctl kern.version | grep -q -- '-current '; then
                    176:             _dir=snapshots
                    177:             FORCE_DIR=snapshots
                    178:         else
1.5       andrew    179:             _dir=${NEW_VER}
                    180:         fi
                    181:         FTP=${MIRROR}/${_dir}/`machine`
1.2       andrew    182:
1.16      andrew    183:         _v=`version_in`
1.10      andrew    184:
1.16      andrew    185:         if [ X"" == X"${_v}" ]; then
1.10      andrew    186:             if [ X"No" != X"$FORCE_DIR" ]; then
                    187:                 echo No sets in forced [${FTP}] >&2
1.12      andrew    188:                 return 2
1.10      andrew    189:             fi
                    190:
                    191:             NEW_VER=$CUR_VER
                    192:             _dir=${NEW_VER}
                    193:             FTP=${MIRROR}/${_dir}/`machine`
                    194:
1.16      andrew    195:             _v=`version_in`
1.9       andrew    196:         fi
                    197:
1.10      andrew    198:         if [ X"" == X"${_v}" ]; then
1.16      andrew    199:             echo No sets in [${FTP}] >&2
1.94      andrew    200:             return 2
1.10      andrew    201:         elif [ X"${_cv}" == X"${_v}" ]; then
1.5       andrew    202:             NEW_VER=$CUR_VER
1.9       andrew    203:         elif [ X"${_nv}" == X"${_v}" ]; then
                    204:             NEW_VER=$NEW_VER
1.2       andrew    205:         else
1.10      andrew    206:             echo Invalid version [$_v] >&2
1.12      andrew    207:             return 2
1.2       andrew    208:         fi
                    209:
1.10      andrew    210:         if [ X"No" == X"$FORCE_DIR" ]; then
1.5       andrew    211:             _dir=$NEW_VER
1.2       andrew    212:         fi
                    213:
                    214:     fi
                    215:
1.5       andrew    216:     if [ X"" == X"${_v}" ]; then
1.64      andrew    217:         if [ X"" == X"${MIRROR}" ]; then
                    218:             echo ERROR: No sets, and no MIRROR, unable to continue. >&2
                    219:         else
                    220:             echo ERROR: Unable to determine FILE_VER, check your MIRROR. >&2
                    221:         fi
1.12      andrew    222:         return 1
1.2       andrew    223:     fi
                    224:
1.5       andrew    225:     if [ X"" == X"$RELEASEDIR" ]; then
                    226:         RELEASEDIR=`pwd`/$_dir
1.2       andrew    227:     fi
1.9       andrew    228:
1.5       andrew    229:     FILE_VER=$_v
1.17      andrew    230:     if [ X"" != X"${MIRROR}" ]; then
                    231:         FTP=${MIRROR}/${_dir}/`machine`
                    232:     fi
1.39      andrew    233:
1.101     andrew    234:     KERNEL_ROOT=""
                    235:     [ -z "$BOOT_DEVICE" ] && set_boot_device
                    236:
1.104     andrew    237:     mount_boot_device
1.111     andrew    238:
                    239:     # _pkr == possible_kernel_roots
                    240:     _pkr=/
                    241:     [ "$BOOT_DEVICE" ] && _pkr="/mnt/ $_pkr"
                    242:
                    243:     for _d in $_pkr; do
                    244:        KERNEL_ROOT=$( df -lnP ${_d}bsd 2>/dev/null | sed -ne 's!/dev/.* !!p' )
                    245:        [ "$KERNEL_ROOT" ] && break
                    246:     done
                    247:
1.112     andrew    248:     if ! [ "$KERNEL_ROOT" ]; then
1.111     andrew    249:         echo "Unable to find KERNEL_ROOT, tried $_pkr" >&2
                    250:         exit 2
                    251:     fi
                    252:
1.104     andrew    253:     cd $KERNEL_ROOT
                    254:     BOOT_KERNEL=$( find_boot_kernel )
                    255:     BOOT_KERNEL_VERSION=$( kernel_file_version $BOOT_KERNEL )
1.106     andrew    256:     if [ $(sysctl -n hw.ncpufound) -gt 1 ] || kernel_is_multiprocessor $BOOT_KERNEL; then
                    257:         BOOT_KERNEL=bsd.mp
                    258:     fi
1.39      andrew    259:
                    260:     BOOTED_KERNEL_VERSION=`sysctl -n kern.version`
                    261:     NEW_KERNEL_VERSION=""
                    262:
                    263:     # We want to default to what we had
1.104     andrew    264:     INSTALL_KERNELS="$BOOT_KERNEL"
1.48      andrew    265:     # if the boot kernel was our specially named bsd.sp, we install from bsd
                    266:     if [ X"$INSTALL_KERNELS" == X"bsd.sp" ]; then
                    267:         INSTALL_KERNELS="bsd"
                    268:     fi
1.106     andrew    269:
                    270:     # We want to update all kernels that exist
                    271:     # either in the $KERNEL_ROOT or in /
                    272:     for b in bsd bsd.mp; do
                    273:         [ -e $b -o -e /$b ] || continue
                    274:         if [ X"${INSTALL_KERNELS% *}" != X"$b" ]; then
                    275:             INSTALL_KERNELS="$INSTALL_KERNELS $b"
                    276:         fi
                    277:     done
                    278:
                    279:     cd $OLDPWD
1.114   ! andrew    280:
        !           281:     EFI_BOOT=""
        !           282:     if [ -d "/mnt/efi/boot" ]; then
        !           283:         _d=$( cd "/mnt/efi/boot" && ls -1 *.{efi,EFI} 2>/dev/null )
        !           284:         # assume an MSDOS filesystem and so case insensitive
        !           285:         [ "$_d" ] && EFI_BOOT=$( echo $_d | tr a-z A-Z )
        !           286:     fi
        !           287:
1.106     andrew    288:     umount_boot_device
                    289:
1.39      andrew    290:     BOOT_KERNELS=$INSTALL_KERNELS
                    291:     INSTALL_KERNELS="$INSTALL_KERNELS bsd.rd"
1.2       andrew    292: }
                    293:
                    294: get_sets() {
1.54      andrew    295:     echo '==> GETTING SETS'
1.2       andrew    296:     if [ X"" == X"$FTP" ]; then
1.5       andrew    297:         echo ERROR: No FTP site set! >&2
1.12      andrew    298:         return 1
1.2       andrew    299:     fi
                    300:
1.5       andrew    301:     mkdir -p ${RELEASEDIR}
                    302:     cd $RELEASEDIR
1.2       andrew    303:
1.5       andrew    304:     local _v=$FILE_VER
1.2       andrew    305:
1.114   ! andrew    306:     if [ "$EFI_BOOT" ]; then
        !           307:         _b="$EFI_BOOT"
        !           308:         if [ ! -e ./${_b} ]; then
        !           309:             echo "===> $FTP_CMD ${FTP}/${_b}"
        !           310:             $FTP_CMD ${FTP}/${_b}
        !           311:         else
        !           312:             echo "===> Have ${_b}"
        !           313:         fi
        !           314:     fi
        !           315:
1.39      andrew    316:     for _b in $INSTALL_KERNELS; do
1.45      andrew    317:         if [ ! -e ./${_b} ]; then
1.54      andrew    318:             echo "===> $FTP_CMD ${FTP}/${_b}"
1.3       andrew    319:             $FTP_CMD ${FTP}/${_b}
1.70      andrew    320:         else
                    321:             echo "===> Have ${_b}"
1.2       andrew    322:         fi
1.70      andrew    323:         kernel_file_version "${_b}"
1.2       andrew    324:     done
                    325:
1.5       andrew    326:     for _s in $INSTALLED_SETS; do
1.71      andrew    327:         [ "$_v" -ge "57" -a "$_s" != "${_s%etc}" ] && continue
1.19      andrew    328:         local _file=${_s}${_v}.tgz
                    329:         if [ ${_s} == sendmail-smtp_auth ]; then
                    330:             _file=${_s}.gz
                    331:         fi
                    332:
                    333:         if [ ! -e ./${_file} ]; then
1.54      andrew    334:             echo "===> $FTP_CMD ${FTP}/${_file}"
1.19      andrew    335:             $FTP_CMD ${FTP}/${_file}
1.5       andrew    336:         fi
1.2       andrew    337:     done
                    338:
1.20      andrew    339:     local _type
1.56      andrew    340:     local _ftp
1.20      andrew    341:     for _type in $CHECKSUM_TYPES; do
1.40      andrew    342:         [ -e $_type ] && break
1.56      andrew    343:         _ftp=`echo "$FTP" | sed -e 's,://[^/]*/,://ftp.openbsd.org/,'`
                    344:         echo "===> $FTP_CMD ${_ftp}/$_type"
                    345:         $FTP_CMD ${_ftp}/$_type
1.20      andrew    346:     done
1.17      andrew    347: }
                    348:
1.23      andrew    349: follow_symlink () {
                    350:     local _file=$1
1.33      andrew    351:     # This could go circular, but I dunno how to fix that.
                    352:     if [ -h $_file ]; then
1.77      andrew    353:         follow_symlink $( readlink -f $_file )
1.23      andrew    354:     else
1.33      andrew    355:         echo $_file
1.23      andrew    356:     fi
                    357: }
                    358:
1.20      andrew    359: check_sum () {
                    360:     local _type=$1
1.54      andrew    361:     echo "==> CHECKING $_type SUMS"
1.17      andrew    362:     cd $RELEASEDIR
                    363:
1.20      andrew    364:     if [ ! -e $_type ]; then
                    365:         echo $_type File does not exist!
1.17      andrew    366:         return 1
                    367:     fi
1.6       andrew    368:
1.57      andrew    369:     local _nv=`echo $NEW_VER | sed -e 's/\.//'`
1.61      andrew    370:     local _signify=`which signify 2>/dev/null`
1.94      andrew    371:     local _keyfile=/etc/signify/openbsd-${_nv}-base.pub
1.59      andrew    372:     local _b _s
1.57      andrew    373:
                    374:     (
1.58      andrew    375:         for _b in $INSTALL_KERNELS; do echo "($_b)"        ; done
                    376:         for _s in $INSTALLED_SETS;  do echo "($_s$_nv.tgz)"; done
1.57      andrew    377:     ) > index
1.94      andrew    378:
1.59      andrew    379:
                    380:     if [ -n "$_signify" -a "$_type" != "${_type%.sig}" ]; then
                    381:         echo "===> Checking signature";
                    382:         if [ ! -e $_keyfile ]; then
                    383:             echo "key [$_keyfile] does not exist, cannot check $_type" >&2
                    384:             return 2
                    385:         fi
1.67      andrew    386:         signify -V -e -p $_keyfile -x $_type -m - | grep -f index | sha256 -c -
1.59      andrew    387:     else
1.73      andrew    388:        grep -f index $_type | sha256 -c
1.59      andrew    389:     fi
1.2       andrew    390:
                    391:     if [ $? -ne 0 ]; then
1.20      andrew    392:         echo ERROR: $_type does not match! >&2
1.12      andrew    393:         return 1
1.2       andrew    394:     fi
                    395: }
                    396:
1.17      andrew    397: check_sets() {
1.54      andrew    398:     echo '==> CHECKING SETS'
1.17      andrew    399:     cd $RELEASEDIR
                    400:
1.18      andrew    401:     local _missing_sets
1.17      andrew    402:     local _v=$FILE_VER
                    403:
1.104     andrew    404:     mount_boot_device
1.39      andrew    405:     for _n in $INSTALL_KERNELS; do
                    406:         local _o=$_n
1.104     andrew    407:         [ X"bsd" == X"${_o}" -a -e ${KERNEL_ROOT}bsd.sp ] && _o=bsd.sp
                    408:         if [ -e ${KERNEL_ROOT}${_o} -a ! -e ./${_n} ]; then
                    409:             echo ${_o} does not exist on $BOOT_DEVICE
1.39      andrew    410:             _missing_sets=1
1.17      andrew    411:         fi
1.39      andrew    412:
1.104     andrew    413:         if [ X"${BOOT_KERNEL}" == X"${_o}" -a -e ./${_n} ]; then
1.39      andrew    414:             NEW_KERNEL_VERSION=`kernel_file_version ./${_n}`
1.17      andrew    415:         fi
                    416:     done
1.104     andrew    417:     umount_boot_device
1.17      andrew    418:
1.39      andrew    419:     if [ X"$NEW_KERNEL_VERSION" == X"" ]; then
                    420:         echo Missing replacement for boot kernel $BOOT_KERNEL >&2
                    421:         _missing_sets=1
                    422:     fi
                    423:
1.17      andrew    424:     for _s in $INSTALLED_SETS; do
1.71      andrew    425:         [ "$_v" -ge "57" -a "$_s" != "${_s%etc}" ] && continue
1.19      andrew    426:         local _file=${_s}${_v}.tgz
                    427:         if [ ${_s} == sendmail-smtp_auth ]; then
                    428:             _file=${_s}.gz
                    429:         fi
                    430:         if [ ! -e ./${_file} ]; then
                    431:             echo ${_file} does not exist
1.18      andrew    432:             _missing_sets=1
1.17      andrew    433:         fi
                    434:     done
1.18      andrew    435:
                    436:     if [ X"" == X"${_missing_sets}" ]; then
1.85      andrew    437:         echo 'All OK'
1.18      andrew    438:     fi
1.17      andrew    439:
1.20      andrew    440:     local _type
                    441:     for _type in $CHECKSUM_TYPES; do
1.74      andrew    442:        [ -n "$NO_SIGNIFY" -a "$_type" != "${_type%.sig}" ] && continue
1.20      andrew    443:         if [ -e $_type ]; then
1.59      andrew    444:             check_sum $_type && break
1.62      andrew    445:             [ -z "$IGNORE_CHECKSUM_ERROR" ] && exit 1
1.20      andrew    446:         fi
                    447:     done
1.59      andrew    448:
                    449:     return 0
1.17      andrew    450: }
                    451:
                    452:
1.30      andrew    453: install_kernels() {
1.110     andrew    454:     local _d="$1"
1.97      andrew    455:     local boot_mount
                    456:     local mount_is_msdos
                    457:
1.110     andrew    458:     if [ "$_d" ]; then
                    459:       _d=$( readlink -nf "$_d" )
                    460:     else
1.101     andrew    461:         mount_boot_device
1.97      andrew    462:
1.111     andrew    463:        if [ "$KERNEL_ROOT" != "/" ]; then
1.99      andrew    464:                local _ik="$INSTALL_KERNELS"
1.104     andrew    465:                INSTALL_KERNELS="$BOOT_KERNEL bsd.rd"
1.97      andrew    466:
1.101     andrew    467:                install_kernels $KERNEL_ROOT
1.99      andrew    468:
                    469:                INSTALL_KERNELS="$_ik"
1.97      andrew    470:        fi
                    471:
1.99      andrew    472:         umount_boot_device
                    473:
1.111     andrew    474:         install_kernels /
1.97      andrew    475:         return
                    476:     fi
                    477:
                    478:     echo "==> INSTALLING KERNEL to $_d"
1.2       andrew    479:
                    480:     if [ X"" == X"$RELEASEDIR" ]; then
1.5       andrew    481:         echo ERROR: no source for new kernels! >&2
1.2       andrew    482:         exit 1
                    483:     fi
                    484:
1.111     andrew    485:     [ $_d != / ] && _d=${_d%/}/
1.100     andrew    486:     [ $_d != / ] && mount | grep -q " on ${_d%/} .* msdos" && mount_is_msdos=1
1.97      andrew    487:
1.114   ! andrew    488:     if [ "$EFI_BOOT" -a -d /mnt/efi/boot ]; then
        !           489:        echo "Copying $EFI_BOOT to /mnt/efi/boot/$EFI_BOOT"
        !           490:        cp "$EFI_BOOT" "/mnt/efi/boot/"
        !           491:     fi
        !           492:
1.46      andrew    493:     if [ X"$BOOT_KERNEL_VERSION" != X"$NEW_KERNEL_VERSION" ]; then
1.97      andrew    494:         echo "===> Backing up $BOOT_KERNEL to ${_d}obsd"
                    495:         if [ $mount_is_msdos ]; then
1.107     andrew    496:             cp ${_d}$BOOT_KERNEL ${_d}obsd
1.97      andrew    497:         else
1.107     andrew    498:             ln -f ${_d}$BOOT_KERNEL ${_d}obsd
1.97      andrew    499:         fi
1.46      andrew    500:         if [ $? -ne 0 ]; then
                    501:             echo "Error copying old kernel!" >&2
                    502:             exit 1
                    503:         fi
1.2       andrew    504:     fi
                    505:
1.39      andrew    506:     cd $RELEASEDIR
1.23      andrew    507:
1.39      andrew    508:     for _b in $INSTALL_KERNELS; do
1.97      andrew    509:         rm -f ${_d}nbsd
1.39      andrew    510:         local _bd=$_b
                    511:         [ X"${_b}" == X"bsd" ] && _bd="bsd.sp"
1.2       andrew    512:
1.39      andrew    513:         local _is_boot=""
1.97      andrew    514:         [ X"$BOOT_KERNEL" == X"${_d}${_bd}" ] && _is_boot="# boot kernel"
1.94      andrew    515:
1.97      andrew    516:         echo "Copying $_b to ${_d}$_bd $_is_boot"
                    517:         cp ${_b} ${_d}nbsd && mv ${_d}nbsd ${_d}${_bd}
1.2       andrew    518:         if [ $? -ne 0 ]; then
1.39      andrew    519:             echo ERROR: Could not copy new $_bd kernel! >&2
1.2       andrew    520:             exit 1
                    521:         fi
1.39      andrew    522:     done
                    523:
                    524:     cd $OLDPWD
1.23      andrew    525:
1.97      andrew    526:     if [ ! -h ${_d}bsd ]; then
                    527:         cd ${_d}
1.39      andrew    528:         for _b in $BOOT_KERNELS; do
                    529:             [ X"$_b" == X"bsd" ] && _b="bsd.sp"
                    530:             if [ -e $_b ]; then
1.97      andrew    531:                 if [ "$mount_is_msdos" ]; then
                    532:                     echo "===> Moving $_b ${_d}bsd (MSDOS)"
                    533:                     mv -f ${_b} bsd
                    534:                 else
                    535:                     echo "===> symlinking $_b to ${_d}bsd"
                    536:                     ln -sf $_b bsd
1.39      andrew    537:                 fi
                    538:                 break
                    539:             fi
                    540:         done
1.97      andrew    541:         cd $OLDPWD
1.2       andrew    542:     fi
                    543: }
                    544:
                    545: install_sets() {
1.54      andrew    546:     echo '==> INSTALLING SETS'
1.2       andrew    547:
                    548:     if [ X"" == X"$RELEASEDIR" ]; then
1.5       andrew    549:         echo ERROR: no source for sets! >&2
1.2       andrew    550:         exit 1
                    551:     else
                    552:         cd $RELEASEDIR
                    553:     fi
                    554:
1.5       andrew    555:     local _v=$FILE_VER
                    556:
1.21      andrew    557:     local _sets=`ls *${_v}.tgz | grep -v ^base `
                    558:     for _f in ${_sets} base${_v}.tgz; do
1.3       andrew    559:         _path=$DESTDIR
                    560:         if [ X"etc${_v}.tgz"  == X"$_f" \
                    561:             -o X"xetc${_v}.tgz" == X"$_f" ]; then
1.21      andrew    562:             [ X"" != X"$SYSMERGE" ] && continue
1.2       andrew    563:             _path=/var/tmp/temproot
                    564:         fi
                    565:
1.85      andrew    566:         echo "Extracting $_f to $_path"
1.65      andrew    567:         mkdir -p $_path
                    568:         tar -C $_path -xzphf ${RELEASEDIR}/${_f}
1.2       andrew    569:         if [ $? -ne 0 ]; then
1.5       andrew    570:             echo ERROR: Could not extract ${_f}! >&2
1.2       andrew    571:             exit 1
                    572:         fi
                    573:     done
                    574:
1.54      andrew    575:     echo '===> Extracted all sets.'
1.51      andrew    576: }
1.19      andrew    577:
1.51      andrew    578: install_sendmail_smtp_auth() {
1.19      andrew    579:     if [ -e ${RELEASEDIR}/sendmail-smtp_auth.gz ]; then
                    580:         gzcat ${RELEASEDIR}/sendmail-smtp_auth.gz > \
                    581:             ${RELEASEDIR}/sendmail-smtp_auth
                    582:     fi
                    583:     if [ -e ${RELEASEDIR}/sendmail-smtp_auth ]; then
1.21      andrew    584:         if ! pkg_info -qe 'cyrus-sasl-*'; then
1.65      andrew    585:             pkg_add -i cyrus-sasl
1.21      andrew    586:         fi
                    587:
1.65      andrew    588:         install -o root -g smmsp -m 2555 \
1.19      andrew    589:             ${RELEASEDIR}/sendmail-smtp_auth \
1.21      andrew    590:             /usr/libexec/sendmail/sendmail
1.19      andrew    591:
1.54      andrew    592:         echo '===> Installed sendmail with smtp_auth'
1.19      andrew    593:     fi
1.2       andrew    594: }
                    595:
                    596: update_etc() {
1.54      andrew    597:     echo '==> UPDATING ETC'
1.10      andrew    598:     if [ ! -e $SYSMERGE ]; then
1.47      andrew    599:         echo "ERROR: Can't find sysmerge!" >&2
                    600:         exit 1;
1.10      andrew    601:     fi
                    602:
1.68      andrew    603:     local _v=$FILE_VER
                    604:     local _args=""
                    605:
1.80      andrew    606:     if [ ! -e /var/sysmerge/etc.tgz ]; then
1.68      andrew    607:         if [ X"" == X"$RELEASEDIR" ]; then
                    608:             echo "ERROR: no source for etc!" >&2
                    609:             exit 1
                    610:         fi
1.2       andrew    611:
1.68      andrew    612:         cd $RELEASEDIR
1.5       andrew    613:
1.68      andrew    614:         if [ -e etc${_v}.tgz ]; then
                    615:             _args="$_args -s ${RELEASEDIR}/etc${_v}.tgz"
                    616:         fi
                    617:         if [ -e xetc${_v}.tgz ]; then
                    618:             _args="$_args -x ${RELEASEDIR}/xetc${_v}.tgz"
                    619:         fi
1.94      andrew    620:         if [ X"" == X"$_args" ]; then
1.68      andrew    621:             echo ERROR: No upgrade sets found! >&2
                    622:             exit 1
                    623:         fi
1.47      andrew    624:     fi
1.68      andrew    625:
                    626:     echo '==> RUNNING SYSMERGE'
                    627:     $SYSMERGE $_args
1.2       andrew    628:
1.47      andrew    629:     cd $OLDPWD
1.2       andrew    630: }
1.14      andrew    631:
1.20      andrew    632:
1.65      andrew    633: if [ $(id -u) != 0 ]; then
                    634:     echo 'ERROR: need root privileges to run this script' >&2
                    635:     exit 1
                    636: fi
                    637:
1.14      andrew    638: if [ -e /etc/update_openbsd.conf ]; then
                    639:     . /etc/update_openbsd.conf
                    640: fi
                    641:
                    642: if [ -e ${HOME}/.update_openbsdrc ]; then
                    643:     . ${HOME}/.update_openbsdrc
                    644: fi
                    645:
1.108     andrew    646: MIRROR=${MIRROR:=http://cdn.openbsd.org/pub/OpenBSD}
1.14      andrew    647: FTP_CMD=${FTP_CMD:=ftp -V}
                    648:
                    649: DESTDIR=${DESTDIR:=/}
                    650: SYSMERGE=${SYSMERGE:=/usr/sbin/sysmerge}
                    651: FORCE_DIR=${FORCE_DIR:=No}
1.79      andrew    652:
1.84      andrew    653: export PKG_PATH TRUSTED_PKG_PATH
                    654:
1.79      andrew    655: set_version
1.91      andrew    656:
1.95      andrew    657: TRUSTED_PKG_PATH=${TRUSTED_PKG_PATH:=/usr/ports/packages/`machine -a`/all}
                    658: if [ "$FORCE_DIR" = "No" ]; then
                    659:        PKG_PATH=${PKG_PATH:=${MIRROR}/$NEW_VER/packages/`machine -a`}
                    660: else
                    661:        PKG_PATH=${PKG_PATH:=${MIRROR}/$FORCE_DIR/packages/`machine -a`}
                    662: fi
1.14      andrew    663:
                    664: INSTALLED_SETS=${INSTALLED_SETS:=`installed_sets`}
1.2       andrew    665:
1.59      andrew    666: CHECKSUM_TYPES=${CHECKSUM_TYPES:=SHA256.sig SHA256}
1.20      andrew    667:
1.12      andrew    668: local _error=$?
1.2       andrew    669:
                    670: echo
                    671: echo "-= update_openbsd - helper script to update OpenBSD =-"
                    672: echo "------------------------------------------------------"
                    673: echo
1.84      andrew    674: echo "        SYSMERGE: $SYSMERGE"
1.88      andrew    675: echo "          MIRROR: $FTP"
1.84      andrew    676: echo "        PKG_PATH: $PKG_PATH"
                    677: echo "TRUSTED_PKG_PATH: $TRUSTED_PKG_PATH"
                    678: echo "      RELEASEDIR: $RELEASEDIR"
                    679: echo "         DESTDIR: $DESTDIR"
1.98      andrew    680: echo "     BOOT_DEVICE: $BOOT_DEVICE"
1.114   ! andrew    681: [ "$EFI_BOOT" ] && echo "        EFI_BOOT: $EFI_BOOT"
1.84      andrew    682: echo "     BOOT_KERNEL: $BOOT_KERNEL"
                    683: echo " INSTALL_KERNELS: $INSTALL_KERNELS"
                    684: echo "  INSTALLED_SETS: $INSTALLED_SETS"
1.8       andrew    685: echo
1.84      andrew    686: echo "         CUR_VER: $CUR_VER"
                    687: echo "         NEW_VER: $NEW_VER"
                    688: #echo "        FILE_VER: $FILE_VER"
1.2       andrew    689: echo
1.70      andrew    690:
1.104     andrew    691: mount_boot_device
1.113     andrew    692: l=$KERNEL_ROOT
                    693: [ "$l" = / ] || l="$BOOT_DEVICE:"
1.70      andrew    694: for k in $INSTALL_KERNELS; do
1.104     andrew    695:     if [ -e $KERNEL_ROOT$k ]; then
1.113     andrew    696:         echo "Existing $l$k"
1.104     andrew    697:         kernel_file_version $KERNEL_ROOT$k
1.70      andrew    698:     fi
                    699: done
1.104     andrew    700: umount_boot_device
1.12      andrew    701:
                    702: if [ ${_error} -ne 0 ]; then
                    703:        exit ${_error}
                    704: fi
1.2       andrew    705:
1.17      andrew    706: if [ X"" != X"${FTP}" ]; then
1.20      andrew    707:     get_sets
1.17      andrew    708: fi
                    709:
                    710: check_sets || exit
1.39      andrew    711:
1.54      andrew    712: echo "===> Last booted:\n$BOOTED_KERNEL_VERSION"
1.39      andrew    713: if [ X"$BOOT_KERNEL_VERSION" != X"$BOOTED_KERNEL_VERSION" \
                    714:   -a X"$BOOT_KERNEL_VERSION" != X"$NEW_KERNEL_VERSION" ]; then
                    715:     echo "Next boot (unless replaced):\n$BOOT_KERNEL_VERSION"
                    716: fi
                    717: if [ -n "$NEW_KERNEL_VERSION" ]; then
1.54      andrew    718:     echo "===> New $BOOT_KERNEL:\n$NEW_KERNEL_VERSION";
1.39      andrew    719: else
                    720:     echo "\n!!! WARNING: Will not replace boot kernel $BOOT_KERNEL! !!!\n" >&2
                    721:     echo "ctrl+C to cancel, enter to continue anyway" >&2
1.44      andrew    722:     local _temp
                    723:     read _temp
1.53      andrew    724:     NEW_KERNEL_VERSION=$BOOT_KERNEL_VERSION
1.44      andrew    725: fi
                    726:
1.66      andrew    727: if [ X"$NEW_KERNEL_VERSION" != X"$BOOTED_KERNEL_VERSION" ]; then
1.44      andrew    728:     echo >&2
1.66      andrew    729:     echo "!!!  You are upgrading the OpenBSD kernel.        !!!" >&2
                    730:     echo "!!!  You will be given the opportunity to reboot  !!!" >&2
1.94      andrew    731:     echo "!!!  at the end of the proces but it is safer to  !!!" >&2
1.66      andrew    732:     echo "!!!  have a separate root shell open.             !!!" >&2
                    733:     echo "!!!  It is needed in order to run /sbin/oreboot.  !!!" >&2
1.78      andrew    734:     echo "!!!  doas MAY NOT WORK after sets are extracted.  !!!" >&2
1.44      andrew    735:     echo >&2
1.66      andrew    736:     echo "enter to continue, ctrl+C to cancel" >&2
1.39      andrew    737:     local _temp
                    738:     read _temp
1.2       andrew    739:
1.66      andrew    740:     if [ ! -e /sbin/oreboot ]; then
                    741:         cp /sbin/reboot /sbin/oreboot
                    742:         if [ $? -ne 0 ]; then
                    743:             echo "Error copying old reboot command!" >&2
                    744:             exit 1
                    745:         fi
                    746:         echo "/sbin/reboot copied to /sbin/oreboot"
1.50      andrew    747:     fi
1.2       andrew    748: fi
                    749:
1.30      andrew    750: install_kernels
1.21      andrew    751: install_sets
1.2       andrew    752:
1.53      andrew    753: if [ X"$NEW_KERNEL_VERSION" == X"$BOOTED_KERNEL_VERSION" ]; then
1.51      andrew    754:     install_sendmail_smtp_auth
                    755:
1.21      andrew    756:     if [ -e /sbin/oreboot ]; then
                    757:         echo Removing /sbin/oreboot
1.69      andrew    758:         rm -f /sbin/oreboot
1.21      andrew    759:     fi
1.2       andrew    760:     update_etc
                    761:
1.81      andrew    762:     OPENUP=$( which openup 2>/dev/null )
1.76      andrew    763:     if [ -n "$OPENUP" ]; then
                    764:         echo "==> UPDATING WITH $OPENUP"
                    765:         $OPENUP
                    766:     else
                    767:         echo '==> UPDATING PACKAGES'
1.86      andrew    768:         pkg_add -u
1.76      andrew    769:     fi
1.72      andrew    770:
                    771:     echo '==> UPDATING FIRMWARE'
                    772:     fw_update
1.2       andrew    773:
                    774: else
1.83      andrew    775:     [ -e /etc/rc.sysmerge ] && grep -q $SYSMERGE /etc/rc.sysmerge ||
1.82      andrew    776:         echo "$SYSMERGE -b" >>/etc/rc.sysmerge &&
                    777:         echo "==> RUNNING $SYSMERGE -b ON REBOOT"
                    778:
1.94      andrew    779:     echo Instructions for updating to the new version available from
1.36      andrew    780:     if [ X"snapshots" == X"$FORCE_DIR" ]; then
1.30      andrew    781:         echo "  http://www.openbsd.org/faq/current.html"
                    782:     else
                    783:         echo "  http://www.openbsd.org/faq/upgrade${FILE_VER}.html"
                    784:     fi
1.2       andrew    785: fi
                    786:
1.66      andrew    787: echo Update complete. enter to reboot, ctrl+C to cancel
1.65      andrew    788: read _temp
1.22      andrew    789: if [ -e /sbin/oreboot ]; then
1.66      andrew    790:     echo using /sbin/oreboot
1.65      andrew    791:     /sbin/oreboot
                    792: else
                    793:     /sbin/reboot
1.22      andrew    794: fi

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