3 # extractLatestVersionFromHtml :: String -> String
4 extractLatestVersionFromHtml = htmlString:
6 majorMinorPatchGroup = "([0-9]+\\.[0-9]+\\.[0-9]+)";
7 splittedVersions = builtins.split "href=\"${majorMinorPatchGroup}" htmlString;
8 stableVersions = builtins.concatLists
9 (builtins.filter (e: builtins.isList e)
12 if stableVersions == [ ]
13 then abort "Failed to extract versions from html."
14 else lib.last (builtins.sort builtins.lessThan stableVersions);
16 # getHtml :: String -> String
18 builtins.readFile (builtins.fetchurl url);
20 # getLatestStableVersion :: String
21 getLatestStableVersion =
22 extractLatestVersionFromHtml
23 (getHtml "https://download.documentfoundation.org/libreoffice/stable/");
25 # extractSha256FromHtml :: String -> String
26 extractSha256FromHtml = htmlString:
28 sha256 = (builtins.match ".*([0-9a-fA-F]{64}).*" htmlString);
31 then abort "Failed to extract sha256 from html."
32 else builtins.head sha256;
34 # getSha256 :: String -> String
35 getSha256 = dmgUrl: oldVersion: newVersion:
36 extractSha256FromHtml (getHtml (getSha256Url dmgUrl oldVersion newVersion));
38 # getSha256Url :: String -> String -> String -> String
39 getSha256Url = dmgUrl: oldVersion: newVersion:
40 (builtins.replaceStrings [ oldVersion ] [ newVersion ] dmgUrl) + ".sha256";
45 extractLatestVersionFromHtml
47 getLatestStableVersion