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

Annotation of openbsd/update_openbsd/update_openbsd, Revision 1.120

1.1       andrew      1: #!/bin/sh
1.120   ! andrew      2: # $AFresh1: update_openbsd,v 1.119 2018/12/16 23:42:07 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}
1.120   ! andrew    175:         elif sysctl kern.version | grep -q -e '-current ' -e '-beta '; then
1.89      andrew    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
1.118     andrew    254:     BOOTED_KERNEL=$( find_boot_kernel )
                    255:     BOOT_KERNEL_VERSION=$( kernel_file_version $BOOTED_KERNEL )
                    256:
                    257:     if [ $(sysctl -n hw.ncpufound) -gt 1 ] || kernel_is_multiprocessor $BOOTED_KERNEL; then
1.106     andrew    258:         BOOT_KERNEL=bsd.mp
1.118     andrew    259:     else
                    260:         BOOT_KERNEL=$BOOTED_KERNEL
1.106     andrew    261:     fi
1.39      andrew    262:
                    263:     BOOTED_KERNEL_VERSION=`sysctl -n kern.version`
                    264:     NEW_KERNEL_VERSION=""
                    265:
                    266:     # We want to default to what we had
1.104     andrew    267:     INSTALL_KERNELS="$BOOT_KERNEL"
1.48      andrew    268:     # if the boot kernel was our specially named bsd.sp, we install from bsd
                    269:     if [ X"$INSTALL_KERNELS" == X"bsd.sp" ]; then
                    270:         INSTALL_KERNELS="bsd"
                    271:     fi
1.106     andrew    272:
                    273:     # We want to update all kernels that exist
                    274:     # either in the $KERNEL_ROOT or in /
                    275:     for b in bsd bsd.mp; do
                    276:         [ -e $b -o -e /$b ] || continue
                    277:         if [ X"${INSTALL_KERNELS% *}" != X"$b" ]; then
                    278:             INSTALL_KERNELS="$INSTALL_KERNELS $b"
                    279:         fi
                    280:     done
                    281:
                    282:     cd $OLDPWD
1.114     andrew    283:
                    284:     EFI_BOOT=""
                    285:     if [ -d "/mnt/efi/boot" ]; then
                    286:         _d=$( cd "/mnt/efi/boot" && ls -1 *.{efi,EFI} 2>/dev/null )
                    287:         # assume an MSDOS filesystem and so case insensitive
                    288:         [ "$_d" ] && EFI_BOOT=$( echo $_d | tr a-z A-Z )
                    289:     fi
                    290:
1.106     andrew    291:     umount_boot_device
                    292:
1.39      andrew    293:     BOOT_KERNELS=$INSTALL_KERNELS
                    294:     INSTALL_KERNELS="$INSTALL_KERNELS bsd.rd"
1.2       andrew    295: }
                    296:
                    297: get_sets() {
1.54      andrew    298:     echo '==> GETTING SETS'
1.2       andrew    299:     if [ X"" == X"$FTP" ]; then
1.5       andrew    300:         echo ERROR: No FTP site set! >&2
1.12      andrew    301:         return 1
1.2       andrew    302:     fi
                    303:
1.5       andrew    304:     mkdir -p ${RELEASEDIR}
                    305:     cd $RELEASEDIR
1.2       andrew    306:
1.5       andrew    307:     local _v=$FILE_VER
1.2       andrew    308:
1.114     andrew    309:     if [ "$EFI_BOOT" ]; then
                    310:         _b="$EFI_BOOT"
                    311:         if [ ! -e ./${_b} ]; then
                    312:             echo "===> $FTP_CMD ${FTP}/${_b}"
                    313:             $FTP_CMD ${FTP}/${_b}
                    314:         else
                    315:             echo "===> Have ${_b}"
                    316:         fi
                    317:     fi
                    318:
1.39      andrew    319:     for _b in $INSTALL_KERNELS; do
1.45      andrew    320:         if [ ! -e ./${_b} ]; then
1.54      andrew    321:             echo "===> $FTP_CMD ${FTP}/${_b}"
1.3       andrew    322:             $FTP_CMD ${FTP}/${_b}
1.70      andrew    323:         else
                    324:             echo "===> Have ${_b}"
1.2       andrew    325:         fi
1.70      andrew    326:         kernel_file_version "${_b}"
1.2       andrew    327:     done
                    328:
1.5       andrew    329:     for _s in $INSTALLED_SETS; do
1.71      andrew    330:         [ "$_v" -ge "57" -a "$_s" != "${_s%etc}" ] && continue
1.19      andrew    331:         local _file=${_s}${_v}.tgz
                    332:         if [ ${_s} == sendmail-smtp_auth ]; then
                    333:             _file=${_s}.gz
                    334:         fi
                    335:
                    336:         if [ ! -e ./${_file} ]; then
1.54      andrew    337:             echo "===> $FTP_CMD ${FTP}/${_file}"
1.19      andrew    338:             $FTP_CMD ${FTP}/${_file}
1.5       andrew    339:         fi
1.2       andrew    340:     done
                    341:
1.20      andrew    342:     local _type
1.56      andrew    343:     local _ftp
1.20      andrew    344:     for _type in $CHECKSUM_TYPES; do
1.40      andrew    345:         [ -e $_type ] && break
1.56      andrew    346:         _ftp=`echo "$FTP" | sed -e 's,://[^/]*/,://ftp.openbsd.org/,'`
                    347:         echo "===> $FTP_CMD ${_ftp}/$_type"
                    348:         $FTP_CMD ${_ftp}/$_type
1.20      andrew    349:     done
1.17      andrew    350: }
                    351:
