global-functions: introduce and use $CleanFilePath

This commit is contained in:
Christian Hesse 2019-02-13 09:44:15 +01:00
parent 8537bbe19d
commit c361caee5b

View file

@ -137,6 +137,25 @@
}
}
# clean file path
:global CleanFilePath do={
:local Path [ :tostr $1 ];
:global CharacterReplace;
:while ($Path ~ "//") do={
:set $Path [ $CharacterReplace $Path "//" "/" ];
}
:if ([ :pick $Path 0 ] = "/") do={
:set Path [ :pick $Path 1 [ :len $Path ] ];
}
:if ([ :pick $Path ([ :len $Path ] - 1) ] = "/") do={
:set Path [ :pick $Path 0 ([ :len $Path ] - 1) ];
}
:return $Path;
}
# download package from upgrade server
:global DownloadPackage do={
:local PkgName [ :tostr $1 ];
@ -145,16 +164,14 @@
:local PkgDir [ :tostr $4 ];
:global CertificateAvailable;
:global CleanFilePath;
: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 ]; }
:local PkgFile ($PkgName . "-" . $PkgVer . "-" . $PkgArch . ".npk");
:local PkgDest $PkgFile;
:if ($PkgDir != "") do={
:set PkgDest ($PkgDir . "/" . $PkgFile);
}
:local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ];
$CertificateAvailable "Let's Encrypt Authority X3" "letsencrypt";
:do {