-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-mirrors.py
28 lines (22 loc) · 1.06 KB
/
update-mirrors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
from argparse import ArgumentParser
from getpass import getuser
from sys import platform
from subprocess import run
parser = ArgumentParser(prog="update-mirrors")
parser.add_argument("-d", "--distro", type=str, metavar="", default="arch",
help="the distro for which to download mirrors for")
parser.add_argument("-s", "--save", type=str, metavar="", default="/etc/pacman.d/mirrorlist",
help="directory where to save the mirrorlist at")
parser.add_argument("--version", action="version", version="%(prog)s 1.0")
args = parser.parse_args()
if __name__ == "__main__":
current_platform: str = platform.lower()
current_user: str = getuser()
if not current_platform == "linux":
raise RuntimeError(f"{current_platform}: platform not supported")
else:
if not current_user == "root":
raise PermissionError("insufficient permissions to run this script")
cmd: str = f"/usr/bin/rate-mirrors --allow-root --save {args.save} {args.distro}"
run(args=cmd, shell=True)