From f46db918453dcb8878b9a0de6e122fb0ea2224d9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 22 Feb 2021 15:14:10 +0100 Subject: global: give script or function name in log messages --- packages-update | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'packages-update') diff --git a/packages-update b/packages-update index 4a2f418..d23be09 100644 --- a/packages-update +++ b/packages-update @@ -6,11 +6,12 @@ # download packages and reboot for installation # https://git.eworm.de/cgit/routeros-scripts/about/doc/packages-update.md +:local 0 "packages-update"; :global GlobalFunctionsReady; :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } :global DownloadPackage; -:global LogPrintExit; +:global LogPrintExit2; :global ScriptFromTerminal; :global ScriptLock; :global VersionToNum; @@ -20,11 +21,11 @@ $ScriptLock "packages-update"; :local Update [ / system package update get ]; :if ([ :typeof ($Update->"latest-version") ] = "nothing") do={ - $LogPrintExit warning "Latest version is not known." true; + $LogPrintExit2 warning $0 ("Latest version is not known.") true; } :if ($Update->"installed-version" = $Update->"latest-version") do={ - $LogPrintExit info ("Version " . $Update->"latest-version" . " is already installed.") true; + $LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is already installed.") true; } :local NumInstalled [ $VersionToNum ($Update->"installed-version") ]; @@ -40,39 +41,39 @@ $ScriptLock "packages-update"; :put "Canceled..."; } } else={ - $LogPrintExit warning ("Not installing downgrade automatically.") true; + $LogPrintExit2 warning $0 ("Not installing downgrade automatically.") true; } } :foreach Package in=[ / system package find where !bundle ] do={ :local PkgName [ / system package get $Package name ]; if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={ - $LogPrintExit error ("Download for package " . $PkgName . " failed.") true; + $LogPrintExit2 error $0 ("Download for package " . $PkgName . " failed.") true; } } :foreach Script in=[ / system script find where name~"^(cloud|email|upload)-backup\$" ] do={ :local ScriptName [ / system script get $Script name ]; :do { - $LogPrintExit info ("Running backup script " . $ScriptName . " before update.") false; + $LogPrintExit2 info $0 ("Running backup script " . $ScriptName . " before update.") false; / system script run $Script; } on-error={ - $LogPrintExit warning ("Running backup script " . $ScriptName . " before update failed!") false; + $LogPrintExit2 warning $0 ("Running backup script " . $ScriptName . " before update failed!") false; :if ([ $ScriptFromTerminal "packages-update" ] = true) do={ :put "Do you want to continue anyway? [y/N]"; :if (([ :terminal inkey timeout=60 ] % 32) = 25) do={ - $LogPrintExit info ("User requested to continue anyway.") false; + $LogPrintExit2 info $0 ("User requested to continue anyway.") false; } else={ - $LogPrintExit info ("Canceled update...") true; + $LogPrintExit2 info $0 ("Canceled update...") true; } } else={ - $LogPrintExit info ("Canceled non-interactive update.") true; + $LogPrintExit2 info $0 ("Canceled non-interactive update.") true; } } } :if ($DoDowngrade = true) do={ - $LogPrintExit info ("Rebooting for downgrade.") false; + $LogPrintExit2 info $0 ("Rebooting for downgrade.") false; :delay 1s; / system package downgrade; } @@ -83,10 +84,10 @@ $ScriptLock "packages-update"; / system scheduler add name="reboot-for-update" start-time=03:00:00 interval=1d \ on-event=(":global RandomDelay; \$RandomDelay 3600; " . \ "/ system scheduler remove reboot-for-update; / system reboot;"); - $LogPrintExit info ("Scheduled reboot for update between 03:00 and 04:00.") true; + $LogPrintExit2 info $0 ("Scheduled reboot for update between 03:00 and 04:00.") true; } } -$LogPrintExit info ("Rebooting for update.") false; +$LogPrintExit2 info $0 ("Rebooting for update.") false; :delay 1s; / system reboot; -- cgit v1.2.3-70-g09d2