-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathupdate-all.sh
executable file
·181 lines (139 loc) · 3.53 KB
/
update-all.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
# To execute run:
#
# zsh update-all.sh
#
# To source and then use individual update-* functions
# first comment out the command at the bottom of the file
# and run:
#
# source ./update-all.sh
#
# If you want to use this command often copy it to directory
# that you have in PATH (check with `echo $PATH`) like this:
#
# USER_SCRIPTS="${HOME}/.local/bin" # change this
# cp ./update-all.sh $USER_SCRIPTS/update-all
# chmod +x $USER_SCRIPTS/update-all
#
# and now you can call the script any time :)
# Text Color Variables
readonly RED='\033[31m' # Red
readonly GREEN='\033[32m' # Green
readonly CLEAR='\033[0m' # Clear color and formatting
println() {
printf "\n${GREEN}%s${CLEAR}\n" "$*" 2>/dev/null
}
print_err() {
printf "\n${RED}%s${CLEAR}\n" "$*" >&2
}
check_command() {
command_name="$1"
if ! command -v "${command_name}" >/dev/null 2>&1; then
print_err "${command_name} is not installed."
return 1
fi
return 0
}
update_brew() {
println "Updating Brew Formula's"
if ! check_command brew; then
return
fi
brew update && brew upgrade && brew cleanup -s
println "Brew Diagnostics"
brew doctor && brew missing
}
update_vscode() {
println "Updating VSCode Extensions"
if ! check_command code; then
return
fi
code --update-extensions
}
update_office() {
println "Updating MS-Office"
readonly MS_OFFICE_UPDATE='/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/msupdate'
if [ ! -f "${MS_OFFICE_UPDATE}" ]; then
print_err "MS-Office update utility is not installed."
return
fi
"${MS_OFFICE_UPDATE}" --install
}
update_gem() {
println "Updating Gems"
if ! check_command gem; then
return
fi
gem update --user-install && gem cleanup --user-install
}
update_npm() {
println "Updating Npm Packages"
if ! check_command npm; then
return
fi
npm update -g
}
update_yarn() {
println "Updating Yarn Packages"
if ! check_command yarn; then
return
fi
yarn upgrade --latest
}
update_cargo() {
println "Updating Rust Cargo Crates"
if ! check_command cargo; then
return
fi
cargo install --list | grep -E '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ' | xargs cargo install
}
update_app_store() {
println "Updating App Store Applications"
if ! check_command mas; then
return
fi
mas upgrade
}
update_macos() {
println "Updating MacOS"
softwareupdate -i -a
}
check_internet() {
if ! check_command curl; then
print_err "Error: curl is required but not installed. Please install curl."
return 1
fi
# Check internet connection by pinging a reliable server
TEST_URL="https://www.google.com"
# Use curl to check the connection
TEST_RESP=$(curl -Is --connect-timeout 5 --max-time 10 "${TEST_URL}" 2>/dev/null | head -n 1)
# Check if response is empty
if [ -z "${TEST_RESP}" ]; then
print_err "No Internet Connection!!!"
return 1
fi
# Check for "200" in the response
if ! printf "%s" "${TEST_RESP}" | grep -q "200"; then
print_err "Internet is not working!!!"
return 1
fi
return 0
}
update_all() {
# Check if internet is available
if ! check_internet; then
exit 1
fi
update_brew
update_office
update_vscode
update_gem
update_npm
update_yarn
update_cargo
update_app_store
update_macos
}
# COMMENT OUT IF SOURCING
update_all