#!/bin/sh
# dm24-support/src/expect-scripts/baudconf.sh
# 
#  Copyright: 2015-2016, Guralp Systems Ltd.
#  Author: Laurence Withers <lwithers@guralp.com>
#  License: GPLv3
#

if [ $# -ne 2 ]
then
	echo "Expecting two arguments: port ID and new baud rate" >& 2
	exit 1
fi

PORT_ID="$1"
BAUD="$2"

logger -t "dm24-support" "$0: setting baud ${BAUD} on port ${PORT_ID}"

CFFILE="/etc/conf.d/serial/${PORT_ID}.cf"
cfset "${CFFILE}" "baud=${BAUD}"
if [ $? -ne 0 ]
then
	logger -t "dm24-support" "$0: failed to update ${CFFILE}"
	exit 2
fi

CFFILE="/etc/conf.d/serial/gcf-in-brp/${PORT_ID}"
if [ ! -e "${CFFILE}" ]
then
	# Laurence's reworking of the port configuration means this
	# file may no longer exist.
	exit 0
fi
cfset "${CFFILE}" "serial_baud=${BAUD}"
if [ $? -ne 0 ]
then
	logger -t "dm24-support" "$0: failed to update ${CFFILE}"
	exit 3
fi

exit 0
