82 lines
4.6 KiB
Bash
Executable File
82 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#########################################################################
|
|
# common - Utility file with common functions for updater #
|
|
# #
|
|
# Dependencies: #
|
|
# tar #
|
|
# #
|
|
# #
|
|
# Author: Ethan Smith-Coss #
|
|
# Version: 0.1.4 #
|
|
# Created: 2021-05-20T16:47+0100 #
|
|
# Last Modified: 2021-06-13T21:36+0100 #
|
|
# #
|
|
# #################################### #
|
|
# #
|
|
# common - Utility file with common functions for updater #
|
|
# Copyright ©️ 2021 Ethan Smith-Coss #
|
|
# #
|
|
# This program is free software: you can redistribute it and/or modify #
|
|
# it under the terms of the GNU General Public License as published by #
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
# (at your option) any later version. #
|
|
# #
|
|
# This program is distributed in the hope that it will be useful, #
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
# GNU General Public License for more details. #
|
|
# #
|
|
# You should have received a copy of the GNU General Public License #
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
|
# #
|
|
#########################################################################
|
|
|
|
function log {
|
|
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
|
|
[[ ! $? -eq 0 ]] && log "ERROR" "Log function encountered an issue writing to \"$3\". Returning 1." "$log_out" && return 1
|
|
|
|
return 0
|
|
}
|
|
|
|
function archive_system {
|
|
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"
|
|
[[ -f "$archive_output" ]] && return 0
|
|
|
|
grep 'usr/.*' "/tmp/microsoft-edge-autoupdater/Contents-amd64" | tar --overwrite -czf "$archive_output" "/opt/$1/" > "/tmp/microsoft-edge-autoupdater/tar_dump.log" 2>>"$log_out"
|
|
exit_code=$?
|
|
[[ ! $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")
|
|
[[ -e $1 ]] && log "ERROR" "Restore function was called without any arguments." "$log_out"
|
|
local backup_file="/tmp/microsoft-edge-autoupdater/$(echo $1 | sed 's/\//_/').tar.gz"
|
|
[[ ! -f "$backup_file" ]] && { log "ERROR" "There is no backup of Microsoft Edge (Beta) identified. Restoration not possible." "$log_out" ; return 12 ; }
|
|
tar -xzf "$backup_file" "/" > "/tmp/microsoft-edge-autoupdater/tar_dump.log" 2>>"$log_out"
|
|
exit_code=$?
|
|
[[ ! $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 ; }
|
|
|
|
return 0
|
|
}
|
|
|
|
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
|
|
notify-send "$1" "$2" >>"$log_out" 2>&1 && tput bel
|
|
exit_code=$?
|
|
[[ ! $exit_code -eq 0 ]] && log "ERROR" "There was an issue send a notification to the system." "$log_out"
|
|
|
|
return 0
|
|
}
|