Added list_mirrors() and prepared for selecting mirrors in guided.py
This commit is contained in:
parent
2ac4172394
commit
5bba102c45
|
|
@ -1,7 +1,9 @@
|
|||
import urllib.request
|
||||
|
||||
from .exceptions import *
|
||||
from .general import *
|
||||
|
||||
def filter_mirrors_by_region(regions, *args, **kwargs):
|
||||
def filter_mirrors_by_region(regions, destination='/etc/pacman.d/mirrorlist', tmp_dir='/root', *args, **kwargs):
|
||||
"""
|
||||
This function will change the active mirrors on the live medium by
|
||||
filtering which regions are active based on `regions`.
|
||||
|
|
@ -12,9 +14,9 @@ def filter_mirrors_by_region(regions, *args, **kwargs):
|
|||
region_list = []
|
||||
for region in regions.split(','):
|
||||
region_list.append(f'country={region}')
|
||||
o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(region_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist")))
|
||||
o = b''.join(sys_command(("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist")))
|
||||
o = b''.join(sys_command(("/usr/bin/mv /root/mirrorlist /etc/pacman.d/")))
|
||||
o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(region_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O {tmp_dir}/mirrorlist")))
|
||||
o = b''.join(sys_command((f"/usr/bin/sed -i 's/#Server/Server/' {tmp_dir}/mirrorlist")))
|
||||
o = b''.join(sys_command((f"/usr/bin/mv {tmp_dir}/mirrorlist {destination}")))
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -54,7 +56,37 @@ def insert_mirrors(mirrors, *args, **kwargs):
|
|||
|
||||
return True
|
||||
|
||||
def use_mirrors(regions :dict, destination='/etc/pacman.d/mirrorlist'):
|
||||
for region, mirrors in regions.items():
|
||||
with open(destination, 'w') as mirrorlist:
|
||||
for mirror in mirrors:
|
||||
mirrorlist.write(f'## {region}\n')
|
||||
mirrorlist.write(f'Server = {mirror}\n')
|
||||
return True
|
||||
|
||||
def re_rank_mirrors(top=10, *positionals, **kwargs):
|
||||
if sys_command((f'/usr/bin/rankmirrors -n {top} /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist')).exit_code == 0:
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
def list_mirrors():
|
||||
url = f"https://www.archlinux.org/mirrorlist/?protocol=https&ip_version=4&ip_version=6&use_mirror_status=on"
|
||||
|
||||
response = urllib.request.urlopen(url)
|
||||
regions = {}
|
||||
|
||||
region = 'Unknown region'
|
||||
for line in response.readlines():
|
||||
if len(line.strip()) == 0: continue
|
||||
|
||||
line = line.decode('UTF-8').strip('\n').strip('\r')
|
||||
if line[:3] == '## ':
|
||||
region = line[3:]
|
||||
elif line[:10] == '#Server = ':
|
||||
if not region in regions:
|
||||
regions[region] = {}
|
||||
|
||||
url = line[1:].lstrip('Server = ')
|
||||
regions[region][url] = True
|
||||
|
||||
return regions
|
||||
|
|
@ -43,6 +43,10 @@ archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', surpress_error
|
|||
keyboard_language = archinstall.select_language(archinstall.list_keyboard_languages())
|
||||
archinstall.set_keyboard_language(keyboard_language)
|
||||
|
||||
# Set which region to download packages from during the installation
|
||||
mirror_regions = archinstall.select_mirror_regions(archinstall.list_mirrors())
|
||||
archinstall.use_mirrors(mirror_regions)
|
||||
|
||||
harddrive = archinstall.select_disk(archinstall.all_disks())
|
||||
while (disk_password := getpass.getpass(prompt='Enter disk encryption password (leave blank for no encryption): ')):
|
||||
disk_password_verification = getpass.getpass(prompt='And one more time for verification: ')
|
||||
|
|
|
|||
4
make.sh
4
make.sh
|
|
@ -11,7 +11,7 @@ mv archinstall.dist "archinstall-v${VERSION}-x86_64"
|
|||
tar -czvf "archinstall-v${VERSION}.tar.gz" "archinstall-v${VERSION}-x86_64"
|
||||
|
||||
# makepkg -f
|
||||
# python3 setup.py sdist bdist_wheel
|
||||
# echo 'python3 -m twine upload dist/* && rm -rf dist/'
|
||||
python3 setup.py sdist bdist_wheel
|
||||
echo 'python3 -m twine upload dist/* && rm -rf dist/'
|
||||
|
||||
rm -rf archinstall.egg-info/ build/ src/ pkg/ archinstall.build/ "archinstall-v${VERSION}-x86_64/"
|
||||
|
|
|
|||
Loading…
Reference in New Issue