From 5f457e5c37ee58f592ca677766515725212a5fad Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 15 Nov 2023 14:22:55 +0100 Subject: backup-upload: build file info in a function --- backup-upload.rsc | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'backup-upload.rsc') diff --git a/backup-upload.rsc b/backup-upload.rsc index 46b4c7b..5c5e37e 100644 --- a/backup-upload.rsc +++ b/backup-upload.rsc @@ -25,8 +25,6 @@ :global CharacterReplace; :global DeviceInfo; -:global FormatLine; -:global HumanReadableNum; :global IfThenElse; :global LogPrintExit2; :global MkDir; @@ -122,24 +120,30 @@ $WaitFullyConnected; /file/remove ($FilePath . ".conf.txt"); } +:local FileInfo do={ + :local Name $1; + :local File $2; + + :global FormatLine; + :global HumanReadableNum; + :global IfThenElse; + + :return \ + [ $IfThenElse ([ :typeof $File ] = "array") \ + ($Name . ":\n" . [ $FormatLine " name" ($File->"name") ] . "\n" . \ + [ $FormatLine " size" ([ $HumanReadableNum ($File->"size") 1024 ] . "iB") ]) \ + [ $FormatLine $Name $File ] ]; +} + $SendNotification2 ({ origin=$0; \ subject=[ $IfThenElse ($Failed > 0) \ ([ $SymbolForNotification "floppy-disk,warning-sign" ] . "Backup & Config upload with failure") \ ([ $SymbolForNotification "floppy-disk,up-arrow" ] . "Backup & Config upload") ]; \ message=("Backup and config export upload for " . $Identity . ".\n\n" . \ [ $DeviceInfo ] . "\n\n" . \ - [ $IfThenElse ([ :typeof $BackupFile ] = "array") \ - ("Backup file:\n" . [ $FormatLine " name" ($BackupFile->"name") ] . "\n" . \ - [ $FormatLine " size" [ $HumanReadableNum ($BackupFile->"size") 1024 ] ]) \ - [ $FormatLine "Backup file" $BackupFile ] ] . "\n" . \ - [ $IfThenElse ([ :typeof $ExportFile ] = "array") \ - ("Export file:\n" . [ $FormatLine " name" ($ExportFile->"name") ] . "\n" . \ - [ $FormatLine " size" [ $HumanReadableNum ($ExportFile->"size") 1024 ] ]) \ - [ $FormatLine "Export file" $ExportFile ] ] . "\n" . \ - [ $IfThenElse ([ :typeof $ConfigFile ] = "array") \ - ("Config file:\n" . [ $FormatLine " name" ($ConfigFile->"name") ] . "\n" . \ - [ $FormatLine " size" [ $HumanReadableNum ($ConfigFile->"size") 1024 ] ]) \ - [ $FormatLine "Config file" $ConfigFile ] ]); silent=true }); + [ $FileInfo "Backup file" $BackupFile ] . "\n" . \ + [ $FileInfo "Export file" $ExportFile ] . "\n" . \ + [ $FileInfo "Config file" $ConfigFile ]); silent=true }); :if ($Failed = 1) do={ :error "An error occured!"; -- cgit v1.2.3-54-g00ecf