1.23      andrew    352: follow_symlink () {
                    353:     local _file=$1
1.33      andrew    354:     # This could go circular, but I dunno how to fix that.
                    355:     if [ -h $_file ]; then
1.77      andrew    356:         follow_symlink $( readlink -f $_file )
1.23      andrew    357:     else
1.33      andrew    358:         echo $_file
1.23      andrew    359:     fi
                    360: }
                    361:
1.20      andrew    362: check_sum () {
                    363:     local _type=$1
1.54      andrew    364:     echo "==> CHECKING $_type SUMS"
1.17      andrew    365:     cd $RELEASEDIR
                    366:
1.20      andrew    367:     if [ ! -e $_type ]; then
                    368:         echo $_type File does not exist!
1.17      andrew    369:         return 1
                    370:     fi
1.6       andrew    371:
1.57      andrew    372:     local _nv=`echo $NEW_VER | sed -e 's/\.//'`
1.61      andrew    373:     local _signify=`which signify 2>/dev/null`
1.94      andrew    374:     local _keyfile=/etc/signify/openbsd-${_nv}-base.pub
1.59      andrew    375:     local _b _s
1.57      andrew    376:
                    377:     (
1.58      andrew    378:         for _b in $INSTALL_KERNELS; do echo "($_b)"        ; done
                    379:         for _s in $INSTALLED_SETS;  do echo "($_s$_nv.tgz)"; done
1.57      andrew    380:     ) > index
1.94      andrew    381:
1.59      andrew    382:
                    383:     if [ -n "$_signify" -a "$_type" != "${_type%.sig}" ]; then
                    384:         echo "===> Checking signature";
                    385:         if [ ! -e $_keyfile ]; then
                    386:             echo "key [$_keyfile] does not exist, cannot check $_type" >&2
                    387:             return 2
                    388:         fi
1.67      andrew    389:         signify -V -e -p $_keyfile -x $_type -m - | grep -f index | sha256 -c -
1.59      andrew    390:     else
1.73      andrew    391:        grep -f index $_type | sha256 -c
1.59      andrew    392:     fi
1.2       andrew    393:
                    394:     if [ $? -ne 0 ]; then
1.20      andrew    395:         echo ERROR: $_type does not match! >&2
1.12      andrew    396:         return 1
1.2       andrew    397:     fi
                    398: }
                    399:
