Updated updater
Changed preamble and comments Changed the wording of some messages to the user and log. Program adds the backup archive to the garbage list if the restoration was successful.
This commit is contained in:
parent
a2fcbb0512
commit
8522783a12
28
updater
28
updater
|
|
@ -4,10 +4,14 @@
|
||||||
# updater - Automatically update Microsoft Edge on Solus #
|
# updater - Automatically update Microsoft Edge on Solus #
|
||||||
# #
|
# #
|
||||||
# Dependencies: #
|
# Dependencies: #
|
||||||
|
# bash #
|
||||||
# wget #
|
# wget #
|
||||||
|
# git #
|
||||||
# gunzip #
|
# gunzip #
|
||||||
# tar #
|
# tar #
|
||||||
# sort (coreutils >= 8.32) #
|
# coreutils (>= 8.32) #
|
||||||
|
# binutils (>=2.35.1) #
|
||||||
|
# procps (only BusyBox-based systems) #
|
||||||
# notify-send #
|
# notify-send #
|
||||||
# #
|
# #
|
||||||
# #
|
# #
|
||||||
|
|
@ -51,6 +55,8 @@ DISCLAIMER: Currently this program can only update the Beta release of Microsoft
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-nn, --no-notify Prevent notifications from being set after a session.
|
-nn, --no-notify Prevent notifications from being set after a session.
|
||||||
|
--mode=[debug] Set the mode of the program to be ran in. Default mode occurs without this flag.
|
||||||
|
* debug - run program in debug mode.
|
||||||
-y, --yes-all Assume yes to all yes/no decisions.
|
-y, --yes-all Assume yes to all yes/no decisions.
|
||||||
-v, --version Print out the version of the script and exit.
|
-v, --version Print out the version of the script and exit.
|
||||||
-h, --help Print this help message and exit
|
-h, --help Print this help message and exit
|
||||||
|
|
@ -65,10 +71,11 @@ garbage="$tmp_path/garbage.tmp"
|
||||||
## program timer
|
## program timer
|
||||||
SECONDS=0
|
SECONDS=0
|
||||||
|
|
||||||
|
## create the logs directory and tmp location if they don't already exist
|
||||||
[[ ! -d "$logs_dir" ]] && mkdir "$logs_dir"
|
[[ ! -d "$logs_dir" ]] && mkdir "$logs_dir"
|
||||||
[[ ! -d "$tmp_path" ]] && mkdir "$tmp_path"
|
[[ ! -d "$tmp_path" ]] && mkdir "$tmp_path"
|
||||||
|
|
||||||
|
# function responsible for cleaning up after a session execution
|
||||||
function clean_up {
|
function clean_up {
|
||||||
log "DEBUG" "EXIT signal was raised, cleaning up system after session before exiting..." "$log_file"
|
log "DEBUG" "EXIT signal was raised, cleaning up system after session before exiting..." "$log_file"
|
||||||
printf "Cleaning up system after session..."
|
printf "Cleaning up system after session..."
|
||||||
|
|
@ -93,6 +100,7 @@ function clean_up {
|
||||||
[[ $debug_run -eq 0 ]] && cat "$logs_dir/updater.log"
|
[[ $debug_run -eq 0 ]] && cat "$logs_dir/updater.log"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ensure that the restoration was sucessful in reverting the system back
|
||||||
function check_restoration {
|
function check_restoration {
|
||||||
[[ ! $1 -eq 0 ]] && { echo -e "failed.\nThere was an error trying to restore system files." \
|
[[ ! $1 -eq 0 ]] && { echo -e "failed.\nThere was an error trying to restore system files." \
|
||||||
"Either there no back was made or another issue occurred. Consult $log_file for more information." ; exit $1 ; }
|
"Either there no back was made or another issue occurred. Consult $log_file for more information." ; exit $1 ; }
|
||||||
|
|
@ -102,6 +110,7 @@ function check_restoration {
|
||||||
"Consult $log_file for more information. Exiting..."
|
"Consult $log_file for more information. Exiting..."
|
||||||
[[ ! $nn_flag -eq 0 ]] && notify "Microsoft Edge (Beta) Update" "There was an issue installing the update to your system." \
|
[[ ! $nn_flag -eq 0 ]] && notify "Microsoft Edge (Beta) Update" "There was an issue installing the update to your system." \
|
||||||
"The previous version, v$current_version, has been restored."
|
"The previous version, v$current_version, has been restored."
|
||||||
|
echo "$backup_file" >>"$garbage"
|
||||||
}
|
}
|
||||||
|
|
||||||
## iterate over all user inputs
|
## iterate over all user inputs
|
||||||
|
|
@ -147,7 +156,7 @@ log "DEBUG" "The yes flag has been set to: $yes_flag." "$log_file"
|
||||||
## setup the no-notify (nn) flag if notify-send isn't installed
|
## setup the no-notify (nn) flag if notify-send isn't installed
|
||||||
command -v notify-send >/dev/null 2>&1 || nn_flag=0
|
command -v notify-send >/dev/null 2>&1 || nn_flag=0
|
||||||
nn_flag=${nn_flag:-1}
|
nn_flag=${nn_flag:-1}
|
||||||
## set the testing flag if not already
|
## set the debugging flag if not already
|
||||||
debug_run=${debug_run:-1}
|
debug_run=${debug_run:-1}
|
||||||
[[ $debug_run -eq 0 ]] && log "DEBUG" "The mode flag has been set so script will operate in debug mode." "$log_file"
|
[[ $debug_run -eq 0 ]] && log "DEBUG" "The mode flag has been set so script will operate in debug mode." "$log_file"
|
||||||
|
|
||||||
|
|
@ -199,8 +208,7 @@ 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..." ;
|
[[ ! $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 "ERROR" "Encountered an issue with wget. Exiting...(4)" "$log_file" ; exit 4 ; }
|
||||||
log "DEBUG" "Successfully downloaded release contents information." "$log_file"
|
log "DEBUG" "Successfully downloaded release contents information." "$log_file"
|
||||||
|
## decompress the packages file
|
||||||
### :@TODO: continue with TODO list. Finish off above code section to ensure wget is successful and logging appropriately.
|
|
||||||
log "DEBUG" "Uncompressing downloaded gz file using gunzip, $tmp_path/Packages.gz..." "$log_file"
|
log "DEBUG" "Uncompressing downloaded gz file using gunzip, $tmp_path/Packages.gz..." "$log_file"
|
||||||
## force gunzip to overwrite decompressed file if it already exists
|
## force gunzip to overwrite decompressed file if it already exists
|
||||||
gunzip -f "$tmp_path/Packages.gz" "$tmp_path/Contents-$archi.gz" >/dev/null 2>&1
|
gunzip -f "$tmp_path/Packages.gz" "$tmp_path/Contents-$archi.gz" >/dev/null 2>&1
|
||||||
|
|
@ -328,8 +336,8 @@ if [[ ! -f "$tmp_path/$filename" ]] ; then
|
||||||
"Please check $logs_dir/updater.log, for more information. Exiting update..." ;
|
"Please check $logs_dir/updater.log, for more information. Exiting update..." ;
|
||||||
log "DEBUG" "Encountered an issue with wget. Exiting...(6)" "$log_file" ; exit 6 ; }
|
log "DEBUG" "Encountered an issue with wget. Exiting...(6)" "$log_file" ; exit 6 ; }
|
||||||
awk -v end=$(grep -n '^\s*$' "$tmp_path/wget_dump.log" | tr '\n' ' ' | cut -d: -f1) 'NR>1*0&&NR<1*end+1' "$tmp_path/wget_dump.log" >> "$log_file"
|
awk -v end=$(grep -n '^\s*$' "$tmp_path/wget_dump.log" | tr '\n' ' ' | cut -d: -f1) 'NR>1*0&&NR<1*end+1' "$tmp_path/wget_dump.log" >> "$log_file"
|
||||||
log "DEBUG" "Download completed successfully in $(echo $wget_timed | cut -d' ' -f2)s, wget log below." "$log_file"
|
log "DEBUG" "Download completed successfully, wget log shown above." "$log_file"
|
||||||
printf "Download complete in $(echo $wget_timed | cut -d' ' -f2)s. Validating checksums..."
|
printf "Download complete. Validating checksums..."
|
||||||
else
|
else
|
||||||
log "DEBUG" "File already downloaded to system. Skipped download and verifying checksum..." "$log_file"
|
log "DEBUG" "File already downloaded to system. Skipped download and verifying checksum..." "$log_file"
|
||||||
printf "Latest Debian release file is downloaded to the system, skipping download. Validating checksums..."
|
printf "Latest Debian release file is downloaded to the system, skipping download. Validating checksums..."
|
||||||
|
|
@ -371,7 +379,6 @@ rm -r "$tmp_path/etc/"
|
||||||
echo "$tmp_path/data.tar.xz" >> "$garbage"
|
echo "$tmp_path/data.tar.xz" >> "$garbage"
|
||||||
|
|
||||||
# compress archive the currently installed version of Edge (Beta) for restoration on failure
|
# compress archive the currently installed version of Edge (Beta) for restoration on failure
|
||||||
## :@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"
|
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..."
|
printf "Installing new version to system. This may take a few minutes..."
|
||||||
archive_system "microsoft/msedge-beta"
|
archive_system "microsoft/msedge-beta"
|
||||||
|
|
@ -385,7 +392,7 @@ fi
|
||||||
log "DEBUG" "Successfully created an archive gzip tarball of the system. Safe to continue with installation." "$log_file"
|
log "DEBUG" "Successfully created an archive gzip tarball of the system. Safe to continue with installation." "$log_file"
|
||||||
|
|
||||||
### :@NOTE: used to terminate the program at a certain point for incremental testing of functionality recently added up to the point of this exit.
|
### :@NOTE: used to terminate the program at a certain point for incremental testing of functionality recently added up to the point of this exit.
|
||||||
#exit 0
|
### exit 0
|
||||||
|
|
||||||
# install the new version to system
|
# install the new version to system
|
||||||
log "DEBUG" "Copying files to there appropriate location..." "$log_file"
|
log "DEBUG" "Copying files to there appropriate location..." "$log_file"
|
||||||
|
|
@ -440,8 +447,11 @@ if [[ "$(microsoft-edge-beta --version | cut -d' ' -f3)" != "$release_version" ]
|
||||||
exit 11
|
exit 11
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## end of update. Inform user of time taken to complete, notify and log.
|
||||||
elapsed_time=$SECONDS
|
elapsed_time=$SECONDS
|
||||||
script_time="$(($elapsed_time / 60))m $(($elapsed_time % 60))s"
|
script_time="$(($elapsed_time / 60))m $(($elapsed_time % 60))s"
|
||||||
log "DEBUG" "Installation and update was successful (completed in: $script_time) and system can be cleaned up to remove any waste." "$log_file"
|
log "DEBUG" "Installation and update was successful (completed in: $script_time) and system can be cleaned up to remove any waste." "$log_file"
|
||||||
echo "Microsoft Edge (Beta) has been successfully updated to the latest version: v$current_version -> v$release_version, in $script_time."
|
echo "Microsoft Edge (Beta) has been successfully updated to the latest version: v$current_version -> v$release_version, in $script_time."
|
||||||
[[ ! $nn_flag -eq 0 ]] && notify "Microsoft Edge (Beta) Update" "Successfully updated Microsoft Edge (Beta) to the latest version: v$release_version"
|
[[ ! $nn_flag -eq 0 ]] && notify "Microsoft Edge (Beta) Update" "Successfully updated Microsoft Edge (Beta) to the latest version: v$release_version"
|
||||||
|
|
||||||
|
# exit of script, clean up function is called now by default exit of script (EOF)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user