0962c3
#!/bin/sh
0962c3
#
0962c3
# Copyright 2009-2014 Red Hat, Inc.  All rights reserved.
0962c3
#
0962c3
# Permission to use, copy, modify, and/or distribute this software for any
0962c3
# purpose with or without fee is hereby granted, provided that the above
0962c3
# copyright notice and this permission notice appear in all copies.
0962c3
# 
0962c3
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0962c3
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0962c3
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0962c3
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0962c3
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0962c3
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0962c3
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0962c3
#
0962c3
0962c3
REGDOMAIN=/etc/sysconfig/regdomain
0962c3
LOCALTIME=/etc/localtime
0962c3
0962c3
LOGGER="/usr/bin/logger -t crda"
0962c3
0962c3
getcountry() {
0962c3
	while read c a z r
0962c3
	do
0962c3
		if [ "$z" = "$ZONE" ]
0962c3
		then
0962c3
			echo $c
0962c3
			break
0962c3
		fi
0962c3
	done < /usr/share/zoneinfo/zone.tab
0962c3
}
0962c3
0962c3
if [ -f $REGDOMAIN ]
0962c3
then
0962c3
	# This should set COUNTRY
0962c3
	. $REGDOMAIN
0962c3
	if [ -n "$COUNTRY" ]
0962c3
	then
0962c3
		/usr/sbin/iw reg set $COUNTRY
0962c3
		exit
0962c3
	fi
0962c3
fi
0962c3
0962c3
if [ -f "$LOCALTIME" ]
0962c3
then
0962c3
	ZONE=$(readlink -f $LOCALTIME)
0962c3
	ZONE=${ZONE#/usr/share/zoneinfo/}
0962c3
else
0962c3
	$LOGGER -s "Timezone information not found!  Unable to set regulatory domain."
0962c3
	exit 1
0962c3
fi
0962c3
0962c3
if [ -z "$ZONE" -o "$ZONE" = "$LOCALTIME" ]
0962c3
then
0962c3
	$LOGGER -s "Could not determine timezone!  Unable to set regulatory domain."
0962c3
	exit 1
0962c3
fi
0962c3
0962c3
COUNTRY=$(getcountry)
0962c3
0962c3
if [ -z "$COUNTRY" ]
0962c3
then
0962c3
	$LOGGER -s "Could not determine country!  Unable to set regulatory domain."
0962c3
	exit 1
0962c3
fi
0962c3
0962c3
$LOGGER "setting regulatory domain to $COUNTRY based on timezone ($ZONE)"
0962c3
/usr/sbin/iw reg set $COUNTRY