1.17      andrew    400: check_sets() {
1.54      andrew    401:     echo '==> CHECKING SETS'
1.17      andrew    402:     cd $RELEASEDIR
                    403:
1.18      andrew    404:     local _missing_sets
1.17      andrew    405:     local _v=$FILE_VER
                    406:
1.104     andrew    407:     mount_boot_device
1.39      andrew    408:     for _n in $INSTALL_KERNELS; do
                    409:         local _o=$_n
1.104     andrew    410:         [ X"bsd" == X"${_o}" -a -e ${KERNEL_ROOT}bsd.sp ] && _o=bsd.sp
                    411:         if [ -e ${KERNEL_ROOT}${_o} -a ! -e ./${_n} ]; then
                    412:             echo ${_o} does not exist on $BOOT_DEVICE
1.39      andrew    413:             _missing_sets=1
1.17      andrew    414:         fi
1.39      andrew    415:
1.104     andrew    416:         if [ X"${BOOT_KERNEL}" == X"${_o}" -a -e ./${_n} ]; then
1.39      andrew    417:             NEW_KERNEL_VERSION=`kernel_file_version ./${_n}`
1.17      andrew    418:         fi
                    419:     done
1.104     andrew    420:     umount_boot_device
1.17      andrew    421:
1.39      andrew    422:     if [ X"$NEW_KERNEL_VERSION" == X"" ]; then
                    423:         echo Missing replacement for boot kernel $BOOT_KERNEL >&2
                    424:         _missing_sets=1
                    425:     fi
                    426:
1.17      andrew    427:     for _s in $INSTALLED_SETS; do
1.71      andrew    428:         [ "$_v" -ge "57" -a "$_s" != "${_s%etc}" ] && continue
1.19      andrew    429:         local _file=${_s}${_v}.tgz
                    430:         if [ ${_s} == sendmail-smtp_auth ]; then
                    431:             _file=${_s}.gz
                    432:         fi
                    433:         if [ ! -e ./${_file} ]; then
                    434:             echo ${_file} does not exist
1.18      andrew    435:             _missing_sets=1
1.17      andrew    436:         fi
                    437:     done
1.18      andrew    438:
                    439:     if [ X"" == X"${_missing_sets}" ]; then
1.85      andrew    440:         echo 'All OK'
1.18      andrew    441:     fi
1.17      andrew    442:
1.20      andrew    443:     local _type
                    444:     for _type in $CHECKSUM_TYPES; do
1.74      andrew    445:        [ -n "$NO_SIGNIFY" -a "$_type" != "${_type%.sig}" ] && continue
1.20      andrew    446:         if [ -e $_type ]; then
1.59      andrew    447:             check_sum $_type && break
1.62      andrew    448:             [ -z "$IGNORE_CHECKSUM_ERROR" ] && exit 1
1.20      andrew    449:         fi
                    450:     done
1.59      andrew    451:
                    452:     return 0
1.17      andrew    453: }
                    454:
                    455:
