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