Skip to content
Snippets Groups Projects
Commit d395c83f authored by Luis Guzmán's avatar Luis Guzmán
Browse files

python-apt: update to latest mirrors system and lists.

parent 41f80384
No related branches found
No related tags found
1 merge request!1627python-apt: update to latest mirrors system and lists.
#! /usr/bin/python3
#
# Script to parse Mirrors.masterlist file for python-apt template
#
# Copyright (C) 2024 Luis Guzmán <ark@switnet.org>
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import re
import argparse
# Set arguments and read input file
parser = argparse.ArgumentParser(description="Parse Mirrors.masterlist")
parser.add_argument(
"file",
help="Path to the Mirrors.masterlist file")
parser.add_argument(
"--country",
"-c",
help="Filter by country (e.g., AU, BR, CA)",
default=None)
parser.add_argument(
"--mirmon",
action="store_true",
help="List mirrors suitable for mirmon output")
args = parser.parse_args()
with open(args.file, 'r') as file:
input_text = file.read()
# Split file by blocks per "Site:"
blocks = re.split(r'(?=Site:\s+)', input_text)
filtered_blocks = [
block.strip()
for block in blocks
if block.strip().startswith("Site:")
]
# Process block country and site
mirrors = {}
for block in blocks:
country_match = re.search(r'Country:\s+(\w{2})\b', block)
country = country_match.group(1) if country_match else None
site_match = re.search(r'Site:\s+(\S+)', block)
site = site_match.group(1) if site_match else None
if not country or not site:
continue
https_matches = re.findall(r"Archive-https:\s+(\S+)", block)
http_matches = re.findall(r"Archive-http:\s+(\S+)", block)
https_urls = [f"https://{site}{path}" for path in https_matches]
http_urls = [f"http://{site}{path}" for path in http_matches]
# Save data in dict
if country not in mirrors:
mirrors[country] = {}
mirrors[country][site] = {"https": https_urls, "http": http_urls}
# Print mirmon output if selected
if args.mirmon:
for country, sites in sorted(mirrors.items()):
if args.country and country != args.country:
continue
for site, urls in sites.items():
if urls["https"]:
print(f"{country.lower()} {urls['https'][0]}")
elif urls["http"]:
print(f"{country.lower()} {urls['http'][0]}")
exit(0)
# Print output
for country, sites in sorted(mirrors.items()):
if args.country and country != args.country:
continue
valid_sites = {
site: urls for site, urls in sites.items()
if urls["https"] or urls["http"]
}
if not valid_sites:
continue
print(f"#LOC:{country}")
for site, urls in valid_sites.items():
for url in urls["https"]:
print(url)
for url in urls["http"]:
print(url)
......@@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
VERSION=8
VERSION=9
COMPONENT=main
. ./config
......@@ -26,38 +26,13 @@ COMPONENT=main
# Fix version number
export UPSTREAMVERSION="$(sed 's|ubuntu0.20.04.1||' <<< $UPSTREAMVERSION)"
# https://en.wikipedia.org/wiki/ISO_3166-2
cat << EOF > data/templates/Trisquel.mirrors
#LOC:AU
https://mirrors.middlendian.com/trisquel-packages/
#LOC:BR
https://trisquel.c3sl.ufpr.br/packages/
#LOC:CA
https://mirror.csclub.uwaterloo.ca/trisquel/packages/
#LOC:CN
https://mirrors.ustc.edu.cn/trisquel
https://mirrors.nju.edu.cn/trisquel/
#LOC:DK
https://mirrors.dotsrc.org/trisquel/
#LOC:EC
https://mirror.cedia.org.ec/trisquel.packages
#LOC:ES
https://mirror.librelabucm.org/trisquel/
#LOC:HU
https://quantum-mirror.hu/mirrors/pub/trisquel/packages/
#LOC:JP
https://repo.jing.rocks/trisquel/
#LOC:SE
https://ftp.acc.umu.se/mirror/trisquel/packages/
https://ftpmirror1.infania.net/mirror/trisquel/packages/
https://ftp.sunet.se/mirror/trisquel/packages/
#LOC:US
https://archive.trisquel.info/trisquel/
https://archive.trisquel.org/trisquel/
https://mirror.fsf.org/trisquel/
https://mirrors.ocf.berkeley.edu/trisquel/
https://mirror.math.princeton.edu/pub/trisquel-packages/
EOF
# Use git Mirrors.masterlist as source.
Mirrors_masterlist=$(mktemp)
Mirrors_masterlist_git="trisquel-packages/-/raw/master/extra/mirrors/Mirrors.masterlist"
wget https://gitlab.trisquel.org/trisquel/$Mirrors_masterlist_git -o /dev/null -O $Mirrors_masterlist
python3 $DATA/parse-mirror-masterlist.py $Mirrors_masterlist > data/templates/Trisquel.mirrors
rm $Mirrors_masterlist
cat << EOF > data/templates/Trisquel.info.in
_ChangelogURI: https://packages.trisquel.org/changelogs/pool/%s/%s/%s/%s_%s/changelog
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment