[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RFC: countrychooser and IP location



Hi!

I think it'd be nice if IP location would be used to check user input from
country chooser.  The main advantage is that "auto" installs get the right
mirror selected.

My proposal is to get the iplocation data as soon as we have network, then
check it against user input and if different ask the user wether to replace
its old country selection (default to yes so that "auto" activates it).

Please see attached PoC (untested) patch.

-- 
Robert Millan

My spam trap is honeypot@aybabtu.com.  Note: this address is only intended for
spam harvesters.  Writing to it will get you added to my black list.
Index: debian/control
===================================================================
--- debian/control	(revision 40466)
+++ debian/control	(working copy)
@@ -12,3 +12,10 @@
 Depends: cdebconf-udeb, iso-3166-udeb, di-utils (>= 1.15)
 XB-Installer-Menu-Item: 10
 Description: choose language/country/locale
+
+Package: localechooser-iplocation
+XC-Package-Type: udeb
+Architecture: all
+Depends: localechooser, configured-network
+XB-Installer-Menu-Item: 10
+Description: check user-provided country against iplocation
Index: debian/localechooser.templates-in
===================================================================
--- debian/localechooser.templates-in	(revision 40466)
+++ debian/localechooser.templates-in	(working copy)
@@ -109,6 +109,20 @@
  Based on your language, you are probably located in one of these countries
  or regions.
 
+Template: countrychooser/iplocation_disparity
+Type: boolean
+Default: true
+Description: Replace ${OLD} with ${NEW}?
+ Earlier in the installation you've selected that you're located in ${OLD}.
+ However, using a dynamic IP location mechanism this installer has determined
+ that you're actualy located in ${NEW}.
+ .
+ We believe the data in our IP location database to be accurate.  However, if
+ there is a mistake in this detection, you can tell the installer not to replace
+ your country information.  In that case, we'd like to remind you that you may
+ later use the form at http://www.hostip.info/ to correct this.  Your feedback
+ will be very appreciated.
+
 Template: debian-installer/locale
 Type: select
 Choices: ${LOCALELIST}
Index: debian/localechooser-iplocation.postinst
===================================================================
--- debian/localechooser-iplocation.postinst	(revision 0)
+++ debian/localechooser-iplocation.postinst	(revision 0)
@@ -0,0 +1,34 @@
+#!/bin/sh -e
+
+. /usr/share/debconf/confmodule
+
+iplocated_country=`wget -q http://api.hostip.info/country.php -O - | head -c 2`
+
+valid ()
+{
+  if ! echo "$1" | grep -qx ".." || ! grep -q "^$1" /usr/share/iso-codes/iso_3166.tab ; then
+    return 1
+  fi
+  return 0
+}
+
+if valid "${iplocated_country}" ; then
+	db_get debian-installer/country
+	if ! valid "$RET" ; then
+		# just in case
+		db_set debian-installer/country ${iplocated_country}
+	elif [ "$RET" != "${iplocated_country}" ] ; then
+		db_subst countrychooser/iplocation_disparity OLD "$RET"
+		db_subst countrychooser/iplocation_disparity NEW "${iplocated_country}"
+		db_input high countrychooser/iplocation_disparity || true
+		db_go || true
+		db_get countrychooser/iplocation_disparity || true
+		if [ "$RET" = "true" ] ; then
+			db_set debian-installer/country ${iplocated_country}
+		fi
+	fi
+fi
+
+#DEBHELPER#
+
+exit 0

Reply to: