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