From 2be42e55945db7d01263d2feb5148630be3faab8 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sun, 8 Oct 2023 12:19:55 -0500 Subject: [PATCH] Use geoip.ubuntu.com by default. --- common/modules/automirror/automirror.conf | 4 ++-- common/modules/automirror/main.py | 17 +++++++++++++---- debian/changelog | 1 + lubuntu/modules/automirror.conf | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/common/modules/automirror/automirror.conf b/common/modules/automirror/automirror.conf index aa1c8ff..ad81b3a 100644 --- a/common/modules/automirror/automirror.conf +++ b/common/modules/automirror/automirror.conf @@ -6,8 +6,8 @@ baseUrl: archive.ubuntu.com # URL used for IP address lookup geoip: - style: "json" - url: "https://ipapi.co/json" + style: "xml" + url: "https://geoip.ubuntu.com/lookup" # Distribution that this is based off of. # This is so we can make safe assumptions for the contents of diff --git a/common/modules/automirror/main.py b/common/modules/automirror/main.py index 6f4f8a8..c436a41 100644 --- a/common/modules/automirror/main.py +++ b/common/modules/automirror/main.py @@ -24,6 +24,7 @@ from urllib.error import URLError import socket import logging import distro +import xml.etree.ElementTree as ET global sources sources = """# Automatically generated by Calamares on DATE. @@ -99,10 +100,20 @@ def getcountrycode(): an empty string. """ if libcalamares.globalstorage.value("hasInternet"): + geoip_style = libcalamares.job.configuration["geoip"]["style"] geoipurl = libcalamares.job.configuration["geoip"]["url"] + try: with urllib.request.urlopen(geoipurl, timeout=75) as http_response: - localedata = json.loads(http_response.read().decode()) + if geoip_style == "json": + localedata = json.loads(http_response.read().decode()) + return localedata["country_code"] + elif geoip_style == "xml": + tree = ET.parse(http_response) + root = tree.getroot() + return root.find("CountryCode").text + else: + logging.error("Unknown geoip style: %s", geoip_style) except HTTPError as http_error: logging.error("Data not retrieved because %s - URL: %s", http_error, geoipurl) @@ -113,9 +124,7 @@ def getcountrycode(): logging.error("Non-timeout protocol error.") else: logging.info("Country successfully determined.") - return localedata["country"] - else: - return "" + return "" def get_subdomain_by_country(countrycode): diff --git a/debian/changelog b/debian/changelog index 9ca5000..95334c9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ calamares-settings-ubuntu (1:23.10.4) UNRELEASED; urgency=medium * Remove the Partners repository as an option. + * Use geoip.ubuntu.com by default. -- Simon Quigley Sun, 08 Oct 2023 11:53:28 -0500 diff --git a/lubuntu/modules/automirror.conf b/lubuntu/modules/automirror.conf index e11458d..075f81a 100644 --- a/lubuntu/modules/automirror.conf +++ b/lubuntu/modules/automirror.conf @@ -2,5 +2,5 @@ baseUrl: archive.ubuntu.com distribution: Lubuntu geoip: - style: "json" - url: "https://ipapi.co/json" + style: "xml" + url: "https://geoip.ubuntu.com/lookup"