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