#!/bin/sh

# Copyright C 2002-2003 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
# 
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
# 
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.

### Isilon configure baudrate
#
# This script changes immediate and permanent (via /boot/loader.conf)
# baud rates.  It is called both before and after imdd, to get
# serial as early as possible and to get loader.conf after that's
# changeable.

# PROVIDE: isi_configure_baud
# REQUIRE: isi_bootdisk_init

. /etc/rc.subr

name="isi_changebaud"
start_cmd="isi_changebaud_start"

#
# Setting (or configuring) the baud rate of the serial console port 
# is accomplished as follows:
#
# 1) The user edits the "/etc/rc.conf.local" file and either modifies
#    the baud rate specified in the 'isi_changebaud_require="115200"' line 
#    or adds the line if it does not already exist.
# 2) When run, "isi_configure_baud" (this script) uses the rate specified 
#    (if any) in the "isi_changebaud_require" environment variable as the 
#    rate parameter for the "/usr/sbin/isi_changebaud" script. 
# 3) The "/usr/sbin/isi_changebaud" script sets the rate of the running
#    system and modifies the rates found in the /boot/loader.conf file.
# 4) The boot loader uses the rates specified in the /boot/loader.conf
#    file to configure the speed of the hardware.
#

isi_changebaud_start()
{
    if [ -x /usr/sbin/isi_changebaud ]; then
	echo -n 'Configuring console port baudrate...  '

	if [ "X${isi_changebaud_require}" != "X" ]; then
	    #always use isi_changebaud_require if set
	    use_baudrate=${isi_changebaud_require}
	else
	    # default is 115200
	    use_baudrate="115200"
	fi

	#If we're booted from CF, we might not always boot from the
	#same type of hardware (the CF can get moved around a lot).
	#So we might want to change it so that flash does only
	#immediate, not permanent.  But I could also argue the other
	#way, so don't special-case it yet.  But you could do:
	#! /sbin/sysctl -n kern.disks | /usr/bin/grep ad2 > /dev/null 
	#has_flash=$?
	#if [ ${has_flash} -eq 1 ]; then [throw flag to isi_changebaud]

	echo ${use_baudrate}
	/usr/sbin/isi_changebaud ${use_baudrate}
    fi
}

load_rc_config $name
run_rc_command "$1"
