Set mirror pamac with continent and global

Hello Manjaro community.

I’m trying to create a command line where the mirrors of my pamac repository are defined with the list of the countries of my continent and the Global as well.

The commands are:
sudo pacman-mirrors --continent (Sets the mirror with the continent’s countries)
sudo pacman-mirrors --country Global (Sets the mirror with Global)

The problem is that either I choose the countries or the Global, when in fact I would like to unify these two commands, make the mirror define the countries of the continent and I will include the Global in this list.

For only then I use the:
–fasttrack

Is it possible via terminal?

Perhaps run each command separately and check your mirrorlist each time. Combine what you like into your own custom mirror list.

@linux-aarhus always has more detailed explanations. :bowing_man:

You could set multiple countries instead if your goal is to do only from one terminal command, add all countries of your region in the country command.

1 Like

Pamac only supports one country - but you can do it with pacman-mirrors

pacman-mirrors -h

or read the man page

man pacman-mirrors

The end result is a what is called a custom mirror pool and any and all subsequent runs of pacman-mirrors will work only on that pool. The mirror pool can be reset using the -c all argument.

List all mirror countries in alphabetical order (no - there is no option to list countries in continent)

pacman-mirrors -l

Then build a command using the your preferred countries.

Or you can use the -c all --interactive --default

sudo pacman-mirrors --country all --interactive --default [--no-status]

Select the countries to include and save the choices.

In case you wonder why only certain countries are represented in the final mirrorlist - you must know that - any run of pacman-mirrors will only return mirrors registered as up-to-date for the current system branch.

It is possible to use the –no-status flag thus including mirrors which has not synced for a very long time. As some mirrors has not synced for months - the result should be limited by using the –interval Y where Y is the number of hours since last sync. Don’t use this feature unless you have very compelling reasons to do so.

To practice my python - I wrote below snippet. The snippet prints out the countries for your continent and adds the Global to the list (I have noted another non-existing country MENA)

import requests
from pacman_mirrors.constants.timezones import countries

# preload countries list with Global mirror
result = ["Global"]

# setup requests
mirror_data_request = requests.get("https://repo.manjaro.org/mirrors.json")
geo_info_request = requests.get("https://get.geojs.io/v1/ip/geo.json")
continent_codes_request = requests.get("https://datahub.io/core/continent-codes/r/continent-codes.json")

# fetch data using the requests
manjaro_mirror_data = mirror_data_request.json()
geo_info_data = geo_info_request.json()
continent_codes_data = continent_codes_request.json()

# setting up filter expressions
continent_data_expression = [cc for cc in continent_codes_data if geo_info_data["continent_code"] in cc["Code"]]
continent_country_expression = [c for c in countries if c["continent"] == continent_data_expression[0]["Name"]]

# loop the countries
for country in continent_country_expression:
    # setup mirror filter expression
    mirror_country_expression = [m for m in manjaro_mirror_data if m["country"] == country["name"].replace(" ", "_")]
    # loop the mirrors
    for mirror in mirror_country_expression:
        # check for duplicates
        if mirror["country"] not in result:
            result.append(mirror["country"])
            # skip the remaining mirrors in country
            continue
print(",".join(result))

Assuming the above snippet is saved in your home as main.py then running the snippet will - for a european citizen - produce the following result

$ ~ python main.py
Global,Iceland,Netherlands,Greece,Germany,Belgium,Hungary,Denmark,Finland,Russia,Ukraine,Portugal,United_Kingdom,Spain,Belarus,Norway,France,Italy,Bulgaria,Sweden,Austria,Poland,Switzerland

It is possible to run the script and feed the output to pacman-mirrors like this

$ ~ sudo pacman-mirrors -c $(python main.py)
1 Like

shiny-mirrors does this, just set continent with “sudo shiny-mirrors config -C” (it will show basic menu to choose from) and run “sudo shiny-mirrors refresh” and it will rank all mirrors from that continent and global mirrors

3 Likes