#!/bin/sh
#
# $NetBSD: securelevel,v 1.8 2009/12/29 17:06:10 elad Exp $
#

# PROVIDE: securelevel
# REQUIRE: ipnat mountd
# BEFORE:  DAEMON

$_rc_subr_loaded . /etc/rc.subr

name="securelevel"
start_cmd="securelevel_start"
stop_cmd=":"

securelevel_start()
{
	#	if $securelevel is set higher, change it here, else if
	#	it is 0, change it to 1 here, before we start daemons
	#	or login services.
	#
	osecurelevel=$(sysctl -n kern.securelevel 2>&-)
	if [ $? != 0 ]; then
		echo "Can't set securelevel. (kern.securelevel sysctl not present.)"
		exit 1
	fi

	if [ -n "$securelevel" -a "$securelevel" != "$osecurelevel" ]; then
		if [ "$securelevel" -lt "$osecurelevel" ]; then
			echo "Can't lower securelevel."
			exit 1
		else
			echo -n "Setting securelevel: "
			sysctl -w kern.securelevel=$securelevel
		fi
	else
		if [ "$osecurelevel" = 0 ]; then
			echo -n "Setting securelevel: "
			sysctl -w kern.securelevel=1
		fi
 	fi
}

load_rc_config $name
run_rc_command "$1"
