diff options
author | Robert Peichaer <rpe@cvs.openbsd.org> | 2017-08-21 21:24:12 +0000 |
---|---|---|
committer | Robert Peichaer <rpe@cvs.openbsd.org> | 2017-08-21 21:24:12 +0000 |
commit | e9d6f86c3468c07e6b1b12c0dd0b46516528e450 (patch) | |
tree | 7cba836626f86722ac738a69df12f88c00543a02 /libexec/reorder_kernel | |
parent | ff4a218bb4eee412ff804eff6aef8a516cdf76dd (diff) |
Move the kernel relinking code from /etc/rc into a seperate script
/usr/libexec/reorder_kernel. Requested by ajacoutot@ to be able to
relink the kernel from within syspatch(8).
OK deraadt@ tb@
Diffstat (limited to 'libexec/reorder_kernel')
-rw-r--r-- | libexec/reorder_kernel/Makefile | 9 | ||||
-rw-r--r-- | libexec/reorder_kernel/reorder_kernel.sh | 58 |
2 files changed, 67 insertions, 0 deletions
diff --git a/libexec/reorder_kernel/Makefile b/libexec/reorder_kernel/Makefile new file mode 100644 index 00000000000..27929b291f0 --- /dev/null +++ b/libexec/reorder_kernel/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1 2017/08/21 21:24:11 rpe Exp $ + +SCRIPT= reorder_kernel.sh + +realinstall: + ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + ${.CURDIR}/${SCRIPT} ${DESTDIR}${BINDIR}/reorder_kernel + +.include <bsd.prog.mk> diff --git a/libexec/reorder_kernel/reorder_kernel.sh b/libexec/reorder_kernel/reorder_kernel.sh new file mode 100644 index 00000000000..62cb8affa1e --- /dev/null +++ b/libexec/reorder_kernel/reorder_kernel.sh @@ -0,0 +1,58 @@ +#!/bin/ksh +# +# $OpenBSD: reorder_kernel.sh,v 1.1 2017/08/21 21:24:11 rpe Exp $ +# +# Copyright (c) 2017 Robert Peichaer <rpe@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +set -o errexit + +# Skip if /usr/share is on a nfs mounted filesystem. +DISK_DEV=$(df /usr/share | sed '1d;s/ .*//') +[[ $(mount | grep "^$DISKDEV") == *" type nfs "* ]] && exit 1 + +COMPILE_DIR=/usr/share/compile +KERNEL=$(sysctl -n kern.osversion) +KERNEL=${KERNEL%#*} +LOGFILE=$COMPILE_DIR/$KERNEL/relink.log +PROGNAME=${0##*/} +SHA256=/var/db/kernel.SHA256 + +# Create kernel compile dir and redirect stdout/stderr to a logfile. +mkdir -m 700 -p $COMPILE_DIR/$KERNEL +exec 1>$LOGFILE +exec 2>&1 + +# Install trap handlers to inform about success or failure via syslog. +trap 'trap - EXIT; logger -st $PROGNAME \ + "kernel relinking failed; see $LOGFILE" >>/dev/console 2>&1' ERR +trap 'logger -t $PROGNAME "kernel relinking done"' EXIT + +if [[ -f $COMPILE_DIR.tgz ]]; then + rm -rf $COMPILE_DIR/$KERNEL/* + # The directory containing the logfile was just deleted, redirect + # stdout again to a new logfile. + exec 1>$LOGFILE + tar -C $COMPILE_DIR -xzf $COMPILE_DIR.tgz $KERNEL + rm -f $COMPILE_DIR.tgz +fi + +sha256 -C $SHA256 /bsd + +cd $COMPILE_DIR/$KERNEL +make newbsd +make newinstall + +echo "\nKernel has been relinked and is active on next reboot.\n" +cat $SHA256 |