1.30      andrew    456: install_kernels() {
1.110     andrew    457:     local _d="$1"
1.97      andrew    458:     local boot_mount
                    459:     local mount_is_msdos
                    460:
1.110     andrew    461:     if [ "$_d" ]; then
                    462:       _d=$( readlink -nf "$_d" )
                    463:     else
1.101     andrew    464:         mount_boot_device
1.97      andrew    465:
1.111     andrew    466:        if [ "$KERNEL_ROOT" != "/" ]; then
1.99      andrew    467:                local _ik="$INSTALL_KERNELS"
1.104     andrew    468:                INSTALL_KERNELS="$BOOT_KERNEL bsd.rd"
1.97      andrew    469:
1.101     andrew    470:                install_kernels $KERNEL_ROOT
1.99      andrew    471:
                    472:                INSTALL_KERNELS="$_ik"
1.97      andrew    473:        fi
                    474:
1.99      andrew    475:         umount_boot_device
                    476:
1.111     andrew    477:         install_kernels /
1.97      andrew    478:         return
                    479:     fi
                    480:
                    481:     echo "==> INSTALLING KERNEL to $_d"
1.2       andrew    482:
                    483:     if [ X"" == X"$RELEASEDIR" ]; then
1.5       andrew    484:         echo ERROR: no source for new kernels! >&2
1.2       andrew    485:         exit 1
                    486:     fi
                    487:
1.111     andrew    488:     [ $_d != / ] && _d=${_d%/}/
1.100     andrew    489:     [ $_d != / ] && mount | grep -q " on ${_d%/} .* msdos" && mount_is_msdos=1
1.97      andrew    490:
1.114     andrew    491:     if [ "$EFI_BOOT" -a -d /mnt/efi/boot ]; then
1.117     andrew    492:        echo "Copying $EFI_BOOT to /mnt/efi/boot/"
1.115     andrew    493:        ( cd /mnt/efi/boot \
1.116     andrew    494:          && cp "$RELEASEDIR/$EFI_BOOT" "n$EFI_BOOT" \
1.115     andrew    495:          && mv "n$EFI_BOOT" "$EFI_BOOT"
                    496:        )
1.114     andrew    497:     fi
                    498:
1.46      andrew    499:     if [ X"$BOOT_KERNEL_VERSION" != X"$NEW_KERNEL_VERSION" ]; then
1.118     andrew    500:         echo "===> Backing up ${_d}$BOOTED_KERNEL to ${_d}obsd"
1.97      andrew    501:         if [ $mount_is_msdos ]; then
1.118     andrew    502:             cp ${_d}$BOOTED_KERNEL ${_d}obsd
1.97      andrew    503:         else
1.118     andrew    504:             ln -f ${_d}$BOOTED_KERNEL ${_d}obsd
1.97      andrew    505:         fi
1.46      andrew    506:         if [ $? -ne 0 ]; then
                    507:             echo "Error copying old kernel!" >&2
                    508:             exit 1
                    509:         fi
1.2       andrew    510:     fi
                    511:
1.39      andrew    512:     cd $RELEASEDIR
1.23      andrew    513:
1.39      andrew    514:     for _b in $INSTALL_KERNELS; do
1.97      andrew    515:         rm -f ${_d}nbsd
1.39      andrew    516:         local _bd=$_b
                    517:         [ X"${_b}" == X"bsd" ] && _bd="bsd.sp"
1.2       andrew    518:
1.39      andrew    519:         local _is_boot=""
1.97      andrew    520:         [ X"$BOOT_KERNEL" == X"${_d}${_bd}" ] && _is_boot="# boot kernel"
1.94      andrew    521:
1.97      andrew    522:         echo "Copying $_b to ${_d}$_bd $_is_boot"
                    523:         cp ${_b} ${_d}nbsd && mv ${_d}nbsd ${_d}${_bd}
1.2       andrew    524:         if [ $? -ne 0 ]; then
1.39      andrew    525:             echo ERROR: Could not copy new $_bd kernel! >&2
1.2       andrew    526:             exit 1
                    527:         fi
1.39      andrew    528:     done
                    529:
                    530:     cd $OLDPWD
1.23      andrew    531:
1.97      andrew    532:     if [ ! -h ${_d}bsd ]; then
                    533:         cd ${_d}
1.39      andrew    534:         for _b in $BOOT_KERNELS; do
                    535:             [ X"$_b" == X"bsd" ] && _b="bsd.sp"
                    536:             if [ -e $_b ]; then
1.97      andrew    537:                 if [ "$mount_is_msdos" ]; then
                    538:                     echo "===> Moving $_b ${_d}bsd (MSDOS)"
                    539:                     mv -f ${_b} bsd
                    540:                 else
                    541:                     echo "===> symlinking $_b to ${_d}bsd"
                    542:                     ln -sf $_b bsd
1.39      andrew    543:                 fi
                    544:                 break
                    545:             fi
                    546:         done
1.97      andrew    547:         cd $OLDPWD
1.2       andrew    548:     fi
1.119     andrew    549:
                    550:     echo "===> Updating /var/db/kernel.SHA256"
                    551:     sha256 -h /var/db/kernel.SHA256 ${_d}/bsd
1.2       andrew    552: }
                    553:
                    554: install_sets() {
1.54      andrew    555:     echo '==> INSTALLING SETS'
1.2       andrew    556:
                    557:     if [ X"" == X"$RELEASEDIR" ]; then
1.5       andrew    558:         echo ERROR: no source for sets! >&2
1.2       andrew    559:         exit 1
                    560:     else
                    561:         cd $RELEASEDIR
                    562:     fi
                    563:
1.5       andrew    564:     local _v=$FILE_VER
                    565:
1.21      andrew    566:     local _sets=`ls *${_v}.tgz | grep -v ^base `
                    567:     for _f in ${_sets} base${_v}.tgz; do
1.3       andrew    568:         _path=$DESTDIR
                    569:         if [ X"etc${_v}.tgz"  == X"$_f" \
                    570:             -o X"xetc${_v}.tgz" == X"$_f" ]; then
1.21      andrew    571:             [ X"" != X"$SYSMERGE" ] && continue
1.2       andrew    572:             _path=/var/tmp/temproot
                    573:         fi
                    574:
1.85      andrew    575:         echo "Extracting $_f to $_path"
1.65      andrew    576:         mkdir -p $_path
                    577:         tar -C $_path -xzphf ${RELEASEDIR}/${_f}
1.2       andrew    578:         if [ $? -ne 0 ]; then
1.5       andrew    579:             echo ERROR: Could not extract ${_f}! >&2
1.2       andrew    580:             exit 1
                    581:         fi
                    582:     done
                    583:
1.54      andrew    584:     echo '===> Extracted all sets.'
1.51      andrew    585: }
1.19      andrew    586:
1.51      andrew    587: install_sendmail_smtp_auth() {
1.19      andrew    588:     if [ -e ${RELEASEDIR}/sendmail-smtp_auth.gz ]; then
                    589:         gzcat ${RELEASEDIR}/sendmail-smtp_auth.gz > \
                    590:             ${RELEASEDIR}/sendmail-smtp_auth
                    591:     fi
                    592:     if [ -e ${RELEASEDIR}/sendmail-smtp_auth ]; then
1.21      andrew    593:         if ! pkg_info -qe 'cyrus-sasl-*'; then
1.65      andrew    594:             pkg_add -i cyrus-sasl
1.21      andrew    595:         fi
                    596:
1.65      andrew    597:         install -o root -g smmsp -m 2555 \
1.19      andrew    598:             ${RELEASEDIR}/sendmail-smtp_auth \
1.21      andrew    599:             /usr/libexec/sendmail/sendmail
1.19      andrew    600:
1.54      andrew    601:         echo '===> Installed sendmail with smtp_auth'
1.19      andrew    602:     fi
1.2       andrew    603: }
                    604:
                    605: update_etc() {
1.54      andrew    606:     echo '==> UPDATING ETC'
1.10      andrew    607:     if [ ! -e $SYSMERGE ]; then
1.47      andrew    608:         echo "ERROR: Can't find sysmerge!" >&2
                    609:         exit 1;
1.10      andrew    610:     fi
                    611:
1.68      andrew    612:     local _v=$FILE_VER
                    613:     local _args=""
                    614:
1.80      andrew    615:     if [ ! -e /var/sysmerge/etc.tgz ]; then
1.68      andrew    616:         if [ X"" == X"$RELEASEDIR" ]; then
                    617:             echo "ERROR: no source for etc!" >&2
                    618:             exit 1
                    619:         fi
1.2       andrew    620:
1.68      andrew    621:         cd $RELEASEDIR
1.5       andrew    622:
1.68      andrew    623:         if [ -e etc${_v}.tgz ]; then
                    624:             _args="$_args -s ${RELEASEDIR}/etc${_v}.tgz"
                    625:         fi
                    626:         if [ -e xetc${_v}.tgz ]; then
                    627:             _args="$_args -x ${RELEASEDIR}/xetc${_v}.tgz"
                    628:         fi
1.94      andrew    629:         if [ X"" == X"$_args" ]; then
1.68      andrew    630:             echo ERROR: No upgrade sets found! >&2
                    631:             exit 1
                    632:         fi
1.47      andrew    633:     fi
1.68      andrew    634:
                    635:     echo '==> RUNNING SYSMERGE'
                    636:     $SYSMERGE $_args
1.2       andrew    637:
1.47      andrew    638:     cd $OLDPWD
1.2       andrew    639: }
1.14      andrew    640:
1.20      andrew    641:
1.65      andrew    642: if [ $(id -u) != 0 ]; then
                    643:     echo 'ERROR: need root privileges to run this script' >&2
                    644:     exit 1
                    645: fi
                    646:
