From ac2e6cfc618fa1e955dcdd49ce1ee6a86cac5b6e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 28 Dec 2018 19:30:15 +0100 Subject: global-functions: add $DownloadPackage ... and make script 'capsman-download-packages' use it. --- capsman-download-packages | 13 +++++-------- global-functions | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/capsman-download-packages b/capsman-download-packages index 8b31574..d8c3e52 100644 --- a/capsman-download-packages +++ b/capsman-download-packages @@ -7,7 +7,7 @@ # # download and cleanup packages for CAP installation from CAPsMAN -:global CertificateAvailable; +:global DownloadPackage; :local "package-path" [ / caps-man manager get package-path ]; :if ([ :pick $"package-path" 0 ] = "/") do={ @@ -26,13 +26,10 @@ :if ($"package-name" = "wireless@") do={ :set "package-name" "wireless"; } - :local "package-file" ($"package-name" . "-" . $"installed-version" . "-" . $"package-architecture" . ".npk"); - $CertificateAvailable "Let's Encrypt Authority X3" "letsencrypt"; - / tool fetch mode=https check-certificate=yes-without-crl \ - ("https://upgrade.mikrotik.com/routeros/" . $"installed-version" . "/" . $"package-file") \ - dst-path=($"package-path" . "/" . $"package-file"); - :set updated true; - / file remove $package; + :if ([ $DownloadPackage $"package-name" $"installed-version" $"package-architecture" $"package-path" ] = true) do={ + :set updated true; + / file remove $package; + } } :if ($updated = true) do={ diff --git a/global-functions b/global-functions index 041700c..6cd05ea 100644 --- a/global-functions +++ b/global-functions @@ -107,3 +107,28 @@ :return "unknown vendor"; } } + +# download package from upgrade server +:global DownloadPackage do={ + :local pkgname [ :tostr $1 ]; + :local pkgver [ :tostr $2 ]; + :local pkgarch [ :tostr $3 ]; + :local pkgdest [ :tostr $4 ]; + + :global CertificateAvailable; + + :if ([ :len $pkgname ] = 0) do={ return false; } + :if ([ :len $pkgver ] = 0) do={ :set pkgver [ / system package update get installed-version ]; } + :if ([ :len $pkgarch ] = 0) do={ :set pkgarch [ / system resource get architecture-name ]; } + + $CertificateAvailable "Let's Encrypt Authority X3" "letsencrypt"; + do { + :local pkgfile ($pkgname . "-" . $pkgver . "-" . $pkgarch . ".npk"); + / tool fetch mode=https check-certificate=yes-without-crl \ + ("https://upgrade.mikrotik.com/routeros/" . $pkgver . "/" . $pkgfile) \ + dst-path=($pkgdest . "/" . $pkgfile); + return true; + } on-error={ + return false; + } +} -- cgit v1.2.3-54-g00ecf