af489f7
#!/bin/sh
72aa9bd
#
John W. Linville c12c901
# Copyright 2009-2014 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 4b91122
LOGGER="/usr/bin/logger -t crda"
John W. Linville 4b91122
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
John W. Linville 39af35d
		/usr/sbin/iw reg set $COUNTRY
f2d5862
		exit
f2d5862
	fi
af489f7
fi
af489f7
John W. Linville 61380c8
if [ -f "$LOCALTIME" ]
af489f7
then
John W. Linville 1884bdc
	ZONE=$(readlink -f $LOCALTIME)
b46ae0a
	ZONE=${ZONE#/usr/share/zoneinfo/}
af489f7
else
John W. Linville 4b91122
	$LOGGER -s "Timezone information not found!  Unable to set regulatory domain."
John W. Linville 63a3110
	exit 1
af489f7
fi
af489f7
John W. Linville 3a24c03
if [ -z "$ZONE" -o "$ZONE" = "$LOCALTIME" ]
af489f7
then
John W. Linville 3a24c03
	$LOGGER -s "Could not determine timezone!  Unable to set regulatory domain."
John W. Linville 63a3110
	exit 1
af489f7
fi
af489f7
John W. Linville 2c17588
COUNTRY=$(getcountry)
af489f7
af489f7
if [ -z "$COUNTRY" ]
af489f7
then
John W. Linville 4b91122
	$LOGGER -s "Could not determine country!  Unable to set regulatory domain."
John W. Linville 63a3110
	exit 1
af489f7
fi
af489f7
John W. Linville 4b91122
$LOGGER "setting regulatory domain to $COUNTRY based on timezone ($ZONE)"
John W. Linville 39af35d
/usr/sbin/iw reg set $COUNTRY