Annotation of openbsd/update_openbsd/update_openbsd, Revision 1.38
1.1 andrew 1: #!/bin/sh
1.38 ! andrew 2: # $AFresh1: update_openbsd,v 1.37 2010/06/17 22:39:09 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:
1.34 andrew 27: sendmail -d0.1 --badoption </dev/null 2>/dev/null | grep -q SASL
1.19 andrew 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.23 andrew 194: follow_symlink () {
195: local _file=$1
1.33 andrew 196: # This could go circular, but I dunno how to fix that.
197: if [ -h $_file ]; then
198: follow_symlink $( file $_file |
199: grep 'symbolic link' |
200: sed -e s/^.*\\\`// -e s/\\\'\$// )
1.23 andrew 201: else
1.33 andrew 202: echo $_file
1.23 andrew 203: fi
204: }
205:
1.20 andrew 206: check_sum () {
207: local _type=$1
208: echo "### CHECKING $_type SUMS ###"
1.17 andrew 209: cd $RELEASEDIR
210:
1.20 andrew 211: if [ ! -e $_type ]; then
212: echo $_type File does not exist!
1.17 andrew 213: return 1
214: fi
1.6 andrew 215:
1.19 andrew 216: ls bsd* *gz | sed -e 's/\(.*\)/(\1)/' > index
1.20 andrew 217: grep -f index $_type | sum -c
1.2 andrew 218:
219: if [ $? -ne 0 ]; then
1.20 andrew 220: echo ERROR: $_type does not match! >&2
1.12 andrew 221: return 1
1.2 andrew 222: fi
223: }
224:
1.17 andrew 225: check_sets() {
226: echo '### CHECKING SETS ###'
227: cd $RELEASEDIR
228:
1.18 andrew 229: local _missing_sets
1.17 andrew 230: local _v=$FILE_VER
231:
232: for _b in `echo /bsd* bsd bsd.mp bsd.rd | sort -u`; do
233: _b=${_b#/}
234: local _n=$_b
235: if [ X"bsd.sp" == X"${_n}" ]; then
236: _n=bsd
237: fi
238: if [ -e /${_b} -a ! -e ./${_n} ]; then
239: echo ${_n} does not exist
1.18 andrew 240: _missing_sets=1
1.17 andrew 241: fi
242: done
243:
244: for _s in $INSTALLED_SETS; do
1.19 andrew 245: local _file=${_s}${_v}.tgz
246: if [ ${_s} == sendmail-smtp_auth ]; then
247: _file=${_s}.gz
248: fi
249: if [ ! -e ./${_file} ]; then
250: echo ${_file} does not exist
1.18 andrew 251: _missing_sets=1
1.17 andrew 252: fi
253: done
1.18 andrew 254:
255: if [ X"" == X"${_missing_sets}" ]; then
256: echo All OK
257: fi
1.17 andrew 258:
1.20 andrew 259: local _type
260: for _type in $CHECKSUM_TYPES; do
261: if [ -e $_type ]; then
262: check_sum $_type
263: fi
264: done
1.17 andrew 265: }
266:
267:
1.30 andrew 268: install_kernels() {
1.5 andrew 269: echo '### INSTALLING KERNEL ###'
1.3 andrew 270: if [ X"$USER" != X"root" -a X"$SUDO" == X"" ]; then
1.2 andrew 271: echo ${0##*/} must be run as root or SUDO must be set! >&2
272: exit 1
273: fi
274:
275: if [ X"" == X"$RELEASEDIR" ]; then
1.5 andrew 276: echo ERROR: no source for new kernels! >&2
1.2 andrew 277: exit 1
278: else
279: cd $RELEASEDIR
280: fi
281:
282: if [ ! -e bsd ]; then
1.5 andrew 283: echo ERROR: new bsd kernel does not exist! >&2
1.2 andrew 284: exit 1
285: fi
286:
287: if [ -e /bsd.mp -a ! -e bsd.mp ]; then
1.5 andrew 288: echo ERROR: new bsd.mp kernel does not exist! >&2
1.2 andrew 289: exit 1
290: fi
291:
292: if [ ! -e bsd.rd ]; then
1.5 andrew 293: echo ERROR: new bsd.rd kernel does not exist! >&2
1.2 andrew 294: exit 1
295: fi
296:
1.5 andrew 297: local _v=$FILE_VER
1.2 andrew 298:
1.3 andrew 299: $SUDO rm -f /obsd
300: $SUDO ln /bsd /obsd
1.2 andrew 301: if [ $? -ne 0 ]; then
1.21 andrew 302: echo "Error copying old kernel!" >&2
1.2 andrew 303: exit 1
304: fi
305:
1.23 andrew 306: local _true_bsd=`follow_symlink /bsd`
1.29 andrew 307: _true_bsd=${_true_bsd#/}
1.23 andrew 308: local _installed_new_bsd
309:
1.3 andrew 310: for _b in bsd*; do
311: $SUDO rm -f /nbsd
1.5 andrew 312: if [ X"${_b}" == X"bsd" ]; then
1.2 andrew 313: echo Copying bsd to /bsd.sp
1.3 andrew 314: $SUDO cp bsd /nbsd && $SUDO mv /nbsd /bsd.sp
1.2 andrew 315: if [ $? -ne 0 ]; then
1.5 andrew 316: echo ERROR: Could not copy new SP kernel! >&2
1.2 andrew 317: exit 1
318: fi
1.29 andrew 319: if [ X"${_true_bsd}" == X"bsd.sp" ]; then
1.23 andrew 320: _installed_new_bsd=1
321: fi
1.2 andrew 322: else
1.30 andrew 323: if [ -e "/${_b}" ]; then
1.3 andrew 324: echo Copying $_b to /
325: $SUDO cp ${_b} /nbsd && $SUDO mv /nbsd /${_b}
1.2 andrew 326: if [ $? -ne 0 ]; then
1.5 andrew 327: echo ERROR: Could not copy new $_b kernel! >&2
1.2 andrew 328: exit 1
329: fi
1.29 andrew 330: if [ X"${_true_bsd}" == X"${_b}" ]; then
1.23 andrew 331: _installed_new_bsd=1
332: fi
1.2 andrew 333: fi
334: fi
335: done
336:
337: if [ ! -h /bsd ]; then
1.38 ! andrew 338: cd /
1.2 andrew 339: if [ -e /bsd.mp ]; then
340: echo linking /bsd.mp to /bsd
1.37 andrew 341: $SUDO ln -sf /bsd.mp bsd
1.2 andrew 342: else
343: echo linking /bsd.sp to /bsd
1.37 andrew 344: $SUDO ln -sf /bsd.sp bsd
1.2 andrew 345: fi
346: if [ $? -ne 0 ]; then
1.5 andrew 347: echo ERROR: Could not symlink new kernel! >&2
1.2 andrew 348: exit 1
349: fi
1.38 ! andrew 350: cd $OLDPWD
1.23 andrew 351: fi
352:
353: if [ -z $_installed_new_bsd ]; then
354: echo WARNING: Did not replace $_true_bsd kernel >&2
1.2 andrew 355: fi
356: }
357:
358: install_sets() {
1.5 andrew 359: echo '### INSTALLING SETS ###'
1.3 andrew 360: if [ X"$USER" != X"root" -a X"$SUDO" == X"" ]; then
1.2 andrew 361: echo ${0##*/} must be run as root or SUDO must be set! >&2
362: exit 1
363: fi
364:
365: if [ X"" == X"$RELEASEDIR" ]; then
1.5 andrew 366: echo ERROR: no source for sets! >&2
1.2 andrew 367: exit 1
368: else
369: cd $RELEASEDIR
370: fi
371:
1.5 andrew 372: local _v=$FILE_VER
373:
1.21 andrew 374: if [ $CUR_VER != $NEW_VER -a ! -e /sbin/oreboot ]; then
375: $SUDO cp /sbin/reboot /sbin/oreboot
376: if [ $? -ne 0 ]; then
377: echo "Error copying old reboot command!" >&2
378: exit 1
379: fi
380: echo "/sbin/reboot copied to /sbin/oreboot"
381: fi
382:
383: local _sets=`ls *${_v}.tgz | grep -v ^base `
384: for _f in ${_sets} base${_v}.tgz; do
1.3 andrew 385: _path=$DESTDIR
386: if [ X"etc${_v}.tgz" == X"$_f" \
387: -o X"xetc${_v}.tgz" == X"$_f" ]; then
1.21 andrew 388: [ X"" != X"$SYSMERGE" ] && continue
1.2 andrew 389: _path=/var/tmp/temproot
390: fi
391:
1.3 andrew 392: echo Extracting $_f to $_path
393: $SUDO mkdir -p $_path
394: $SUDO tar -C $_path -xzphf ${RELEASEDIR}/${_f}
1.2 andrew 395: if [ $? -ne 0 ]; then
1.5 andrew 396: echo ERROR: Could not extract ${_f}! >&2
1.2 andrew 397: exit 1
398: fi
399: done
400:
401: echo Extracted all sets.
1.19 andrew 402:
403: if [ -e ${RELEASEDIR}/sendmail-smtp_auth.gz ]; then
404: gzcat ${RELEASEDIR}/sendmail-smtp_auth.gz > \
405: ${RELEASEDIR}/sendmail-smtp_auth
406: fi
407: if [ -e ${RELEASEDIR}/sendmail-smtp_auth ]; then
1.21 andrew 408: if ! pkg_info -qe 'cyrus-sasl-*'; then
409: $SUDO pkg_add -i cyrus-sasl
410: fi
411:
412: $SUDO install -o root -g smmsp -m 2555 \
1.19 andrew 413: ${RELEASEDIR}/sendmail-smtp_auth \
1.21 andrew 414: /usr/libexec/sendmail/sendmail
1.19 andrew 415:
416: echo Installed sendmail with smtp_auth
417: fi
1.2 andrew 418: }
419:
420: update_etc() {
1.5 andrew 421: echo '### UPDATING ETC ###'
1.10 andrew 422: if [ ! -e $SYSMERGE ]; then
423: SYSMERGE=
424: fi
425:
1.3 andrew 426: if [ X"" == X"$SYSMERGE" ]; then
1.2 andrew 427: if [ -e /var/tmp/temproot ]; then
428: MERGEMASTER=`which mergemaster`
429:
430: if [ $? != 0 ]; then
1.3 andrew 431: $SUDO pkg_add -i mergemaster
1.5 andrew 432:
1.2 andrew 433: MERGEMASTER=`which mergemaster`
434: if [ $? != 0 ]; then
435: echo ERROR: mergemaster not installed! >&2
436: exit 1
437: fi
438: fi
439:
440: echo '### RUNNING MERGEMASTER ###'
1.3 andrew 441: $SUDO $MERGEMASTER -irv
1.2 andrew 442: else
443: echo "ERROR: no source for etc!" >&2
444: exit 1
445: fi
446: else
447: if [ X"" == X"$RELEASEDIR" ]; then
448: echo "ERROR: no source for etc!" >&2
449: exit 1
450: else
451: cd $RELEASEDIR
452: fi
453:
1.5 andrew 454: local _v=$FILE_VER
1.30 andrew 455: local _args=""
1.5 andrew 456: if [ -e etc${_v}.tgz ]; then
457: _args="$_args -s etc${_v}.tgz"
1.2 andrew 458: fi
1.5 andrew 459: if [ -e xetc${_v}.tgz ]; then
460: _args="$_args -x xetc${_v}.tgz"
1.2 andrew 461: fi
462: if [ X"" == X"$_args" ]; then
463: echo ERROR: No upgrade sets found! >&2
464: else
465: echo '### RUNNING SYSMERGE ###'
1.27 andrew 466: if sysmerge 2>&1 | grep -- -a >/dev/null; then
467: _args="-a $_args"
468: fi
1.3 andrew 469: $SUDO $SYSMERGE $_args
1.2 andrew 470: fi
471: fi
472: }
1.14 andrew 473:
1.20 andrew 474:
1.14 andrew 475: if [ -e /etc/update_openbsd.conf ]; then
476: . /etc/update_openbsd.conf
477: fi
478:
479: if [ -e ${HOME}/.update_openbsdrc ]; then
480: . ${HOME}/.update_openbsdrc
481: fi
482:
1.17 andrew 483: #MIRROR=${MIRROR:=ftp://ftp.openbsd.org/pub/OpenBSD}
1.14 andrew 484: FTP_CMD=${FTP_CMD:=ftp -V}
485: PKG_PATH=${PKG_PATH:=/usr/ports/packages/`machine`/all/:${MIRROR}/`uname -r`/packages/`machine`/}
486:
487: DESTDIR=${DESTDIR:=/}
488: SYSMERGE=${SYSMERGE:=/usr/sbin/sysmerge}
489: FORCE_DIR=${FORCE_DIR:=No}
490:
491: INSTALLED_SETS=${INSTALLED_SETS:=`installed_sets`}
1.2 andrew 492:
1.21 andrew 493: CHECKSUM_TYPES=${CHECKSUM_TYPES:=SHA256 MD5}
1.20 andrew 494:
1.2 andrew 495: set_version
1.12 andrew 496: local _error=$?
1.2 andrew 497:
498: echo
499: echo "-= update_openbsd - helper script to update OpenBSD =-"
500: echo "------------------------------------------------------"
501: echo
1.8 andrew 502: echo " SUDO: $SUDO"
503: echo " SYSMERGE: $SYSMERGE"
504: echo " MIRROR: $MIRROR"
505: echo " RELEASEDIR: $RELEASEDIR"
506: echo " DESTDIR: $DESTDIR"
507: echo "INSTALLED_SETS: $INSTALLED_SETS"
508: echo
509: echo " CUR_VER: $CUR_VER"
510: echo " NEW_VER: $NEW_VER"
511: #echo " FILE_VER: $FILE_VER"
1.2 andrew 512: echo
1.12 andrew 513:
514: if [ ${_error} -ne 0 ]; then
515: exit ${_error}
516: fi
1.2 andrew 517:
1.17 andrew 518: if [ X"" != X"${FTP}" ]; then
1.20 andrew 519: get_sets
1.17 andrew 520: fi
521:
522: check_sets || exit
1.2 andrew 523:
524: if [ X"" != X"$SUDO" ]; then
525: echo Please enter your sudo password if prompted.
526: echo You may be asked for it again later in the process.
527: $SUDO -v
528: fi
529:
1.30 andrew 530: install_kernels
1.21 andrew 531: install_sets
1.2 andrew 532:
1.5 andrew 533: if [ $CUR_VER == $NEW_VER ]; then
1.21 andrew 534: if [ -e /sbin/oreboot ]; then
535: echo Removing /sbin/oreboot
536: $SUDO rm -f /sbin/oreboot
537: fi
1.2 andrew 538: update_etc
539:
540: echo '### UPDATING PACKAGES ###'
541: $SUDO pkg_add -ui -F update -F updatedepends
542:
543: else
544: echo Instructions for updating to the new version available from
1.36 andrew 545: if [ X"snapshots" == X"$FORCE_DIR" ]; then
1.30 andrew 546: echo " http://www.openbsd.org/faq/current.html"
547: else
548: echo " http://www.openbsd.org/faq/upgrade${FILE_VER}.html"
549: fi
1.2 andrew 550: fi
551:
552: echo New kernel installed. Please reboot!
1.22 andrew 553: if [ -e /sbin/oreboot ]; then
554: echo Possibly using /sbin/oreboot
1.31 andrew 555: fi
556:
557: local _send_dmesg=`dirname $0`/send_dmesg
558: if [ -e "$_send_dmesg" ]; then
1.32 andrew 559: if [ -e $RELEASEDIR/.send_dmesg ]; then
1.31 andrew 560: $_send_dmesg
561: rm -f $RELEASEDIR/.send_dmesg
1.32 andrew 562: elif [ X"$CUR_VER" != X"$NEW_VER" ]; then
1.31 andrew 563: touch $RELEASEDIR/.send_dmesg
564: fi
1.22 andrew 565: fi
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>