Edit

IABSD.fr/src/libexec/reorder_kernel/reorder_kernel.sh

Branch :

  • Show log

    Commit

  • Author : kn
    Date : 2022-11-07 15:55:56
    Hash : f29e23ab
    Message : Use variable and shorter logic for NFS check No need to hardcode a parent path if we can reuse an existing variable for the specific path that is in being used. Negate the file system type in df(1) so the `|| exit 1' can be dropped in favour of the errexit option, as is done for everything else in there. Clarify the comment how this is intentionally NOT logged, i.e. the test happens before the error trap/syslog/logfile handling. OK millert

  • libexec/reorder_kernel/reorder_kernel.sh
  • #!/bin/ksh
    #
    # $OpenBSD: reorder_kernel.sh,v 1.13 2022/11/07 15:55:56 kn 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
    
    export PATH=/usr/bin:/bin:/usr/sbin:/sbin
    
    KERNEL=$(sysctl -n kern.osversion)
    KERNEL=${KERNEL%#*}
    KERNEL_DIR=/usr/share/relink/kernel
    LOGFILE=$KERNEL_DIR/$KERNEL/relink.log
    PROGNAME=${0##*/}
    SHA256=/var/db/kernel.SHA256
    
    # Silently skip if on a NFS mounted filesystem.
    df -t nonfs $KERNEL_DIR >/dev/null 2>&1
    
    # Install trap handlers to inform about success or failure via syslog.
    ERRMSG='failed'
    trap 'trap - EXIT; logger -st $PROGNAME "$ERRMSG" >/dev/console 2>&1' ERR
    trap 'logger -t $PROGNAME "kernel relinking done"' EXIT
    
    # Create kernel compile dir and redirect stdout/stderr to a logfile.
    mkdir -m 700 -p $KERNEL_DIR/$KERNEL
    exec 1>$LOGFILE
    exec 2>&1
    
    ERRMSG="failed -- see $LOGFILE"
    
    if [[ -f $KERNEL_DIR.tgz ]]; then
    	rm -rf $KERNEL_DIR/$KERNEL/*
    	# The directory containing the logfile was just deleted, redirect
    	# stdout/stderr again to a new logfile.
    	exec 1>$LOGFILE
    	exec 2>&1
    	tar -C $KERNEL_DIR -xzf $KERNEL_DIR.tgz $KERNEL
    	rm -f $KERNEL_DIR.tgz
    fi
    
    if ! sha256 -C $SHA256 /bsd; then
    	cat <<__EOF
    
    Failed to verify /bsd's checksum, therefore a randomly linked kernel (KARL)
    is not being built. KARL can be re-enabled for next boot by issuing as root:
    
    sha256 -h $SHA256 /bsd
    __EOF
    	# Trigger ERR trap
    	false
    fi
    
    cd $KERNEL_DIR/$KERNEL
    make newbsd
    [ -f /etc/bsd.re-config ] && config -e -c /etc/bsd.re-config -f bsd
    make newinstall
    sync
    
    echo "\nKernel has been relinked and is active on next reboot.\n"
    cat $SHA256