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