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

Annotation of openbsd/update_openbsd/update_openbsd, Revision 1.71

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

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