From ab3980e73a318c4cdc66001de97073daa8c2aec0 Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Sat, 7 Aug 2021 13:37:01 +0200 Subject: [PATCH] asterisk: add update script --- pkgs/servers/asterisk/default.nix | 54 ++++++++--------------------- pkgs/servers/asterisk/update.py | 36 +++++++++++++++++++ pkgs/servers/asterisk/versions.json | 18 ++++++++++ 3 files changed, 68 insertions(+), 40 deletions(-) create mode 100755 pkgs/servers/asterisk/update.py create mode 100644 pkgs/servers/asterisk/versions.json diff --git a/pkgs/servers/asterisk/default.nix b/pkgs/servers/asterisk/default.nix index be0cd877458c..e8912f4b5374 100644 --- a/pkgs/servers/asterisk/default.nix +++ b/pkgs/servers/asterisk/default.nix @@ -90,7 +90,16 @@ let sha256 = "1s9idx2miwk178sa731ig9r4fzx4gy1q8xazfqyd7q4lfd70s1cy"; }; -in rec { + # auto-generated by update.py + versions = lib.mapAttrs (_: {version, sha256}: common { + inherit version sha256; + externals = { + "externals_cache/pjproject-2.10.tar.bz2" = pjproject_2_10; + "addons/mp3" = mp3-202; + }; + }) (builtins.fromJSON (builtins.readFile ./versions.json)); + +in { # Supported releases (as of 2020-10-26). # Source: https://wiki.asterisk.org/wiki/display/AST/Asterisk+Versions # Exact version can be found at https://www.asterisk.org/downloads/asterisk/all-asterisk-versions/ @@ -100,43 +109,8 @@ in rec { # 16.x LTS 2018-10-09 2022-10-09 2023-10-09 # 17.x Standard 2019-10-28 2020-10-28 2021-10-28 # 18.x LTS 2020-10-20 2024-10-20 2025-10-20 - asterisk-lts = asterisk_18; - asterisk-stable = asterisk_18; - asterisk = asterisk_18; + asterisk-lts = versions.asterisk_18; + asterisk-stable = versions.asterisk_18; + asterisk = versions.asterisk_18; - asterisk_13 = common { - version = "13.38.2"; - sha256 = "1v7wgsa9vf7qycg3xpvmn2bkandkfh3x15pr8ylg0w0gvfkkf5b9"; - externals = { - "externals_cache/pjproject-2.10.tar.bz2" = pjproject_2_10; - "addons/mp3" = mp3-202; - }; - }; - - asterisk_16 = common { - version = "16.17.0"; - sha256 = "1bzlsk9k735qf8a693b6sa548my7m9ahavmdicwmc14px70wrvnw"; - externals = { - "externals_cache/pjproject-2.10.tar.bz2" = pjproject_2_10; - "addons/mp3" = mp3-202; - }; - }; - - asterisk_17 = common { - version = "17.9.3"; - sha256 = "0nhk0izrxx24pz806fwnhidjmciwrkcrsvxvhrdvibiqyvfk8yk7"; - externals = { - "externals_cache/pjproject-2.10.tar.bz2" = pjproject_2_10; - "addons/mp3" = mp3-202; - }; - }; - - asterisk_18 = common { - version = "18.3.0"; - sha256 = "1xb953i9ay82vcdv8izi5dd5xnspcsvg10ajiyph377jw2xnd5fb"; - externals = { - "externals_cache/pjproject-2.10.tar.bz2" = pjproject_2_10; - "addons/mp3" = mp3-202; - }; - }; -} +} // versions diff --git a/pkgs/servers/asterisk/update.py b/pkgs/servers/asterisk/update.py new file mode 100755 index 000000000000..d194481c6f4f --- /dev/null +++ b/pkgs/servers/asterisk/update.py @@ -0,0 +1,36 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python3 -p python39 python39.pkgs.packaging python39.pkgs.beautifulsoup4 python39.pkgs.requests +from packaging import version +from bs4 import BeautifulSoup +import re, requests, json + +URL = "https://downloads.asterisk.org/pub/telephony/asterisk" + +page = requests.get(URL) +changelog = re.compile("^ChangeLog-\d+\.\d+\.\d+$") +changelogs = [a.get_text() for a in BeautifulSoup(page.text, 'html.parser').find_all('a') if changelog.match(a.get_text())] +major_versions = {} +for changelog in changelogs: + v = version.parse(changelog.removeprefix("ChangeLog-")) + major_versions.setdefault(v.major, []).append(v) + +out = {} +for mv in major_versions.keys(): + v = max(major_versions[mv]) + sha = requests.get(f"{URL}/asterisk-{v}.sha256").text.split()[0] + out["asterisk_" + str(mv)] = { + "version": str(v), + "sha256": sha + } + +try: + with open("versions.json", "r") as in_file: + in_data = json.loads(in_file.read()) + for v in in_data.keys(): + print(v + ":", in_data[v]["version"], "->", out[v]["version"]) +except: + # nice to have for the PR, not a requirement + pass + +with open("versions.json", "w") as out_file: + out_file.write(json.dumps(out, sort_keys=True, indent=2)) diff --git a/pkgs/servers/asterisk/versions.json b/pkgs/servers/asterisk/versions.json new file mode 100644 index 000000000000..fce5449aa118 --- /dev/null +++ b/pkgs/servers/asterisk/versions.json @@ -0,0 +1,18 @@ +{ + "asterisk_13": { + "sha256": "1v7wgsa9vf7qycg3xpvmn2bkandkfh3x15pr8ylg0w0gvfkkf5b9", + "version": "13.38.2" + }, + "asterisk_16": { + "sha256": "1bzlsk9k735qf8a693b6sa548my7m9ahavmdicwmc14px70wrvnw", + "version": "16.17.0" + }, + "asterisk_17": { + "sha256": "0nhk0izrxx24pz806fwnhidjmciwrkcrsvxvhrdvibiqyvfk8yk7", + "version": "17.9.3" + }, + "asterisk_18": { + "sha256": "1xb953i9ay82vcdv8izi5dd5xnspcsvg10ajiyph377jw2xnd5fb", + "version": "18.3.0" + } +}