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

Bug#239560: base-config: Set default mirror site patch



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Package: base-config
Version: 2.17
Severity: wishlist
Tags: patch

I created default mirror patch for apt-setup.
This checks debian-installer/country value and choices his/her country
first as mirror list.

This patch looks dirty, but this is because it is difficult to apply
i18n value to dynamic created items.

After this report, I'll commit this patch into base-config repository.
- -- 
Kenshi Muto
kmuto@debian.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkBgMH0ACgkQQKW+7XLQPLGuIgCfdPCFc0VZac+vubKpQ2I6qEvQ
qwwAn3KpcV6E+LrI6wNE/9XnGdIl2j5c
=Mx+r
-----END PGP SIGNATURE-----
diff -u -r1.44 apt-setup
--- apt-setup	23 Feb 2004 00:16:56 -0000	1.44
+++ apt-setup	23 Mar 2004 12:34:07 -0000
@@ -32,6 +32,42 @@
 	APTCDROM Dir::Bin::apt-cdrom/d`
 eval $RES
 
+country_i18n () {
+  # conversion country name using iso_3166 table
+    case "$1" in
+      local)
+        perl -e '
+		use Locale::gettext;
+		use POSIX;
+		textdomain("iso_3166");
+		print gettext(shift);
+		' $2
+      ;;
+      C)
+        perl -e '
+		use Locale::gettext;
+		use POSIX;
+		textdomain("iso_3166");
+		$country=shift;
+		$ret= "";
+
+		open (T, "/usr/share/zoneinfo/iso3166.tab");
+		while (<T>) {
+			next if /^#/;
+			chomp;
+			($code, $long)=split(/\t/, $_);
+			if (gettext($long) eq $country) {
+			    $ret = $long;
+			    close T;
+			}
+		}
+		close T;
+		print $ret ? $ret : $country;
+		' $2
+      ;;
+    esac
+}
+
 # Pass in a URI type; this function returns a list of countries
 # that have mirrors in them that match the type.
 country_list () {
@@ -47,14 +83,14 @@
 				next if /^#/;
 				chomp;
 				($code, $long)=split(/\t/, $_);
-				$c{$code}=$long;
+				$co{$code}=$long;
 			}
 			close T;
 			$/="\n\n";
 		}
 		if (/Archive-$type:/) {
 			($c)=/Country: (.*?)\s+.*\n/;
-			$countries{gettext($c{$c})}=1 if $c;
+			$countries{gettext($co{$c})}=1 if $c;
 		}
 		END { print join(", ", sort(keys %countries)) }
 	' $1 $MIRRORLIST
@@ -67,9 +103,6 @@
 mirror_list () {
 	perl -ne '
 		BEGIN {
-			use Locale::gettext;
-			use POSIX;
-			textdomain("iso_3166");
 			$type=shift;
 			$country=shift;
 			open (T, "/usr/share/zoneinfo/iso3166.tab");
@@ -77,7 +110,7 @@
 				next if /^#/;
 				chomp;
 				($code, $long)=split(/\t/, $_);
-				if (gettext($long) eq $country) {
+				if ($long eq $country) {
 					$country=$code;
 				        close T;
 				}
@@ -272,12 +305,48 @@
 	ftp|http)
 		# Ask them which country they're in.
 		db_subst apt-setup/country countries "`country_list $URI`"
+		db_fget apt-setup/country seen
+		if [ "$RET" = "false" ]; then
+		  # Set default country
+		  db_get debian-installer/country
+		  COUNTRY=$(perl -e '
+			$countrycode=shift;
+			open (T, "/usr/share/zoneinfo/iso3166.tab");
+			while (<T>) {
+				next if /^#/;
+				chomp;
+				($code, $long)=split(/\t/, $_);
+				if ($code eq $countrycode) {
+					print "$long";
+				        close T;
+				}
+			}
+			close T;
+		   ' $RET)
+		   if [ -n $COUNTRY ]; then
+		     db_set apt-setup/country $COUNTRY
+		   fi
+		fi
+		db_get apt-setup/country
+		IFS=","
+		db_set apt-setup/country $(country_i18n local "$RET")
+		unset IFS
+		db_get apt-setup/country
 		db_fset apt-setup/country seen false
 		db_input critical apt-setup/country || true
 		db_go || continue
-		
+
 		db_get apt-setup/country
 		if [ "$RET, " != "$(gettext 'enter information manually, ')" ]; then
+		   IFS=","
+		   db_set apt-setup/country $(country_i18n C "$RET")
+		   unset IFS
+		else
+		   db_set apt-setup/country 'enter information manually'
+		fi
+
+		db_get apt-setup/country
+		if [ "$RET" != "enter information manually" ]; then
 			# Now prompt with the mirrors in the selected country.
 			db_subst apt-setup/mirror mirrors "`mirror_list $URI \"$RET\"`"
 			db_fset apt-setup/mirror seen false



Reply to: