Repository navigation
Expand file tree
/
Copy pathupdate
More file actions
executable file
·74 lines (69 loc) · 3.22 KB
/
Copy pathupdate
File metadata and controls
executable file
·74 lines (69 loc) · 3.22 KB
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
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# Simple bash script to update macOS and utilities.
# Usage: "update os" or "update tools" or "update os tools" or "update"
# Updated: November 2020 (Reviewed: February 2025)
macOS_updater() {
printf "\n\e[32m[+]\e[0m Starting macOS Update...\n"
printf "Warning: This will restart your system. Continue? (y/N) "
read -r response
[[ "$response" =~ ^[Yy]$ ]] || { printf "\t\e[31m[✘]\e[0m Update aborted\n"; exit 1; }
sudo softwareupdate --all --install --force --verbose --restart || {
printf "\t\e[31m[✘]\e[0m macOS update failed\n"; exit 1;
}
printf "\n\n"
}
utils_runner() {
trap 'printf "\t\e[31m[✘]\e[0m Caught Signal\n"; exit 1' SIGINT SIGTERM SIGTSTP
if [ "$SYSTEM" == "Darwin" ]; then
command -v mas >/dev/null || { printf "\t\e[31m[✘]\e[0m mas not installed\n"; exit 1; }
command -v brew >/dev/null || { printf "\t\e[31m[✘]\e[0m brew not installed\n"; exit 1; }
printf "\n\e[32m[+]\e[0m Starting Mac App Store Apps update...\n"
/usr/local/bin/mas upgrade || { printf "\t\e[31m[✘]\e[0m mas upgrade failed\n"; exit 1; }
printf "\n\e[32m[+]\e[0m Starting Brew Update...\n"
/usr/local/bin/brew update || { printf "\t\e[31m[✘]\e[0m brew update failed\n"; exit 1; }
/usr/local/bin/brew upgrade --cask || { printf "\t\e[31m[✘]\e[0m brew cask upgrade failed\n"; exit 1; }
/usr/local/bin/brew upgrade || { printf "\t\e[31m[✘]\e[0m brew upgrade failed\n"; exit 1; }
elif [ "$SYSTEM" == "Linux" ]; then
command -v brew >/dev/null || { printf "\t\e[31m[✘]\e[0m brew not installed\n"; exit 1; }
printf "\n\e[32m[+]\e[0m Starting Brew packages update...\n"
"$HOME/.linuxbrew/bin/brew" update || { printf "\t\e[31m[✘]\e[0m brew update failed\n"; exit 1; }
"$HOME/.linuxbrew/bin/brew" upgrade || { printf "\t\e[31m[✘]\e[0m brew upgrade failed\n"; exit 1; }
fi
printf "\n\e[32m[✔]\e[0m Utils update completed successfully!\n"
return 0
}
main() {
local SYSTEM cmd
SYSTEM=$(uname -s)
cmd=$(basename "$0")
if [ "$#" -gt 2 ]; then
printf "\t\e[31m[✘]\e[0m Too many arguments!\n"
exit 1
elif [ "$#" -eq 0 ]; then
utils_runner; exit 0
elif [ "$#" -eq 1 ]; then
if [ "$1" == "os" ]; then
if [ "$SYSTEM" == "Darwin" ]; then
macOS_updater; exit 0
elif [ "$SYSTEM" == "Linux" ]; then
( sudo apt update && sudo apt upgrade -y ) || { printf "\t\e[31m[✘]\e[0m apt update failed\n"; exit 1; }
exit 0
fi
elif [ "$1" == "tools" ]; then
utils_runner; exit 0
else
printf "\t\e[31m[✘]\e[0m Wrong option! Usage: '%s os' or '%s tools' or '%s os tools' or '%s'\n" "$cmd" "$cmd" "$cmd" "$cmd"
exit 2
fi
elif [ "$#" -eq 2 ]; then
if [ "$1" == "os" ] && [ "$2" == "tools" ]; then
macOS_updater && utils_runner; exit 0
else
printf "\t\e[31m[✘]\e[0m Wrong option! Usage: '%s os' or '%s tools' or '%s os tools' or '%s'\n" "$cmd" "$cmd" "$cmd" "$cmd"
exit 3
fi
fi
}
### MAIN:
[[ -n $BASH_VERSION ]] || { echo "This script requires Bash"; exit 1; }
main "$@"