Update plugins for new lure-updater and add go-bin plugin

This commit is contained in:
Elara 2023-06-25 13:08:29 -07:00
parent d2b3baaca4
commit 6178c3068f
2 changed files with 55 additions and 10 deletions

45
go-bin.star Normal file
View File

@ -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)

View File

@ -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): def update_pkg(req):
if req.headers["X-Gitea-Event"][0] != "release": if req.headers["X-Gitea-Event"][0] != "release":
return {"code": 400, "body": "This plugin only accepts release events"} return {"code": 400, "body": "This plugin only accepts release events"}
body = json.decode(req.body.string()) body = req.body.read_json()
req.body.close() req.body.close()
if body["action"] != "published": if body["action"] != "published":
@ -47,12 +56,3 @@ def update_pkg(req):
updater.push_changes("upg(lure-bin): %s" % name[1:]) updater.push_changes("upg(lure-bin): %s" % name[1:])
register_webhook(update_pkg) 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