-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdating_system.sh
55 lines (40 loc) · 2.67 KB
/
updating_system.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
log_error_location='/root/Desktop' # Defining a location to store the error log that will be generated.
time_for_update=600 # Time limit for 'update'.
time_for_upgrade=600 # Time limit for 'upgrade'.
echo -e "Executing update...\n\n"
error_update=$(timeout $time_for_update sudo apt-get update 2>&1 > /dev/null) # Executing the 'update' command with a
# limit of 5 minutes to its conclusion. Capturing the STDERR, if it generates any error.
update_status=$? # Storing the exit status from the 'update' command.
if [ $update_status -ne 0 ]; then # Checking if the 'update' command wasn't successful:
echo; echo
echo "Update failed. Code: $update_status" # Printing a error message and the code returned by the 'update' function
echo -n "$(date): " >> "$log_error_location/error.log"
echo -n "[Status]: $update_status - " >> "$log_error_location/error.log"
echo -ne "Update failed: ($error_update)\n" >> "$log_error_location/error.log"
# Storing the STDERR and the exit status from the 'update' command into a log file.
exit $update_status # Exiting the script using the status from 'update' command.
else # If the 'update' command is successful, the script follows to executing the 'upgrade' command:
echo; echo
echo "Update successful. Code: $update_status"; echo "Executing upgrade..." # Printing a message that the 'update'
# was successful.
echo; echo
error_upgrade=$(timeout $time_for_upgrade echo "yes" | sudo apt-get upgrade 2>&1 > /dev/null) # Executing the
# 'upgrade' command with a limit for 10 minutes for the conclusion. Also capturing the STDERR generated by the command,
# if it generates any error.
upgrade_status=$? # Capturing the exit status from 'upgrade'.
if [ $upgrade_status -ne 0 ]; then # Checking if the execution of 'upgrade' wasn't successful:
echo; echo
echo "Upgrade failed. Code: $upgrade_status" # Printing a error message and the exit status from 'upgrade'
echo -n "$(date): " >> "$log_error_location/error.log"
echo -n "[Status]: $upgrade_status - " >> "$log_error_location/error.log"
echo -ne "Upgrade failed: ($error_upgrade)\n" >> "$log_error_location/error.log"
# Storing the STDERR and log status generated by the 'upgrade' command into a log file.
exit $upgrade_status # Exiting the script with the exit status returned by 'upgrade' command.
else # If the 'upgrade' command was successfully executed:
echo; echo
echo "Upgrade successful. Code: $upgrade_status"; echo "Finishing updating procedure..." # Printing a successful
# message using the exit status from 'upgrade'.
exit $upgrade_status # Exiting the script using the exit status from 'upgrade' command.
fi
fi