From 6178c3068fecca8d7bb496ef6361345b9f3aa897 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Sun, 25 Jun 2023 13:08:29 -0700 Subject: [PATCH] Update plugins for new lure-updater and add go-bin plugin --- go-bin.star | 45 +++++++++++++++++++++++++++++++++++++++++++++ lure-bin.star | 20 ++++++++++---------- 2 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 go-bin.star diff --git a/go-bin.star b/go-bin.star new file mode 100644 index 0000000..95311e3 --- /dev/null +++ b/go-bin.star @@ -0,0 +1,45 @@ +def update_pkg(s, version): + rows = s.find('tbody > tr') + checksums = {} + for row in rows: + link = row.first().find('a').attr('href') + checksum = row.last().find('tt').text() + + if 'linux' not in link: + continue + elif 'linux-386' in link: + checksums['386'] = checksum + elif 'linux-amd64' in link: + checksums['amd64'] = checksum + elif 'linux-arm64' in link: + checksums['arm64'] = checksum + elif 'linux-armv6l' in link: + checksums['arm6'] = checksum + + tmpl = updater.get_package_file("go-bin", "lure.tmpl.sh") + updater.write_package_file("go-bin", "lure.sh", tmpl % ( + version, + checksums["amd64"], + checksums["arm64"], + checksums["arm6"], + checksums["386"], + )) + + updater.push_changes("upg(go-bin): %s" % version) + + print(version) + print(checksums) + +def poll_for_updates(): + res = http.get('https://go.dev/dl') + s = html.parse(res.body).find('h2#stable').next() + + version = s.attr("id").removeprefix("go") + stored = store.get('version') + if stored == "": + store.set("version", version) + elif stored != version: + update_pkg(s, version) + store.set("version", version) + +run_every("1h", poll_for_updates) diff --git a/lure-bin.star b/lure-bin.star index a753629..bbee0b0 100644 --- a/lure-bin.star +++ b/lure-bin.star @@ -1,8 +1,17 @@ +def get_checksums(download_url): + checksum_url = download_url + "/checksums.txt" + res = http.get(checksum_url) + lines = res.body.string().split("\n") + res.body.close() + checksum_list = [item.split(" ") for item in lines] + checksums = [(checksum[1], checksum[0]) for checksum in checksum_list if len(checksum) == 2] + return checksums + def update_pkg(req): if req.headers["X-Gitea-Event"][0] != "release": return {"code": 400, "body": "This plugin only accepts release events"} - body = json.decode(req.body.string()) + body = req.body.read_json() req.body.close() if body["action"] != "published": @@ -47,12 +56,3 @@ def update_pkg(req): updater.push_changes("upg(lure-bin): %s" % name[1:]) register_webhook(update_pkg) - -def get_checksums(download_url): - checksum_url = download_url + "/checksums.txt" - res = http.get(checksum_url) - lines = res.body.string().split("\n") - res.body.close() - checksum_list = [item.split(" ") for item in lines] - checksums = [(checksum[1], checksum[0]) for checksum in checksum_list if len(checksum) == 2] - return checksums