-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_system.sh
65 lines (55 loc) · 1.57 KB
/
update_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
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Exit on error, but don't exit on pipefail
set -eo pipefail
# Function to print colored output
print_color() {
case $1 in
"green") echo -e "\033[0;32m$2\033[0m" ;;
"red") echo -e "\033[0;31m$2\033[0m" ;;
"yellow") echo -e "\033[0;33m$2\033[0m" ;;
esac
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to update the system
update_system() {
print_color "yellow" "Updating system packages..."
if command_exists nala; then
sudo nala upgrade
elif command_exists apt-get; then
sudo apt-get update && sudo apt-get upgrade
else
print_color "red" "No supported package manager found. Skipping system update."
return 1
fi
}
# Function to update Flatpak
update_flatpak() {
if command_exists flatpak; then
print_color "yellow" "Updating Flatpak applications..."
flatpak update 2>/dev/null || print_color "red" "Flatpak update encountered an error, but continuing..."
else
print_color "yellow" "Flatpak not found. Skipping Flatpak update."
fi
}
# Function to update Snap
update_snap() {
if command_exists snap; then
print_color "yellow" "Updating Snap packages..."
sudo snap refresh
else
print_color "yellow" "Snap not found. Skipping Snap update."
fi
}
# Main function
main() {
print_color "green" "Starting system update..."
update_system
update_flatpak
update_snap
print_color "green" "System update completed successfully!"
}
# Run the main function
main