#!/bin/bash

# sourcing our current rc.conf requires this to be a bash script
. /usr/lib/rc/functions

config(){
    if [[ -e /proc/sys/kernel/dmesg_restrict ]] &&
    (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then
        install -Tm 0600 <( dmesg ) /var/log/dmesg.log
        ck_verbose && substat "dmesg_restrict is enabled"
        ck_verbose && substat "dmesg log can only be read by root"
    else
        install -Tm 0644 <( dmesg ) /var/log/dmesg.log
    fi
}

case "$1" in
    start)
        stat_busy "Saving dmesg log"
        config
        add_daemon dmesg
        stat_done
        ;;
    *)
        echo "usage: $0 {start|stop}"
        exit 1
        ;;
esac