1.14      andrew    647: if [ -e /etc/update_openbsd.conf ]; then
                    648:     . /etc/update_openbsd.conf
                    649: fi
                    650:
                    651: if [ -e ${HOME}/.update_openbsdrc ]; then
                    652:     . ${HOME}/.update_openbsdrc
                    653: fi
                    654:
1.108     andrew    655: MIRROR=${MIRROR:=http://cdn.openbsd.org/pub/OpenBSD}
1.14      andrew    656: FTP_CMD=${FTP_CMD:=ftp -V}
                    657:
                    658: DESTDIR=${DESTDIR:=/}
                    659: SYSMERGE=${SYSMERGE:=/usr/sbin/sysmerge}
                    660: FORCE_DIR=${FORCE_DIR:=No}
1.79      andrew    661:
1.84      andrew    662: export PKG_PATH TRUSTED_PKG_PATH
                    663:
1.79      andrew    664: set_version
1.91      andrew    665:
1.95      andrew    666: TRUSTED_PKG_PATH=${TRUSTED_PKG_PATH:=/usr/ports/packages/`machine -a`/all}
                    667: if [ "$FORCE_DIR" = "No" ]; then
                    668:        PKG_PATH=${PKG_PATH:=${MIRROR}/$NEW_VER/packages/`machine -a`}
                    669: else
                    670:        PKG_PATH=${PKG_PATH:=${MIRROR}/$FORCE_DIR/packages/`machine -a`}
                    671: fi
1.14      andrew    672:
                    673: INSTALLED_SETS=${INSTALLED_SETS:=`installed_sets`}
1.2       andrew    674:
1.59      andrew    675: CHECKSUM_TYPES=${CHECKSUM_TYPES:=SHA256.sig SHA256}
1.20      andrew    676:
1.12      andrew    677: local _error=$?
1.2       andrew    678:
                    679: echo
                    680: echo "-= update_openbsd - helper script to update OpenBSD =-"
                    681: echo "------------------------------------------------------"
                    682: echo
1.84      andrew    683: echo "        SYSMERGE: $SYSMERGE"
1.88      andrew    684: echo "          MIRROR: $FTP"
1.84      andrew    685: echo "        PKG_PATH: $PKG_PATH"
                    686: echo "TRUSTED_PKG_PATH: $TRUSTED_PKG_PATH"
                    687: echo "      RELEASEDIR: $RELEASEDIR"
                    688: echo "         DESTDIR: $DESTDIR"
1.98      andrew    689: echo "     BOOT_DEVICE: $BOOT_DEVICE"
1.114     andrew    690: [ "$EFI_BOOT" ] && echo "        EFI_BOOT: $EFI_BOOT"
1.84      andrew    691: echo "     BOOT_KERNEL: $BOOT_KERNEL"
                    692: echo " INSTALL_KERNELS: $INSTALL_KERNELS"
                    693: echo "  INSTALLED_SETS: $INSTALLED_SETS"
1.8       andrew    694: echo
1.84      andrew    695: echo "         CUR_VER: $CUR_VER"
                    696: echo "         NEW_VER: $NEW_VER"
                    697: #echo "        FILE_VER: $FILE_VER"
1.2       andrew    698: echo
1.70      andrew    699:
1.104     andrew    700: mount_boot_device
1.113     andrew    701: l=$KERNEL_ROOT
                    702: [ "$l" = / ] || l="$BOOT_DEVICE:"
1.70      andrew    703: for k in $INSTALL_KERNELS; do
1.104     andrew    704:     if [ -e $KERNEL_ROOT$k ]; then
1.113     andrew    705:         echo "Existing $l$k"
1.104     andrew    706:         kernel_file_version $KERNEL_ROOT$k
1.70      andrew    707:     fi
                    708: done
1.104     andrew    709: umount_boot_device
1.12      andrew    710:
                    711: if [ ${_error} -ne 0 ]; then
                    712:        exit ${_error}
                    713: fi
1.2       andrew    714:
1.17      andrew    715: if [ X"" != X"${FTP}" ]; then
1.20      andrew    716:     get_sets
1.17      andrew    717: fi
                    718:
                    719: check_sets || exit
1.39      andrew    720:
1.54      andrew    721: echo "===> Last booted:\n$BOOTED_KERNEL_VERSION"
1.39      andrew    722: if [ X"$BOOT_KERNEL_VERSION" != X"$BOOTED_KERNEL_VERSION" \
                    723:   -a X"$BOOT_KERNEL_VERSION" != X"$NEW_KERNEL_VERSION" ]; then
1.118     andrew    724:     echo "Next boot $BOOTED_KERNEL (unless replaced):\n$BOOT_KERNEL_VERSION"
1.39      andrew    725: fi
                    726: if [ -n "$NEW_KERNEL_VERSION" ]; then
1.54      andrew    727:     echo "===> New $BOOT_KERNEL:\n$NEW_KERNEL_VERSION";
1.39      andrew    728: else
                    729:     echo "\n!!! WARNING: Will not replace boot kernel $BOOT_KERNEL! !!!\n" >&2
                    730:     echo "ctrl+C to cancel, enter to continue anyway" >&2
1.44      andrew    731:     local _temp
                    732:     read _temp
1.53      andrew    733:     NEW_KERNEL_VERSION=$BOOT_KERNEL_VERSION
1.44      andrew    734: fi
                    735:
1.66      andrew    736: if [ X"$NEW_KERNEL_VERSION" != X"$BOOTED_KERNEL_VERSION" ]; then
1.44      andrew    737:     echo >&2
1.66      andrew    738:     echo "!!!  You are upgrading the OpenBSD kernel.        !!!" >&2
                    739:     echo "!!!  You will be given the opportunity to reboot  !!!" >&2
1.94      andrew    740:     echo "!!!  at the end of the proces but it is safer to  !!!" >&2
1.66      andrew    741:     echo "!!!  have a separate root shell open.             !!!" >&2
                    742:     echo "!!!  It is needed in order to run /sbin/oreboot.  !!!" >&2
1.78      andrew    743:     echo "!!!  doas MAY NOT WORK after sets are extracted.  !!!" >&2
1.44      andrew    744:     echo >&2
1.66      andrew    745:     echo "enter to continue, ctrl+C to cancel" >&2
1.39      andrew    746:     local _temp
                    747:     read _temp
1.2       andrew    748:
1.66      andrew    749:     if [ ! -e /sbin/oreboot ]; then
                    750:         cp /sbin/reboot /sbin/oreboot
                    751:         if [ $? -ne 0 ]; then
                    752:             echo "Error copying old reboot command!" >&2
                    753:             exit 1
                    754:         fi
                    755:         echo "/sbin/reboot copied to /sbin/oreboot"
1.50      andrew    756:     fi
1.119     andrew    757: fi
                    758:
                    759: if [ $( ls -1 /usr/share/relink/ 2>/dev/null | wc -l ) -gt 0 ]; then
                    760:     echo "==> REMOVING /usr/share/relink/*"
                    761:     rm -rf /usr/share/relink/*
1.2       andrew    762: fi
                    763:
1.30      andrew    764: install_kernels
1.21      andrew    765: install_sets
1.2       andrew    766:
1.53      andrew    767: if [ X"$NEW_KERNEL_VERSION" == X"$BOOTED_KERNEL_VERSION" ]; then
1.51      andrew    768:     install_sendmail_smtp_auth
                    769:
1.21      andrew    770:     if [ -e /sbin/oreboot ]; then
                    771:         echo Removing /sbin/oreboot
1.69      andrew    772:         rm -f /sbin/oreboot
1.21      andrew    773:     fi
1.2       andrew    774:     update_etc
                    775:
1.81      andrew    776:     OPENUP=$( which openup 2>/dev/null )
1.76      andrew    777:     if [ -n "$OPENUP" ]; then
                    778:         echo "==> UPDATING WITH $OPENUP"
                    779:         $OPENUP
                    780:     else
                    781:         echo '==> UPDATING PACKAGES'
1.86      andrew    782:         pkg_add -u
1.76      andrew    783:     fi
1.72      andrew    784:
                    785:     echo '==> UPDATING FIRMWARE'
                    786:     fw_update
1.2       andrew    787:
                    788: else
1.83      andrew    789:     [ -e /etc/rc.sysmerge ] && grep -q $SYSMERGE /etc/rc.sysmerge ||
1.82      andrew    790:         echo "$SYSMERGE -b" >>/etc/rc.sysmerge &&
                    791:         echo "==> RUNNING $SYSMERGE -b ON REBOOT"
                    792:
1.94      andrew    793:     echo Instructions for updating to the new version available from
1.36      andrew    794:     if [ X"snapshots" == X"$FORCE_DIR" ]; then
1.30      andrew    795:         echo "  http://www.openbsd.org/faq/current.html"
                    796:     else
                    797:         echo "  http://www.openbsd.org/faq/upgrade${FILE_VER}.html"
                    798:     fi
1.2       andrew    799: fi
                    800:
1.66      andrew    801: echo Update complete. enter to reboot, ctrl+C to cancel
1.65      andrew    802: read _temp
1.22      andrew    803: if [ -e /sbin/oreboot ]; then
1.66      andrew    804:     echo using /sbin/oreboot
1.65      andrew    805:     /sbin/oreboot
                    806: else
                    807:     /sbin/reboot
1.22      andrew    808: fi

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