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