From eb1ed051d2eafc38eaed90f1dd713a82f571e4a3 Mon Sep 17 00:00:00 2001 From: TheOnePath Date: Fri, 28 May 2021 18:26:55 +0100 Subject: [PATCH] Updated common to v0.1.3 Common now contains a notify function which uses notify-send to provide a user with a notification when the function is called. - Function takes 2 inputs, {summary} and {body} which are respectful to the basic arguments for notify-send. - Function returns an issue with required amount of arguments aren't met. - Default arguments are used with notify-send, no other interaction is made possible. Updated backup functions to only log STDERR to file, which files are (de)compressed aren't fundamental to logging information and exact files can be checked appropriately via other means. Fixed bug with relative path being incorrect for operation of updater when sourcing in common. --- utils/common | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/utils/common b/utils/common index 1a5ae5e..07045f7 100755 --- a/utils/common +++ b/utils/common @@ -7,9 +7,9 @@ # # # # # Author: Ethan Smith-Coss # -# Version: 0.1.2 # +# Version: 0.1.3 # # Created: 2021-05-20T16:47+0100 # -# Last Modified: 2021-05-23T23:06+0100 # +# Last Modified: 2021-05-27T15:34+0100 # # # # #################################### # # # @@ -32,7 +32,7 @@ ######################################################################### function log { - local log_out=$(realpath "${0%/*}/../.log.1") + local log_out=$(realpath "${0%/*}/.log.1") [[ $# -eq 0 ]] && log "ERROR" "Log function was called without any arguments. Returning 1." "$log_out" && return 1 [[ ! $# -eq 3 ]] && log "ERROR" "Log function expected at least 3 arguments, recieved $#. Returning 1." "$log_out" && return 1 $(echo "$(date -Iseconds) ($1): $2" >> "$3") >/dev/null 2>&1 @@ -42,24 +42,24 @@ function log { } function archive_system { - local log_out=$(realpath "${0%/*}/../.log.1") + local log_out=$(realpath "${0%/*}/.log.1") [[ -e $1 ]] && log "ERROR" "Archive function was called without any arguments." "$log_out" - local archive_output="$/tmp/microsoft-edge-autoupdater/$(echo $1 | sed 's/\//_/').tar.gz" + local archive_output="/tmp/microsoft-edge-autoupdater/$(echo $1 | sed 's/\//_/').tar.gz" [[ -f "$archive_output" ]] && return 0 - exit_code=$(grep 'usr/.*' "/tmp/microsoft-edge-autoupdater/Contents-amd64" | tar --overwrite -cvzf "$archive_output" "/opt/$1/" >>"$log_out" 2>&1 ) + exit_code=$(grep 'usr/.*' "/tmp/microsoft-edge-autoupdater/Contents-amd64" | tar --overwrite -cvzf "$archive_output" "/opt/$1/" 2>>"$log_out") [[ ! $exit_code -eq 0 ]] && { log "ERROR" "(Archive) There was an issue creating the archive file of system. Returning...(10)" "$log_out" ; return 10 ; } return 0 } function restore_files { - local log_out=$(realpath "${0%/*}/../.log.1") + local log_out=$(realpath "${0%/*}/.log.1") [[ -e $1 ]] && log "ERROR" "Restore function was called without any arguments." "$log_out" - local backup_file="/tmp/microsoft-edge-autoupdater/$(echo $1 | 's/\/_/').tar.gz" + local backup_file="/tmp/microsoft-edge-autoupdater/$(echo $1 | 's/\//_/').tar.gz" [[ -f "$backup_file" ]] && { log "ERROR" "There is no backup of Microsoft Edge (Beta) identified. Restoration not possible." "$log_out" ; return 12 ; } - exit_code=$( tar -xvzf "$backup_file" "/" >>"$log_out" 2>&1) + exit_code=$( tar -xvzf "$backup_file" "/" 2>>"$log_out") [[ ! $exit_code -eq 0 ]] && { log "ERROR" "There was an issue restoring pervious files to system." \ "The backup created will not be removed to allow for manual restoration. Returning...(12)" ; return 12 ; } @@ -68,5 +68,11 @@ function restore_files { function notify { ## :@TODO: implement notification system. + local log_out=$(realpath "${0%/*}/.log.1") + [[ $# -eq 0 ]] && log "ERROR" "Notify function was called without any arguments. Returning 1." "$log_out" && return 1 + [[ ! $# -eq 2 ]] && log "ERROR" "Notify function expected at least 2 arguments, recieved $#. Returning 1." "$log_out" && return 1 + exit_code=$(notify-send "$1" "$2" >>"$log_out" 2>&1) && tput bel + [[ ! $exit_code -eq 0 ]] && log "ERROR" "There was an issue send a notification to the system." "$log_out" + return 0 }