diff --git a/updater b/updater index f911ef3..92a3c57 100755 --- a/updater +++ b/updater @@ -18,7 +18,7 @@ # Author: Ethan Smith-Coss # # Version: 0.1.4 # # Created: 2021-05-20T16:47+0100 # -# Last Modified: 2021-06-13T21:36+0100 # +# Last Modified: 2021-06-21T14:29+0100 # # # # #################################### # # # @@ -84,14 +84,28 @@ function clean_up { log "CLEANER" "Finished cleaning up system after session. Nice and clean :D Goodbye." "$runtime_dir/logs/updater.log" echo "done. Goodbye." - + elapsed_time=$SECONDS script_time="$(($elapsed_time / 60))m $(($elapsed_time % 60))s" log "END" "Total time for script execution was: $script_time" "$runtime_dir/logs/updater.log" echo >> "$runtime_dir/logs/updater.log" cat "$logs_dir/updater.log" >> "$logs_dir/updater.history" + + [[ $test_run -eq 0 ]] && cat "$logs_dir/updater.log" } + +function check_restoration { + [[ ! $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 ; } + log "DEBUG" "System restoration was successful, safe to use; however, the update was still failed. Exiting...($2+$1)" \ + "$log_file" + echo -e "completed. However, there was still an issue trying to update Microsoft Edge (Beta) to the latest version." \ + "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." \ + "The previous version, v$current_version, has been restored." +} + ## iterate over all user inputs while test $# -gt 0 ; do case $1 in @@ -109,6 +123,9 @@ while test $# -gt 0 ; do -nn | --no-notify) nn_flag=0 ; shift ;; + --dev-test) + test_run=0 ; shift + ;; *) shift ;; @@ -143,7 +160,7 @@ log "DEBUG" "Microsoft Edge (Beta) is installed to system. Proceeding with updat source_list="$runtime_dir/source.list" log "DEBUG" "Checking for a source.list in current runtime directory..." "$log_file" printf "Checking for source.list..." -[[ ! -f "$source_list" ]] && { echo -e "\nUpdater encountered an issue: source.list not found. Exiting..." ; +[[ ! -f "$source_list" ]] && { echo -e "\nUpdater encountered an issue: source.list not found. Exiting..." ; log "ERROR" "Cannot find source.list in runtime directory ($source_list). Exiting...(2)" "$log_file" ; exit 2 ; } log "DEBUG" "Found a souce.list in $runtime_dir." "$log_file" @@ -157,7 +174,7 @@ if ! wget --spider "$host" >/dev/null 2>&1 ; then echo "Cannot reach end-point for distribution information. Check your Internet connection and try again. Exiting..." log "DEBUG" "Upstream end-point is cannot be contacted. Potential Internet connection issue or end-point address ($dist_upstream). Exiting...(3)" "$log_file" [[ ! $nn_flag -eq 0 ]] && notify "Microsoft Edge (Beta) Update" "There seems to be an issue connecting to the end-point of Microsoft. Check your Internet connection and try again." - + exit 3 fi log "DEBUG" "Host is known and reachable. Continuing update to fetch data..." "$log_file" @@ -230,13 +247,13 @@ fi ##"${upgradeable:=1}" upgradeable=${upgradeable:-1} ## check if we can upgrade, can exit 1 for passive exit - exit not notifying a failure for another reason -if [[ $upgradeable -eq 1 ]] ; then +if [[ $upgradeable -eq 1 ]] ; then elapsed_time=$SECONDS script_time="$(($elapsed_time / 60))m $(($elapsed_time % 60))s" echo "Most recent version of Microsoft Edge (Beta) [v$current_version] is already installed on this system, no need to update. Finished in $script_time" log "DEBUG" "Most recent version of Microsoft Edge (Beta) is already installed to the system (v$current_version). Completed in $script_time. Exiting...(1)" "$log_file" [[ ! $nn_flag -eq 0 ]] && notify "Microsoft Edge (Beta) Update" "There is no newer version of Microsoft Edge (Beta) to install. Newest version is already installed: v$current_version" - + exit 1 fi log "DEBUG" "There is a more recent release of Microsoft Edge (Beta) available for download (v$release_version). Continuing with update." "$log_file" @@ -318,7 +335,7 @@ fi ## add the .deb file to garbage list echo "$tmp_path/$filename" >> "$garbage" -## verify the downloaded file +## verify the downloaded file if [[ "$(sha256sum "$tmp_path/$filename" | cut -d' ' -f1)" != "$(grep 'SHA256:.*' "$tmp_path/Release" | cut -d' ' -f2)" ]] ; then ## automatically remove the file - :@Ethan: it's either corrupt or hazardous to the health of the system rm "$tmp_path/$filename" @@ -370,14 +387,37 @@ 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" -cp -r "$tmp_path/opt" "/" >>"$log_file" 2>&1 +cp -ar "$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 ; } -cp -r "$tmp_path/usr" "/" >>"$log_file" 2>&1 +if [[ ! $exit_code -eq 0 ]] ; then + echo -ne "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" + + ## attempt restoration of system + restore_files "microsoft_msedge-beta" + return_code=$? + ## check the restoration was successful + check_restoration $return_code 9 + + exit 9 +fi + +cp -ar "$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 ; } +if [[ ! $exit_code -eq 0 ]] ; then + echo -ne "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" + + ## attempt restoration of system + restore_files "microsoft_msedge-beta" + return_code=$? + ## check the restoration was successful + check_restoration $return_code 9 + + exit 9 +fi log "DEBUG" "Successfully installed files to their appropriate location." "$log_file" echo "installation complete." ## add directories usr/ and opt/ to garbage @@ -385,20 +425,16 @@ echo "$tmp_path/usr" >> "$garbage" echo "$tmp_path/opt" >> "$garbage" ## confirm the update was successful - try to restore system otherwise -## :@TODO: validate new version has successfully installed properly - exit 12 if [[ "$(microsoft-edge-beta --version | cut -d' ' -f3)" != "$release_version" ]] ; then log "ERROR" "There was an issue with the update and installation. Restoring to previous version..." "$log_file" printf "Update was unsuccessful. Restoring to previous version..." ## attempt restoration of system - return_code=$(restore_files "microsoft/msedge-beta") - [[ $return_code -eq 12 ]] && { 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 $return_code ; } - log "DEBUG" "System restoration was successful, safe to use; however, the update was still failed. Exiting...(11)" "$log_file" - echo -e "completed. However, there was still an issue trying to update Microsoft Edge (Beta) to the latest version." \ - "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. The previous version, v$current_version, has been restored." - + restore_files "microsoft_msedge-beta" + return_code=$? + ## check the restoration was successful + check_restoration $return_code 11 + exit 11 fi