2022-05-24 13:06:19 +02:00
|
|
|
{ lib }:
|
|
|
|
let
|
2022-05-25 16:10:10 +02:00
|
|
|
# extractLatestVersionFromHtml :: String -> String
|
2022-05-24 13:06:19 +02:00
|
|
|
extractLatestVersionFromHtml = htmlString:
|
|
|
|
let
|
|
|
|
majorMinorPatchGroup = "([0-9]+\\.[0-9]+\\.[0-9]+)";
|
|
|
|
splittedVersions = builtins.split "href=\"${majorMinorPatchGroup}" htmlString;
|
2022-05-25 16:10:10 +02:00
|
|
|
stableVersions = builtins.concatLists
|
|
|
|
(builtins.filter (e: builtins.isList e)
|
|
|
|
splittedVersions);
|
2022-05-24 13:06:19 +02:00
|
|
|
in
|
2022-05-25 16:10:10 +02:00
|
|
|
if stableVersions == [ ]
|
|
|
|
then abort "Failed to extract versions from html."
|
|
|
|
else lib.last (builtins.sort builtins.lessThan stableVersions);
|
2022-05-24 13:06:19 +02:00
|
|
|
|
2022-05-25 16:10:10 +02:00
|
|
|
# getHtml :: String -> String
|
2022-05-24 13:06:19 +02:00
|
|
|
getHtml = url:
|
|
|
|
builtins.readFile (builtins.fetchurl url);
|
|
|
|
|
2022-05-25 16:10:10 +02:00
|
|
|
# getLatestStableVersion :: String
|
2022-05-24 13:06:19 +02:00
|
|
|
getLatestStableVersion =
|
2022-05-25 16:10:10 +02:00
|
|
|
extractLatestVersionFromHtml
|
|
|
|
(getHtml "https://download.documentfoundation.org/libreoffice/stable/");
|
2022-05-24 13:06:19 +02:00
|
|
|
|
2022-05-25 16:10:10 +02:00
|
|
|
# extractSha256FromHtml :: String -> String
|
2022-05-24 13:06:19 +02:00
|
|
|
extractSha256FromHtml = htmlString:
|
|
|
|
let
|
|
|
|
sha256 = (builtins.match ".*([0-9a-fA-F]{64}).*" htmlString);
|
|
|
|
in
|
2022-05-25 16:10:10 +02:00
|
|
|
if sha256 == [ ]
|
|
|
|
then abort "Failed to extract sha256 from html."
|
|
|
|
else builtins.head sha256;
|
2022-05-24 13:06:19 +02:00
|
|
|
|
2022-05-25 16:10:10 +02:00
|
|
|
# getSha256 :: String -> String
|
2022-05-24 13:06:19 +02:00
|
|
|
getSha256 = dmgUrl: oldVersion: newVersion:
|
|
|
|
extractSha256FromHtml (getHtml (getSha256Url dmgUrl oldVersion newVersion));
|
|
|
|
|
2022-05-25 16:10:10 +02:00
|
|
|
# getSha256Url :: String -> String -> String -> String
|
2022-05-24 13:06:19 +02:00
|
|
|
getSha256Url = dmgUrl: oldVersion: newVersion:
|
|
|
|
(builtins.replaceStrings [ oldVersion ] [ newVersion ] dmgUrl) + ".sha256";
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
2022-05-25 16:10:10 +02:00
|
|
|
inherit
|
|
|
|
extractLatestVersionFromHtml
|
|
|
|
getHtml
|
|
|
|
getLatestStableVersion
|
|
|
|
extractSha256FromHtml
|
|
|
|
getSha256
|
2022-05-25 21:35:11 +02:00
|
|
|
getSha256Url;
|
2022-05-24 13:06:19 +02:00
|
|
|
}
|