Fixed bugs
Changed the behaviour of tar to not be verbose and any output it placed in a tmp file, STDERR is redirected to logs. Bug with the format of exit code capture in updater that was fixed in common; however, those changes hadn't been made until now in updater.
This commit is contained in:
parent
8340f56d2f
commit
11a90f8f92
34
updater
34
updater
|
|
@ -18,7 +18,7 @@
|
|||
# Author: Ethan Smith-Coss #
|
||||
# Version: 0.1.4 #
|
||||
# Created: 2021-05-20T16:47+0100 #
|
||||
# Last Modified: 2021-06-05T16:45+0100 #
|
||||
# Last Modified: 2021-06-13T21:36+0100 #
|
||||
# #
|
||||
# #################################### #
|
||||
# #
|
||||
|
|
@ -133,7 +133,8 @@ command -v notify-send >/dev/null 2>&1 || nn_flag=0
|
|||
nn_flag=${nn_flag:-1}
|
||||
|
||||
## check if Microsoft Edge (Beta) is already installed
|
||||
exit_code=$(command -v microsoft-edge-beta &>/dev/null)
|
||||
command -v microsoft-edge-beta &>/dev/null
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo "Microsoft Edge (Beta) is not installed. Exiting updater..." ;
|
||||
log "DEBUG" "Microsoft Edge (Beta) not recognised as an installed program. Exiting...(1)" ; exit 1 ; }
|
||||
log "DEBUG" "Microsoft Edge (Beta) is installed to system. Proceeding with update..." "$log_file"
|
||||
|
|
@ -167,13 +168,15 @@ dist_upstream=$(grep "\[dists.*\]" "$source_list" | cut -d' ' -f 2-4 --output-de
|
|||
archi=$(grep -o "\[dists.*\]" "$source_list" | sed -E 's/\[dists=(.*)\]/\1/')
|
||||
log "DEBUG" "Fetching Packages file from $dist_upstream for $archi architectures..." "$log_file"
|
||||
## fetch the file - :@Ethan: there's no reason to inform the user of this operation unless it fails
|
||||
exit_code=$(wget -a "$log_file" -O "$tmp_path/Packages.gz" "$dist_upstream/binary-$archi/Packages.gz")
|
||||
wget -a "$log_file" -O "$tmp_path/Packages.gz" "$dist_upstream/binary-$archi/Packages.gz"
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo "There was an issue retrieving the package information for the update. Please check $logs_dir/updater.log, for more information. Exiting..." ;
|
||||
log "DEBUG" "Encountered an issue with wget. Exiting...(4)" "$log_file" ; exit 4 ; }
|
||||
log "DEBUG" "Successfully downloaded release package information." "$log_file"
|
||||
|
||||
log "DEBUG" "Fetching Contents-$archi.gz from ${dist_upstream::-4}" "$log_file"
|
||||
exit_code=$(wget -a "$log_file" -O "$tmp_path/Contents-$archi.gz" "${dist_upstream::-4}/Contents-$archi.gz")
|
||||
wget -a "$log_file" -O "$tmp_path/Contents-$archi.gz" "${dist_upstream::-4}/Contents-$archi.gz"
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo "There was an issue retrieving the package contents for the update. Please check $log_file/updater.log, so more information. Exiting..." ;
|
||||
log "ERROR" "Encountered an issue with wget. Exiting...(4)" "$log_file" ; exit 4 ; }
|
||||
log "DEBUG" "Successfully downloaded release contents information." "$log_file"
|
||||
|
|
@ -248,7 +251,8 @@ if [[ $is_running -gt 1 ]] ; then
|
|||
[[ $(echo $choice | awk '{print tolower($0)}') == "n" ]] && { log "DEBUG" "User opted against allowing the script to close Microsoft Edge (Beta) by default. Exiting...(1)" "$log_file" ; exit 1 ; }
|
||||
fi
|
||||
log "DEBUG" "Confirmation has been given to proceed with killing Microsoft Edge (Beta) processes. Killing msedge..." "$log_file"
|
||||
exit_code=$(killall msedge)
|
||||
killall msedge
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { log "ERROR" "Process is refusing to exit. Sending SIGKILL signal." "$log_file" ;
|
||||
pkill -9 msedge ; }
|
||||
fi
|
||||
|
|
@ -298,8 +302,9 @@ log "DEBUG" "Checking if the file is already downloaded to the system..." "$log_
|
|||
if [[ ! -f "$tmp_path/$filename" ]] ; then
|
||||
log "DEBUG" "Downloading the latest release version [v$release_version], file: $filename (URL: $url)" "$log_file"
|
||||
echo "Downloading the following release file: $filename. This may take a moment..."
|
||||
wget_timed=$(\time --format "%x:%e" wget -a "$tmp_path/wget_dump.log" -O "$tmp_path/$filename" "$url" 2>&1)
|
||||
exit_code=$(echo $wget_timed | cut -d: -f1)
|
||||
# wget_timed=$(\time --format "%x:%e" wget -a "$tmp_path/wget_dump.log" -O "$tmp_path/$filename" "$url" 2>&1)
|
||||
wget -a "$tmp_path/wget_dump.log" --progress=bar --show-progress -O "$tmp_path/$filename" "$url"
|
||||
exit_code=$? # $(echo $wget_timed | cut -d: -f1)
|
||||
[[ ! $exit_code -eq 0 ]] && { echo "There was an issue downloading the Debian version of Microsoft Edge (Beta)." \
|
||||
"Please check $logs_dir/updater.log, for more information. Exiting update..." ;
|
||||
log "DEBUG" "Encountered an issue with wget. Exiting...(6)" "$log_file" ; exit 6 ; }
|
||||
|
|
@ -329,12 +334,14 @@ echo "complete."
|
|||
log "DEBUG" "Unarchiving the downloaded DEB file ($tmp_path/$filename)..." "$log_file"
|
||||
printf "Unzipping download..."
|
||||
## use ar to unarchive .deb file
|
||||
exit_code=$(ar vx "$tmp_path/$filename" --output "$tmp_path" >/dev/null 2>&1)
|
||||
ar vx "$tmp_path/$filename" --output "$tmp_path" >/dev/null 2>&1
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo -e "incomplete.\nThere was an issue unarchiving $filename. Exiting updater...\n" ;
|
||||
log "ERROR" "There was an issue when unarchiving $filename. Exiting...(8)" "$log_file" ; exit 8 ; }
|
||||
log "DEBUG" "Successfully unarchived $filename, decompressing the data.tar.gz file..." "$log_file"
|
||||
## extract data from data.tar.gz
|
||||
exit_code=$(tar --overwrite -xvf "$tmp_path/data.tar.xz" --directory "$tmp_path" 2>>"$log_file")
|
||||
tar --overwrite -xf "$tmp_path/data.tar.xz" --directory "$tmp_path" 1>"$tmp_path/tar_dump.log" 2>>"$log_file"
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo -e "incomplete.\nThere was an extracting data.tar.gz. Exiting updater...\n" ;
|
||||
log "ERROR" "There was an issue when decompressing data.tar.gz using tar -xvf. Exiting...(8)" "$tmp_path" ; exit 8 ; }
|
||||
log "DEBUG" "Successfully extracted files from data.tar.gz." "$log_file"
|
||||
|
|
@ -348,7 +355,8 @@ echo "$tmp_path/data.tar.xz" >> "$garbage"
|
|||
## :@TODO: compress everything on the system for a backup. Remove it if installation of new version was successful
|
||||
log "DEBUG" "Creating an archive gzip tarball of system /opt/ and /usr/ directories..." "$log_file"
|
||||
printf "Installing new version to system. This may take a few minutes..."
|
||||
exit_code=$(archive_system "microsoft/msedge-beta")
|
||||
archive_system "microsoft/msedge-beta"
|
||||
exit_code=$?
|
||||
if [[ ! $exit_code -eq 0 ]] ; then
|
||||
### :@Ethan: there was an issue with creating an archive, should probably inform the user to make a decision (unless -y is set)
|
||||
echo -e "failed.\nThere was an issue creating a backup of the system. Exiting..."
|
||||
|
|
@ -362,10 +370,12 @@ log "DEBUG" "Successfully created an archive gzip tarball of the system. Safe to
|
|||
|
||||
# install the new version to system
|
||||
log "DEBUG" "Copying files to there appropriate location..." "$log_file"
|
||||
exit_code=$(cp -r "$tmp_path/opt" "/" >>"$log_file" 2>&1)
|
||||
cp -r "$tmp_path/opt" "/" >>"$log_file" 2>&1
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo -e "failed.\nThere was an issue installing files to the system. Reverting to previous version..." ;
|
||||
log "DEBUG" "There was an issue copying $tmp_path/opt/ file to system /opt/. Reverting system files and exiting...(9)" "$log_file" ; restore_files && exit 9 ; }
|
||||
exit_code=$(cp -r "$tmp_path/usr" "/" >>"$log_file" 2>&1)
|
||||
cp -r "$tmp_path/usr" "/" >>"$log_file" 2>&1
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && { echo -e "failed.\nThere was an issue installing files to the system. Reverting to previous version..." ;
|
||||
log "DEBUG" "There was an issue copying $tmp_path/usr/ file to system /usr/. Reverting system files and exiting...(9)" "$log_file" ; restore_files && exit 9 ; }
|
||||
log "DEBUG" "Successfully installed files to their appropriate location." "$log_file"
|
||||
|
|
|
|||
11
utils/common
11
utils/common
|
|
@ -9,7 +9,7 @@
|
|||
# Author: Ethan Smith-Coss #
|
||||
# Version: 0.1.4 #
|
||||
# Created: 2021-05-20T16:47+0100 #
|
||||
# Last Modified: 2021-06-05T16:45+0100 #
|
||||
# Last Modified: 2021-06-13T21:36+0100 #
|
||||
# #
|
||||
# #################################### #
|
||||
# #
|
||||
|
|
@ -48,7 +48,8 @@ function archive_system {
|
|||
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/" 2>>"$log_out" ; echo $?)
|
||||
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
|
||||
|
|
@ -59,7 +60,8 @@ function restore_files {
|
|||
[[ -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"
|
||||
[[ -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" "/" 2>>"$log_out" ; echo $?)
|
||||
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 ; }
|
||||
|
||||
|
|
@ -71,7 +73,8 @@ function notify {
|
|||
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 ; echo $?) && tput bel
|
||||
notify-send "$1" "$2" >>"$log_out" 2>&1 ; echo $?) && tput bel
|
||||
exit_code=$?
|
||||
[[ ! $exit_code -eq 0 ]] && log "ERROR" "There was an issue send a notification to the system." "$log_out"
|
||||
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user