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

Annotation of openbsd/update_openbsd/update_openbsd, Revision 1.98

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

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