mirror of
https://git.launchpad.net/~ubuntu-qt-code/+git/calamares-settings-ubuntu
synced 2025-06-01 21:01:33 +00:00
Migrate to deb822 sources, removing the sources.list file pre-populated by livecd-rootfs. Main and Universe deb sources are enabled by default, Restricted and Multiverse are opt-in via the installer checkbox.
This commit is contained in:
parent
9b0d4c4394
commit
9f6b8f8e8a
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# Copyright (C) 2018 Simon Quigley <tsimonq2@ubuntu.com>
|
# Copyright (C) 2018-2023 Simon Quigley <tsimonq2@ubuntu.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -19,152 +19,97 @@ import json
|
|||||||
import libcalamares
|
import libcalamares
|
||||||
from time import strftime
|
from time import strftime
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.error import URLError
|
|
||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import distro
|
import distro
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
from os import remove
|
||||||
global sources
|
|
||||||
sources = """# Automatically generated by Calamares on DATE.
|
|
||||||
# Lines starting with "deb" are mandatory, while lines starting with "deb-src"
|
|
||||||
# are for more detailed package information.
|
|
||||||
|
|
||||||
## See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
|
|
||||||
## newer versions of DISTRIBUTION.
|
|
||||||
deb URL/ubuntu/ CODENAME main restricted
|
|
||||||
# deb-src URL/ubuntu/ CODENAME main restricted
|
|
||||||
|
|
||||||
## Major bug fix updates produced after the final release of DISTRIBUTION.
|
|
||||||
## Have you noticed a regression? Please report it!
|
|
||||||
## https://wiki.ubuntu.com/StableReleaseUpdates#Regressions
|
|
||||||
deb URL/ubuntu/ CODENAME-updates main restricted
|
|
||||||
# deb-src URL/ubuntu/ CODENAME-updates main restricted
|
|
||||||
|
|
||||||
## Software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu team.
|
|
||||||
## Also, please note that software in Universe WILL NOT receive any review or
|
|
||||||
## updates from the Ubuntu security team directly. Updates in this repository
|
|
||||||
## are provided by volunteers, but most come from Debian.
|
|
||||||
deb URL/ubuntu/ CODENAME universe
|
|
||||||
# deb-src URL/ubuntu/ CODENAME universe
|
|
||||||
deb URL/ubuntu/ CODENAME-updates universe
|
|
||||||
# deb-src URL/ubuntu/ CODENAME-updates universe
|
|
||||||
|
|
||||||
## Software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu team,
|
|
||||||
## and may not be under a free licence. Please satisfy yourself as your rights
|
|
||||||
## to use the software. Also, please note that software in Multiverse WILL NOT
|
|
||||||
## receive any review or updates from the Ubuntu security team directly.
|
|
||||||
deb URL/ubuntu/ CODENAME multiverse
|
|
||||||
# deb-src URL/ubuntu/ CODENAME multiverse
|
|
||||||
deb URL/ubuntu/ CODENAME-updates multiverse
|
|
||||||
# deb-src URL/ubuntu/ CODENAME-updates multiverse
|
|
||||||
|
|
||||||
## Software from this repository contains tested security updates from the
|
|
||||||
## Ubuntu security team.
|
|
||||||
deb http://security.ubuntu.com/ubuntu CODENAME-security main restricted
|
|
||||||
# deb-src http://security.ubuntu.com/ubuntu CODENAME-security main restricted
|
|
||||||
deb http://security.ubuntu.com/ubuntu CODENAME-security universe
|
|
||||||
# deb-src http://security.ubuntu.com/ubuntu CODENAME-security universe
|
|
||||||
deb http://security.ubuntu.com/ubuntu CODENAME-security multiverse
|
|
||||||
# deb-src http://security.ubuntu.com/ubuntu CODENAME-security multiverse
|
|
||||||
|
|
||||||
## Software from this repository may not have been tested as extensively as
|
|
||||||
## software contained in the main release, although it includes newer versions
|
|
||||||
## of some applications which may provide useful features. Also, please note
|
|
||||||
## that software in Backports WILL NOT receive any review or updates from the
|
|
||||||
## Ubuntu security team.
|
|
||||||
deb URL/ubuntu/ CODENAME-backports main restricted universe multiverse
|
|
||||||
# deb-src URL/ubuntu/ CODENAME-backports main restricted universe multiverse"""
|
|
||||||
|
|
||||||
SUBDOMAINS_BY_COUNTRY_CODE = {"US": "us.",
|
|
||||||
"AU": "au.",
|
|
||||||
"SE": "no.",
|
|
||||||
"NO": "no.",
|
|
||||||
"NZ": "nz.",
|
|
||||||
"NL": "nl.",
|
|
||||||
"KR": "kr.",
|
|
||||||
"DE": "de.",
|
|
||||||
"GE": "ge.",
|
|
||||||
"PF": "pf.",
|
|
||||||
"CZ": "cz.",
|
|
||||||
"HR": "hr."}
|
|
||||||
|
|
||||||
|
|
||||||
def getcountrycode():
|
SUBDOMAINS_BY_COUNTRY_CODE = {
|
||||||
"""
|
"US": "us.", "AU": "au.", "SE": "no.", "NO": "no.",
|
||||||
Return the two-letter country code or an empty string.
|
"NZ": "nz.", "NL": "nl.", "KR": "kr.", "DE": "de.",
|
||||||
|
"GE": "ge.", "PF": "pf.", "CZ": "cz.", "HR": "hr."
|
||||||
|
}
|
||||||
|
|
||||||
Tries to determine the country code based on the public IP address,
|
|
||||||
if the device is connected to the Internet. Otherwise it returns
|
|
||||||
an empty string.
|
|
||||||
"""
|
|
||||||
if libcalamares.globalstorage.value("hasInternet"):
|
|
||||||
geoip_style = libcalamares.job.configuration["geoip"]["style"]
|
|
||||||
geoipurl = libcalamares.job.configuration["geoip"]["url"]
|
|
||||||
|
|
||||||
try:
|
def get_sources_template():
|
||||||
with urllib.request.urlopen(geoipurl, timeout=75) as http_response:
|
return """# Automatically generated by Calamares on {date}.
|
||||||
if geoip_style == "json":
|
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
|
||||||
localedata = json.loads(http_response.read().decode())
|
# newer versions of {distro}.
|
||||||
return localedata["country_code"]
|
|
||||||
elif geoip_style == "xml":
|
Types: deb
|
||||||
tree = ET.parse(http_response)
|
URIs: {url}
|
||||||
root = tree.getroot()
|
Suites: {codename} {codename}-updates
|
||||||
return root.find("CountryCode").text
|
Components: main universe
|
||||||
else:
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
||||||
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)
|
def get_sec_sources_template():
|
||||||
except URLError as url_error:
|
return """Types: deb
|
||||||
if isinstance(url_error.reason, socket.timeout):
|
URIs: http://security.ubuntu.com/ubuntu
|
||||||
logging.error("Socket timed out - URL %s", geoipurl)
|
Suites: {codename}-security
|
||||||
else:
|
Components: main universe
|
||||||
logging.error("Non-timeout protocol error.")
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
||||||
else:
|
"""
|
||||||
logging.info("Country successfully determined.")
|
|
||||||
|
|
||||||
|
def get_restricted_sources_template():
|
||||||
|
return """Types: deb
|
||||||
|
URIs: {url}
|
||||||
|
Suites: {codename} {codename}-updates
|
||||||
|
Components: restricted multiverse
|
||||||
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
||||||
|
Enabled: no
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def get_country_code():
|
||||||
|
if not libcalamares.globalstorage.value("hasInternet"):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
geoip_config = libcalamares.job.configuration["geoip"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(geoip_config["url"], timeout=75) as resp:
|
||||||
|
if geoip_config["style"] == "json":
|
||||||
|
return json.loads(resp.read().decode())["country_code"]
|
||||||
|
elif geoip_config["style"] == "xml":
|
||||||
|
return ET.parse(resp).getroot().find("CountryCode").text
|
||||||
|
except (HTTPError, URLError, socket.timeout):
|
||||||
|
logging.error("Failed to get country code.")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def get_subdomain_by_country(countrycode):
|
def get_subdomain_by_country(country_code):
|
||||||
"""Return the subdomain for the given countrycode
|
return SUBDOMAINS_BY_COUNTRY_CODE.get(country_code, "")
|
||||||
or an empty string.
|
|
||||||
"""
|
|
||||||
if countrycode in SUBDOMAINS_BY_COUNTRY_CODE.keys():
|
|
||||||
return SUBDOMAINS_BY_COUNTRY_CODE[countrycode]
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def getcodename():
|
def write_file(path, content):
|
||||||
"""Return the codename of the distribution, similar to lsb_release -cs"""
|
with open(path, "w") as f:
|
||||||
return distro.codename()
|
f.write(content)
|
||||||
|
|
||||||
|
|
||||||
def changesources(subdomain):
|
|
||||||
"""Replace the placeholders and then create the sources.list"""
|
|
||||||
distro = libcalamares.job.configuration["distribution"]
|
|
||||||
url = "http://{}{}".format(subdomain,
|
|
||||||
libcalamares.job.configuration["baseUrl"])
|
|
||||||
|
|
||||||
global sources
|
|
||||||
sources = sources.replace("DISTRIBUTION", distro)
|
|
||||||
sources = sources.replace("CODENAME", getcodename())
|
|
||||||
sources = sources.replace("URL", url)
|
|
||||||
sources = sources.replace("DATE", strftime("%Y-%m-%d"))
|
|
||||||
|
|
||||||
filepath = libcalamares.globalstorage.value("rootMountPoint")
|
|
||||||
filepath += "/etc/apt/sources.list"
|
|
||||||
with open(filepath, "r+") as sourcesfile:
|
|
||||||
sourcesfile.seek(0)
|
|
||||||
sourcesfile.write(sources)
|
|
||||||
sourcesfile.truncate()
|
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""Autoselect a mirror and create the sources.list file."""
|
country_code = get_country_code()
|
||||||
countrycode = getcountrycode()
|
subdomain = get_subdomain_by_country(country_code)
|
||||||
subdomain = get_subdomain_by_country(countrycode)
|
base_url = "http://{}{}/ubuntu".format(subdomain, libcalamares.job.configuration["baseUrl"])
|
||||||
|
codename = distro.codename()
|
||||||
|
|
||||||
changesources(subdomain)
|
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
||||||
|
|
||||||
|
sources = get_sources_template().format(date=strftime("%Y-%m-%d"), distro=libcalamares.job.configuration["distribution"], url=base_url, codename=codename)
|
||||||
|
write_file(f"{root_mount_point}/etc/apt/sources.list.d/ubuntu.sources", sources)
|
||||||
|
|
||||||
|
sec_sources = get_sec_sources_template().format(codename=codename)
|
||||||
|
write_file(f"{root_mount_point}/etc/apt/sources.list.d/ubuntu_security.sources", sec_sources)
|
||||||
|
|
||||||
|
restricted_sources = get_restricted_sources_template().format(url=base_url, codename=codename)
|
||||||
|
write_file(f"{root_mount_point}/etc/apt/sources.list.d/ubuntu_nonfree.sources", restricted_sources)
|
||||||
|
|
||||||
|
remove(f"{root_mount_point}/etc/apt/sources.list")
|
||||||
|
|
||||||
|
libcalamares.globalstorage.insert("mirrorURL", base_url)
|
||||||
|
libcalamares.globalstorage.insert("ubuntuCodename", codename)
|
||||||
|
3
debian/changelog
vendored
3
debian/changelog
vendored
@ -3,6 +3,9 @@ calamares-settings-ubuntu (1:24.04.1) UNRELEASED; urgency=medium
|
|||||||
* Fix Vcs-*.
|
* Fix Vcs-*.
|
||||||
* Add a Package Select module, allowing for fine-tuned customization of the
|
* Add a Package Select module, allowing for fine-tuned customization of the
|
||||||
installed system.
|
installed system.
|
||||||
|
* Migrate to deb822 sources, removing the sources.list file pre-populated by
|
||||||
|
livecd-rootfs. Main and Universe deb sources are enabled by default,
|
||||||
|
Restricted and Multiverse are opt-in via the installer checkbox.
|
||||||
|
|
||||||
-- Simon Quigley <tsimonq2@ubuntu.com> Sun, 08 Oct 2023 22:02:44 -0500
|
-- Simon Quigley <tsimonq2@ubuntu.com> Sun, 08 Oct 2023 22:02:44 -0500
|
||||||
|
|
||||||
|
@ -5,6 +5,11 @@ timeout: 300
|
|||||||
true:
|
true:
|
||||||
- "apt-get -y --purge remove snapd vlc plasma-discover muon transmission-qt quassel 2048-qt featherpad noblenote kcalc qps zsync partitionmanager qapt-deb-installer picom qlipper qtpass libreoffice*"
|
- "apt-get -y --purge remove snapd vlc plasma-discover muon transmission-qt quassel 2048-qt featherpad noblenote kcalc qps zsync partitionmanager qapt-deb-installer picom qlipper qtpass libreoffice*"
|
||||||
- "apt-get -y autoremove"
|
- "apt-get -y autoremove"
|
||||||
|
"packages.restrictedExtras":
|
||||||
|
true:
|
||||||
|
- "sed -i 's/Enabled: no/Enabled: yes/g' /etc/apt/sources.list.d/ubuntu_nonfree.sources"
|
||||||
|
- "apt-get update"
|
||||||
|
- "apt-get -y install ubuntu-restricted-extras"
|
||||||
"packages.updateNow":
|
"packages.updateNow":
|
||||||
true: "apt-get -y full-upgrade"
|
true: "apt-get -y full-upgrade"
|
||||||
"packages.virt-manager":
|
"packages.virt-manager":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user