From 5d28f203cf756df55316755455ea613e4fa9b8b0 Mon Sep 17 00:00:00 2001 From: "Rudra B.S." Date: Mon, 20 Nov 2023 20:12:51 +0530 Subject: [PATCH] feat: use reflector --- akshara | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/akshara b/akshara index 91e105e..3ab4ab2 100755 --- a/akshara +++ b/akshara @@ -213,9 +213,33 @@ def update_system(): print(blend_release) + exec_chroot('cp', '/.new_rootfs/etc/pacman.d/mirrorlist', '/.new_rootfs/etc/pacman.d/mirrorlist.bkp') + with open('/.new_rootfs/etc/pacman.d/mirrorlist', 'w') as pacman_mirrorlist_conf: pacman_mirrorlist_conf.write('Server = https://cloudflaremirrors.com/archlinux/$repo/os/$arch\n') + exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg') + exec_chroot('rm', '-rf', '/var/cache/pacman/pkg') + exec('cp', '-r', '/var/cache/pacman/pkg', '/.new_rootfs/var/cache/pacman') + + # update packages + exec_chroot('pacman-key', '--init') + exec_chroot('pacman-key', '--populate') + + counter = 0 + while True: + return_val = exec_chroot('pacman', '-Sy', '--ask=4', 'reflector') + counter += 1 + if counter > 30: + error('failed to download packages') + exit(50) + if return_val == 0: + break + + exec_chroot('mv', '/.new_rootfs/etc/pacman.d/mirrorlist.bkp', '/.new_rootfs/etc/pacman.d/mirrorlist') + + exec_chroot('reflector', '--latest', '20', '--protocol', 'https', '--sort', 'rate', '--save', '/etc/pacman.d/mirrorlist') + #exec_chroot('sed', 's/#//g', '-i', '/etc/pacman.d/mirrorlist') #exec_chroot('bash', '-c', 'grep "^Server =" /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist.tmp; mv /etc/pacman.d/mirrorlist.tmp /etc/pacman.d/mirrorlist') @@ -239,15 +263,6 @@ SigLevel = Never Server = {package_repo["repo-url"]} ''') - - exec_chroot('mkdir', '-p', '/var/cache/pacman/pkg') - exec_chroot('rm', '-rf', '/var/cache/pacman/pkg') - exec('cp', '-r', '/var/cache/pacman/pkg', '/.new_rootfs/var/cache/pacman') - - # update packages - exec_chroot('pacman-key', '--init') - exec_chroot('pacman-key', '--populate') - counter = 0 while True: return_val = exec_chroot('pacman', '-Syu', '--noconfirm')