diff options
author | Achilleas Koutsou | 2022-11-28 01:37:31 +0100 |
---|---|---|
committer | Achilleas Koutsou | 2022-11-28 01:41:44 +0100 |
commit | 867d872ea92d9143756deff846f86f35a95aadbe (patch) | |
tree | 058539392d0c62bf4db54febe777f02c0e3cdcb0 | |
parent | 1686725a6b8df51d9282516b8b0921dfc84f004f (diff) | |
download | aur-867d872ea92d9143756deff846f86f35a95aadbe.tar.gz |
checkupdate: script for checking for upstream releases
- Reads the aur version from the AUR metadata API.
- Parses the redirect URL from the 'latest' link from the Crashplan
site.
- Compares the versions and exits with 0 status if the upstream version
is newer.
-rwxr-xr-x | checkupdate | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/checkupdate b/checkupdate new file mode 100755 index 000000000000..6c12e3433dc0 --- /dev/null +++ b/checkupdate @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +import http.client +import json +import re +import sys + +from typing import Dict, Tuple + + +def parse_location(fname: str) -> Dict[str, str]: + pattern = r"CrashPlanSmb_(?P<ver>[0-9.]+)_(?P<timestamp>[0-9]{14})_(?P<build>[0-9]+)_Linux.tgz" + regex = re.compile(pattern) + match = regex.match(fname) + if match: + return match.groupdict() + else: + raise ValueError("regex match failed") + + +def get_upstream_ver(): + # get upstream version from parsing the redirect URL from: + # download.crashplan.com/installs/agent/latest-smb-linux.tgz + conn = http.client.HTTPSConnection("download.crashplan.com") + conn.request("HEAD", "/installs/agent/latest-smb-linux.tgz") + resp = conn.getresponse() + loc = resp.headers.get("location") + fname = loc.rsplit("/", 1)[-1] + info = parse_location(fname) + return info["ver"] + + +def get_aur_ver() -> str: + # get aur version from aur rpc: + # aur.archlinux.org/rpc/?v=5&type=info&arg[]=crashplan-pro + conn = http.client.HTTPSConnection("aur.archlinux.org") + conn.request("GET", "/rpc/?v=5&type=info&arg[]=crashplan-pro") + resp = conn.getresponse().read() + respj = json.loads(resp) + data = respj["results"][0] + ver, _ = data["Version"].rsplit("-", 2) + return ver + + +def parse_ver(v: str) -> Tuple[int, ...]: + return tuple(int(cmp) for cmp in v.split(".")) + + +def newer(other: str, base: str) -> bool: + return parse_ver(other) > parse_ver(base) + + +def main(): + aur_ver = get_aur_ver() + upstream_ver = get_upstream_ver() + + if newer(upstream_ver, aur_ver): + print(f"{upstream_ver} > {aur_ver}") + sys.exit(0) + + print(f"{upstream_ver} <= {aur_ver}") + sys.exit(1) + + +if __name__ == "__main__": + main() |