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