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

Annotation of openbsd/update_openbsd/update_openbsd, Revision 1.21

1.1       andrew      1: #!/bin/sh
1.21    ! andrew      2: # $RedRiver: update_openbsd,v 1.20 2009/04/25 00:14:12 andrew Exp $
1.7       andrew      3:
1.2       andrew      4: installed_sets() {
1.5       andrew      5:     local misc=/usr/share/doc/README
                      6:     local man=/usr/share/man/cat1/intro.0
                      7:     local comp=/usr/bin/cc
                      8:     local game=/usr/games/
                      9:     local xbase=/usr/X11R6/
                     10:     local xetc=/etc/X11/xinit/xinitrc
                     11:     local xfont=/usr/X11R6/lib/X11/fonts
                     12:     local xserv=/usr/X11R6/bin/X
                     13:     local xshare=/usr/X11R6/bin/startx
                     14:
                     15:     local _c _d _e
                     16:     echo -n base
                     17:     echo -n ' etc'
1.3       andrew     18:     for _d in misc man comp game xbase xetc xfont xserv xshare; do
                     19:         eval _e=\$${_d}
                     20:         _c=`ls $_e 2> /dev/null | wc -l`
                     21:         #echo $_c $_d $_e
                     22:         if [ $_c -ne 0 ]; then
1.5       andrew     23:             echo -n " $_d"
1.2       andrew     24:         fi
                     25:     done
1.19      andrew     26:
                     27:     sendmail -d0.1 root < /dev/null | grep -q SASL
                     28:     if [ $? == 0 ]; then
                     29:         echo -n ' sendmail-smtp_auth'
                     30:     fi
1.2       andrew     31: }
1.7       andrew     32:
1.16      andrew     33: version_in() {
1.10      andrew     34:         local _proto=${FTP%%://*}
1.16      andrew     35:         local _file
1.10      andrew     36:
                     37:         if [ X"ftp" == X"${_proto}" ]; then
1.16      andrew     38:             local _list=`echo "ls base*.tgz" | ${FTP_CMD} ${FTP}/`
                     39:             _file=`echo ${_list} | awk '/base[0-9][0-9].tgz/ { print $9 }'`
1.15      andrew     40:
1.10      andrew     41:         elif [ X"http" == X"${_proto}" ]; then
1.16      andrew     42:             local _list=`${FTP_CMD} -V -o - ${FTP}/`
                     43:             _file=`echo ${_list} | awk '/[^x]base[0-9][0-9]*\.tgz/ {
1.15      andrew     44:                     sub("^.*base","base");
                     45:                     sub("\.tgz.*",".tgz");
                     46:                     print $0;
1.16      andrew     47:                 }'`
1.15      andrew     48:
                     49:         elif [ X"scp" == X"${_proto}" ]; then
                     50:             echo SCP is not yet supported >&2
                     51:             return 2
                     52:
1.10      andrew     53:         else
                     54:             echo Unsupported FTP ${FTP} >&2
1.12      andrew     55:             return 2
1.15      andrew     56:
1.10      andrew     57:         fi
1.16      andrew     58:
                     59:         local _v=${_file##*base}
                     60:         _v=${_v%.tgz*}
                     61:         echo $_v
1.10      andrew     62: }
1.2       andrew     63:
                     64: set_version() {
                     65:     CUR_VER=`uname -r`
1.3       andrew     66:     NEW_VER=`dc -e "$CUR_VER 0.1 + p"`
1.5       andrew     67:     FILE_VER=""
                     68:     FTP=""
1.2       andrew     69:
1.5       andrew     70:     local _cv=`echo $CUR_VER | sed -e 's/\.//'`
                     71:     local _nv=`echo $NEW_VER | sed -e 's/\.//'`
1.9       andrew     72:     local _v
1.5       andrew     73:
1.10      andrew     74:     if [ X"No" != X"$FORCE_DIR" -a -d $FORCE_DIR ]; then
1.5       andrew     75:         _dir=$FORCE_DIR
                     76:         if [ -e ${_dir}/base${_nv}.tgz ]; then
                     77:             _v=$_nv
                     78:         elif [ -e ${_dir}/base${_cv}.tgz ]; then
                     79:             NEW_VER=$CUR_VER
                     80:             _v=$_cv
                     81:         fi
1.2       andrew     82:
1.5       andrew     83:     elif [ -d $CUR_VER ]; then
                     84:         _dir=$CUR_VER
1.2       andrew     85:         NEW_VER=$CUR_VER
1.5       andrew     86:         if [ -e ${_dir}/base${_cv}.tgz ]; then
                     87:             _v=$_cv
                     88:         fi
1.2       andrew     89:
1.5       andrew     90:     elif [ -d $NEW_VER ]; then
                     91:         _dir=$NEW_VER
                     92:         if [ -e ${_dir}/base${_nv}.tgz ]; then
                     93:             _v=$_nv
                     94:         fi
1.2       andrew     95:
                     96:     fi
                     97:
1.17      andrew     98:     if [ X"" != X"${MIRROR}" -a X"" == X"${_v}" ]; then
1.10      andrew     99:         if [ X"No" == X"${FORCE_DIR}" ]; then
1.5       andrew    100:             _dir=${NEW_VER}
                    101:         else
                    102:             _dir=${FORCE_DIR}
                    103:         fi
                    104:         FTP=${MIRROR}/${_dir}/`machine`
1.2       andrew    105:
1.16      andrew    106:         _v=`version_in`
1.10      andrew    107:
1.16      andrew    108:         if [ X"" == X"${_v}" ]; then
1.10      andrew    109:             if [ X"No" != X"$FORCE_DIR" ]; then
                    110:                 echo No sets in forced [${FTP}] >&2
1.12      andrew    111:                 return 2
1.10      andrew    112:             fi
                    113:
                    114:             NEW_VER=$CUR_VER
                    115:             _dir=${NEW_VER}
                    116:             FTP=${MIRROR}/${_dir}/`machine`
                    117:
1.16      andrew    118:             _v=`version_in`
1.9       andrew    119:         fi
                    120:
1.10      andrew    121:         if [ X"" == X"${_v}" ]; then
1.16      andrew    122:             echo No sets in [${FTP}] >&2
1.12      andrew    123:             return 2
1.10      andrew    124:         elif [ X"${_cv}" == X"${_v}" ]; then
1.5       andrew    125:             NEW_VER=$CUR_VER
1.9       andrew    126:         elif [ X"${_nv}" == X"${_v}" ]; then
                    127:             NEW_VER=$NEW_VER
1.2       andrew    128:         else
1.10      andrew    129:             echo Invalid version [$_v] >&2
1.12      andrew    130:             return 2
1.2       andrew    131:         fi
                    132:
1.10      andrew    133:         if [ X"No" == X"$FORCE_DIR" ]; then
1.5       andrew    134:             _dir=$NEW_VER
1.2       andrew    135:         fi
                    136:
                    137:     fi
                    138:
1.5       andrew    139:     if [ X"" == X"${_v}" ]; then
                    140:         echo ERROR: Unable to determine file version! >&2
1.12      andrew    141:         return 1
1.2       andrew    142:     fi
                    143:
1.5       andrew    144:     if [ X"" == X"$RELEASEDIR" ]; then
                    145:         RELEASEDIR=`pwd`/$_dir
1.2       andrew    146:     fi
1.9       andrew    147:
1.5       andrew    148:     FILE_VER=$_v
1.17      andrew    149:     if [ X"" != X"${MIRROR}" ]; then
                    150:         FTP=${MIRROR}/${_dir}/`machine`
                    151:     fi
1.2       andrew    152: }
                    153:
                    154: get_sets() {
1.5       andrew    155:     echo '### GETTING SETS ###'
1.2       andrew    156:     if [ X"" == X"$FTP" ]; then
1.5       andrew    157:         echo ERROR: No FTP site set! >&2
1.12      andrew    158:         return 1
1.2       andrew    159:     fi
                    160:
1.5       andrew    161:     mkdir -p ${RELEASEDIR}
                    162:     cd $RELEASEDIR
1.2       andrew    163:
1.5       andrew    164:     local _v=$FILE_VER
1.2       andrew    165:
1.5       andrew    166:     for _b in `echo /bsd* bsd bsd.mp bsd.rd | sort -u`; do
1.2       andrew    167:         if [ -e /${_b} -a ! -e ./${_b} ]; then
1.3       andrew    168:             echo $FTP_CMD ${FTP}/${_b}
                    169:             $FTP_CMD ${FTP}/${_b}
1.2       andrew    170:         fi
                    171:     done
                    172:
1.5       andrew    173:     for _s in $INSTALLED_SETS; do
1.19      andrew    174:         local _file=${_s}${_v}.tgz
                    175:         if [ ${_s} == sendmail-smtp_auth ]; then
                    176:             _file=${_s}.gz
                    177:         fi
                    178:
                    179:         if [ ! -e ./${_file} ]; then
                    180:             echo $FTP_CMD ${FTP}/${_file}
                    181:             $FTP_CMD ${FTP}/${_file}
1.5       andrew    182:         fi
1.2       andrew    183:     done
                    184:
1.20      andrew    185:     local _type
                    186:     for _type in $CHECKSUM_TYPES; do
                    187:         if [ ! -e $_type ]; then
                    188:             echo $FTP_CMD ${FTP}/$_type
                    189:             $FTP_CMD ${FTP}/$_type
                    190:         fi
                    191:     done
1.17      andrew    192: }
                    193:
1.20      andrew    194: check_sum () {
                    195:     local _type=$1
                    196:     echo "### CHECKING $_type SUMS ###"
1.17      andrew    197:     cd $RELEASEDIR
                    198:
1.20      andrew    199:     if [ ! -e $_type ]; then
                    200:         echo $_type File does not exist!
1.17      andrew    201:         return 1
                    202:     fi
1.6       andrew    203:
1.19      andrew    204:     ls bsd* *gz | sed -e 's/\(.*\)/(\1)/' > index
1.20      andrew    205:     grep -f index $_type | sum -c
1.2       andrew    206:
                    207:     if [ $? -ne 0 ]; then
1.20      andrew    208:         echo ERROR: $_type does not match! >&2
1.12      andrew    209:         return 1
1.2       andrew    210:     fi
                    211: }
                    212:
1.17      andrew    213: check_sets() {
                    214:     echo '### CHECKING SETS ###'
                    215:     cd $RELEASEDIR
                    216:
1.18      andrew    217:     local _missing_sets
1.17      andrew    218:     local _v=$FILE_VER
                    219:
                    220:     for _b in `echo /bsd* bsd bsd.mp bsd.rd | sort -u`; do
                    221:        _b=${_b#/}
                    222:         local _n=$_b
                    223:         if [ X"bsd.sp" == X"${_n}" ]; then
                    224:             _n=bsd
                    225:         fi
                    226:         if [ -e /${_b} -a ! -e ./${_n} ]; then
                    227:             echo ${_n} does not exist
1.18      andrew    228:             _missing_sets=1
1.17      andrew    229:         fi
                    230:     done
                    231:
                    232:     for _s in $INSTALLED_SETS; do
1.19      andrew    233:         local _file=${_s}${_v}.tgz
                    234:         if [ ${_s} == sendmail-smtp_auth ]; then
                    235:             _file=${_s}.gz
                    236:         fi
                    237:         if [ ! -e ./${_file} ]; then
                    238:             echo ${_file} does not exist
1.18      andrew    239:             _missing_sets=1
1.17      andrew    240:         fi
                    241:     done
1.18      andrew    242:
                    243:     if [ X"" == X"${_missing_sets}" ]; then
                    244:         echo All OK
                    245:     fi
1.17      andrew    246:
1.20      andrew    247:     local _type
                    248:     for _type in $CHECKSUM_TYPES; do
                    249:         if [ -e $_type ]; then
                    250:             check_sum $_type
                    251:         fi
                    252:     done
1.17      andrew    253: }
                    254:
                    255:
1.2       andrew    256: install_kernel() {
1.5       andrew    257:     echo '### INSTALLING KERNEL ###'
1.3       andrew    258:     if [ X"$USER" != X"root" -a X"$SUDO" == X"" ]; then
1.2       andrew    259:         echo ${0##*/} must be run as root or SUDO must be set! >&2
                    260:         exit 1
                    261:     fi
                    262:
                    263:     if [ X"" == X"$RELEASEDIR" ]; then
1.5       andrew    264:         echo ERROR: no source for new kernels! >&2
1.2       andrew    265:         exit 1
                    266:     else
                    267:         cd $RELEASEDIR
                    268:     fi
                    269:
                    270:     if [ ! -e bsd ]; then
1.5       andrew    271:         echo ERROR: new bsd kernel does not exist! >&2
1.2       andrew    272:         exit 1
                    273:     fi
                    274:
                    275:     if [ -e /bsd.mp -a ! -e bsd.mp ]; then
1.5       andrew    276:         echo ERROR: new bsd.mp kernel does not exist! >&2
1.2       andrew    277:         exit 1
                    278:     fi
                    279:
                    280:     if [ ! -e bsd.rd ]; then
1.5       andrew    281:         echo ERROR: new bsd.rd kernel does not exist! >&2
1.2       andrew    282:         exit 1
                    283:     fi
                    284:
1.5       andrew    285:     local _v=$FILE_VER
1.2       andrew    286:
1.3       andrew    287:     $SUDO rm -f /obsd
                    288:     $SUDO ln /bsd /obsd
1.2       andrew    289:     if [ $? -ne 0 ]; then
1.21    ! andrew    290:         echo "Error copying old kernel!" >&2
1.2       andrew    291:         exit 1
                    292:     fi
                    293:
1.3       andrew    294:     for _b in bsd*; do
                    295:         $SUDO rm -f /nbsd
1.2       andrew    296:
1.5       andrew    297:         if [ X"${_b}" == X"bsd" ]; then
1.2       andrew    298:             echo Copying bsd to /bsd.sp
1.3       andrew    299:             $SUDO cp bsd /nbsd && $SUDO mv /nbsd /bsd.sp
1.2       andrew    300:             if [ $? -ne 0 ]; then
1.5       andrew    301:                 echo ERROR: Could not copy new SP kernel! >&2
1.2       andrew    302:                 exit 1
                    303:             fi
                    304:         else
1.3       andrew    305:             if [ -e /$_b ]; then
                    306:                 echo Copying $_b to /
                    307:                 $SUDO cp ${_b} /nbsd && $SUDO mv /nbsd /${_b}
1.2       andrew    308:                 if [ $? -ne 0 ]; then
1.5       andrew    309:                     echo ERROR: Could not copy new $_b kernel! >&2
1.2       andrew    310:                     exit 1
                    311:                 fi
                    312:             fi
                    313:         fi
                    314:     done
                    315:
                    316:     if [ ! -h /bsd ]; then
                    317:         if [ -e /bsd.mp ]; then
                    318:             echo linking /bsd.mp to /bsd
1.3       andrew    319:             $SUDO ln -sf /bsd.mp /bsd
1.2       andrew    320:         else
                    321:             echo linking /bsd.sp to /bsd
1.3       andrew    322:             $SUDO ln -sf /bsd.sp /bsd
1.2       andrew    323:         fi
                    324:         if [ $? -ne 0 ]; then
1.5       andrew    325:             echo ERROR: Could not symlink new kernel! >&2
1.2       andrew    326:             exit 1
                    327:         fi
                    328:     fi
                    329: }
                    330:
                    331: install_sets() {
1.5       andrew    332:     echo '### INSTALLING SETS ###'
1.3       andrew    333:     if [ X"$USER" != X"root" -a X"$SUDO" == X"" ]; then
1.2       andrew    334:         echo ${0##*/} must be run as root or SUDO must be set! >&2
                    335:         exit 1
                    336:     fi
                    337:
                    338:     if [ X"" == X"$RELEASEDIR" ]; then
1.5       andrew    339:         echo ERROR: no source for sets! >&2
1.2       andrew    340:         exit 1
                    341:     else
                    342:         cd $RELEASEDIR
                    343:     fi
                    344:
1.5       andrew    345:     local _v=$FILE_VER
                    346:
1.21    ! andrew    347:     if [ $CUR_VER != $NEW_VER -a ! -e /sbin/oreboot ]; then
        !           348:         $SUDO cp /sbin/reboot /sbin/oreboot
        !           349:         if [ $? -ne 0 ]; then
        !           350:             echo "Error copying old reboot command!" >&2
        !           351:             exit 1
        !           352:         fi
        !           353:         echo "/sbin/reboot copied to /sbin/oreboot"
        !           354:     fi
        !           355:
        !           356:     local _sets=`ls *${_v}.tgz | grep -v ^base `
        !           357:     for _f in ${_sets} base${_v}.tgz; do
1.3       andrew    358:         _path=$DESTDIR
                    359:         if [ X"etc${_v}.tgz"  == X"$_f" \
                    360:             -o X"xetc${_v}.tgz" == X"$_f" ]; then
1.21    ! andrew    361:             [ X"" != X"$SYSMERGE" ] && continue
1.2       andrew    362:             _path=/var/tmp/temproot
                    363:         fi
                    364:
1.3       andrew    365:         echo Extracting $_f to $_path
                    366:         $SUDO mkdir -p $_path
                    367:         $SUDO tar -C $_path -xzphf ${RELEASEDIR}/${_f}
1.2       andrew    368:         if [ $? -ne 0 ]; then
1.5       andrew    369:             echo ERROR: Could not extract ${_f}! >&2
1.2       andrew    370:             exit 1
                    371:         fi
                    372:     done
                    373:
                    374:     echo Extracted all sets.
1.19      andrew    375:
                    376:     if [ -e ${RELEASEDIR}/sendmail-smtp_auth.gz ]; then
                    377:         gzcat ${RELEASEDIR}/sendmail-smtp_auth.gz > \
                    378:             ${RELEASEDIR}/sendmail-smtp_auth
                    379:     fi
                    380:     if [ -e ${RELEASEDIR}/sendmail-smtp_auth ]; then
1.21    ! andrew    381:         if ! pkg_info -qe 'cyrus-sasl-*'; then
        !           382:             $SUDO pkg_add -i cyrus-sasl
        !           383:         fi
        !           384:
        !           385:         $SUDO install -o root -g smmsp -m 2555 \
1.19      andrew    386:             ${RELEASEDIR}/sendmail-smtp_auth \
1.21    ! andrew    387:             /usr/libexec/sendmail/sendmail
1.19      andrew    388:
                    389:         echo Installed sendmail with smtp_auth
                    390:     fi
1.2       andrew    391: }
                    392:
                    393: update_etc() {
1.5       andrew    394:     echo '### UPDATING ETC ###'
1.10      andrew    395:     if [ ! -e $SYSMERGE ]; then
                    396:         SYSMERGE=
                    397:     fi
                    398:
1.3       andrew    399:     if [ X"" == X"$SYSMERGE" ]; then
1.2       andrew    400:         if [ -e /var/tmp/temproot ]; then
                    401:             MERGEMASTER=`which mergemaster`
                    402:
                    403:             if [ $? != 0 ]; then
1.3       andrew    404:                 $SUDO pkg_add -i mergemaster
1.5       andrew    405:
1.2       andrew    406:                 MERGEMASTER=`which mergemaster`
                    407:                 if [ $? != 0 ]; then
                    408:                     echo ERROR: mergemaster not installed! >&2
                    409:                     exit 1
                    410:                 fi
                    411:             fi
                    412:
                    413:             echo '### RUNNING MERGEMASTER ###'
1.3       andrew    414:             $SUDO $MERGEMASTER -irv
1.2       andrew    415:         else
                    416:             echo "ERROR: no source for etc!" >&2
                    417:             exit 1
                    418:         fi
                    419:     else
                    420:         if [ X"" == X"$RELEASEDIR" ]; then
                    421:             echo "ERROR: no source for etc!" >&2
                    422:             exit 1
                    423:         else
                    424:             cd $RELEASEDIR
                    425:         fi
                    426:
1.5       andrew    427:         local _v=$FILE_VER
                    428:         if [ -e etc${_v}.tgz ]; then
                    429:             _args="$_args -s etc${_v}.tgz"
1.2       andrew    430:         fi
1.5       andrew    431:         if [ -e xetc${_v}.tgz ]; then
                    432:             _args="$_args -x xetc${_v}.tgz"
1.2       andrew    433:         fi
                    434:         if [ X"" == X"$_args" ]; then
                    435:             echo ERROR: No upgrade sets found! >&2
                    436:         else
                    437:             echo '### RUNNING SYSMERGE ###'
                    438:             _args="-a $_args"
1.3       andrew    439:             $SUDO $SYSMERGE $_args
1.2       andrew    440:         fi
                    441:     fi
                    442: }
1.14      andrew    443:
1.20      andrew    444:
1.14      andrew    445: if [ -e /etc/update_openbsd.conf ]; then
                    446:     . /etc/update_openbsd.conf
                    447: fi
                    448:
                    449: if [ -e ${HOME}/.update_openbsdrc ]; then
                    450:     . ${HOME}/.update_openbsdrc
                    451: fi
                    452:
1.17      andrew    453: #MIRROR=${MIRROR:=ftp://ftp.openbsd.org/pub/OpenBSD}
1.14      andrew    454: FTP_CMD=${FTP_CMD:=ftp -V}
                    455: PKG_PATH=${PKG_PATH:=/usr/ports/packages/`machine`/all/:${MIRROR}/`uname -r`/packages/`machine`/}
                    456:
                    457: DESTDIR=${DESTDIR:=/}
                    458: SYSMERGE=${SYSMERGE:=/usr/sbin/sysmerge}
                    459: FORCE_DIR=${FORCE_DIR:=No}
                    460:
                    461: INSTALLED_SETS=${INSTALLED_SETS:=`installed_sets`}
1.2       andrew    462:
1.21    ! andrew    463: CHECKSUM_TYPES=${CHECKSUM_TYPES:=SHA256 MD5}
1.20      andrew    464:
1.2       andrew    465: set_version
1.12      andrew    466: local _error=$?
1.2       andrew    467:
                    468: echo
                    469: echo "-= update_openbsd - helper script to update OpenBSD =-"
                    470: echo "------------------------------------------------------"
                    471: echo
1.8       andrew    472: echo "          SUDO: $SUDO"
                    473: echo "      SYSMERGE: $SYSMERGE"
                    474: echo "        MIRROR: $MIRROR"
                    475: echo "    RELEASEDIR: $RELEASEDIR"
                    476: echo "       DESTDIR: $DESTDIR"
                    477: echo "INSTALLED_SETS: $INSTALLED_SETS"
                    478: echo
                    479: echo "       CUR_VER: $CUR_VER"
                    480: echo "       NEW_VER: $NEW_VER"
                    481: #echo "      FILE_VER: $FILE_VER"
1.2       andrew    482: echo
1.12      andrew    483:
                    484: if [ ${_error} -ne 0 ]; then
                    485:        exit ${_error}
                    486: fi
1.2       andrew    487:
1.17      andrew    488: if [ X"" != X"${FTP}" ]; then
1.20      andrew    489:     get_sets
1.17      andrew    490: fi
                    491:
                    492: check_sets || exit
1.2       andrew    493:
                    494: if [ X"" != X"$SUDO" ]; then
                    495:     echo Please enter your sudo password if prompted.
                    496:     echo You may be asked for it again later in the process.
                    497:     $SUDO -v
                    498: fi
                    499:
                    500: install_kernel
1.21    ! andrew    501: install_sets
1.2       andrew    502:
1.5       andrew    503: if [ $CUR_VER == $NEW_VER ]; then
1.21    ! andrew    504:     if [ -e /sbin/oreboot ]; then
        !           505:         echo Removing /sbin/oreboot
        !           506:         $SUDO rm -f /sbin/oreboot
        !           507:     fi
1.2       andrew    508:     update_etc
                    509:
                    510:     echo '### UPDATING PACKAGES ###'
                    511:     $SUDO pkg_add -ui -F update -F updatedepends
                    512:
                    513: else
                    514:     echo Instructions for updating to the new version available from
                    515:     echo "  http://www.openbsd.org/faq/upgrade${_v}.html"
                    516: fi
                    517:
                    518: echo New kernel installed.  Please reboot!

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