-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·283 lines (264 loc) · 7.79 KB
/
update.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#! /usr/bin/env bash
function format_output() {
local red="\033[0;31m"
local yellow="\033[1;33m"
local no_color="\033[0m"
case $1 in
red)
printf "${red}${2}${no_color}\n"
;;
yellow)
printf "${yellow}${2}${no_color}\n"
;;
*)
printf "Unsupported color.\n"
;;
esac
}
# input processors
function print_greeting() {
printf "Which of the following do you want to update, ${USER^}?\n"
printf "Hint: Either type the highlighted letters below or the words themselves.\n"
printf "GNU/[L]inux [N]ode.js [G]lobalNPMPackages [O]hMyZsh T[M]ux [A]ll [E]xit\n\n"
}
function read_command() {
read -p "Update: " update_choice
printf "\n"
distinguish_command "$update_choice"
}
function distinguish_command() {
local update_choice_length=${#1}
if [ $update_choice_length == "1" ]; then
process_short_command "${1,,}"
else
process_long_command "${1,,}"
fi
}
function process_short_command() {
case $1 in
l)
update_gnulinux
;;
n)
update_node
;;
g)
update_npm_global_packages
;;
o)
update_oh_my_zsh
;;
# t)
# update_tkg
# ;;
m)
update_tmux
;;
a)
update_everything
;;
e)
update_nothing
;;
*)
update_not_sure
;;
esac
}
function process_long_command() {
case $1 in
linux)
update_gnulinux
;;
node)
update_node
;;
nodejs)
update_node
;;
node.js)
update_node
;;
npmglobalpackages)
update_npm_global_packages
;;
ohmyzsh)
update_oh_my_zsh
;;
tkg)
update_tkg
;;
tmux)
update_tmux
;;
all)
update_everything
;;
exit)
update_nothing
;;
*)
update_not_sure
;;
esac
}
# updaters
function update_gnulinux() {
printf "==> Updating GNU/Linux and your packages\n"
sudo systemctl start reflector
if [[ $(pacman -Qi paru) ]]; then
paru -Syu --noconfirm
elif [[ $(pacman -Qi yay) ]]; then
yay -Syu --noconfirm
else
sudo pacman -Syu --noconfirm
fi
remove_unused_pacman_packages
format_output "yellow" "Your GNU/Linux system and packages are now up to date!"
}
function remove_unused_pacman_packages() {
printf "==> Attempting to remove unused pacman packages\n"
local unused_packages=$(sudo pacman -Qtdq)
if [ -z $(echo "$unused_packages" | tail -n 1) ]; then
format_output "yellow" "No unused packages were found"
else
format_output "yellow" "Unused packages were found"
printf "==> Removing unused packages\n"
echo "$unused_packages" | sudo pacman --noconfirm -Rns -
format_output "yellow" "Unused packages were removed."
fi
}
function update_node() {
if [ -d /usr/share/nvm/ ]; then
printf "==> Updating Node and NPM\n"
. /usr/share/nvm/nvm.sh
update_node_via_nvm
elif [ -d ~/.nvm/ ]; then
. ~/.nvm/nvm.sh
update_node_via_nvm
else
format_output "red" "Missing package: NVM\n"
read_command
fi
}
function update_node_via_nvm() {
local old_version=$(nvm current | sed -n -e 's/v//p')
local versions=$(nvm ls-remote --lts)
wait
local latest_version=$(echo "$versions" | grep -P -o "\d+\.\d+\.\d+" | tail -n 1)
echo "Current version: $old_version"
echo "Latest LTS version: $latest_version"
if [[ $old_version == $latest_version ]]; then
format_output "yellow" "Your local version of Node.js is already up to date!"
else
format_output "red" "Your local version of Node.js is outdated."
printf "==> Installing the latest LTS version of Node.js.\n"
format_output "red" "WARNING: This will uninstall Node ${old_version} but keep your global NPM packages."
format_output "red" "WARNING: This also installs an LTS version of Node.js.\n"
nvm install node --lts
nvm alias default node
nvm reinstall-packages $old_version
nvm uninstall $old_version
nvm use default
format_output "red" "WARNING: Node.js v${old_version} was uninstalled!"
format_output "yellow" "The Node.js LTS v${latest_version} was installed!"
fi
}
function update_npm_global_packages() {
printf "==> Updating your NPM global packages\n"
npm update --location=global
format_output "yellow" "Packages updated!"
}
function update_oh_my_zsh() {
# local current_directory=$(pwd)
printf "==> Updating Oh My Zsh\n"
zsh -c "source $ZSH/oh-my-zsh.sh && omz update"
# if [ -d $XDG_DATA_HOME/oh-my-zsh ]; then
# cd $XDG_DATA_HOME/oh-my-zsh
# else
# cd ~/.oh-my-zsh
# fi
# git pull --ff-only
# cd "$current_directory"
format_output "yellow" "Oh My Zsh has been updated!"
}
function update_tkg() {
local current_directory=$(pwd)
printf "==> Updating/Installing TKG Proton and Wine\n"
tkg_github_repo="Frogging-Family/wine-tkg-git"
tkg_proton_download_link=$(curl -s https://api.github.com/repos/${tkg_github_repo}/releases/latest | grep -P -o https\:\/\/.*\.release\.tar... | head -n 1)
tkg_wine_download_link=$(curl -s https://api.github.com/repos/${tkg_github_repo}/releases/latest | grep -P -o https\:\/\/.\*\.zst | head -n 1)
if [[ -d "/tmp/tkg" ]]; then
cd /tmp/tkg
else
mkdir /tmp/tkg && cd /tmp/tkg
fi
install_tkg_proton $tkg_proton_download_link
#install_tkg_wine $tkg_wine_download_link
rm -rf /tmp/tkg
cd "$current_directory"
}
function install_tkg_proton() {
local install_directory="/home/${USER}/.steam/root/compatibilitytools.d"
curl -L -o proton-tkg.tar.xz $1
mkdir Proton-TKG
tar xzf proton-tkg.tar.xz --directory="/tmp/tkg/Proton-TKG" --strip-components=1
rm proton-tkg.tar.xz
if [[ ! -d "$install_directory" ]]; then
mkdir -p "$install_directory"
printf "==> Steam compatibility tools directory missing. Created directory.\n"
fi
if [[ -d "$install_directory/Proton-TKG" ]]; then
rm -rf "$install_directory/Proton-TKG"
format_output "red" "==> Deleted old TKG folder"
fi
mv Proton-TKG "$install_directory"
format_output "yellow" "Proton-TKG has been installed!"
}
function install_tkg_wine() {
curl -L -o wine-tkg.zst $1
sudo pacman -U wine-tkg.zst
format_output "yellow" "Wine-TKG has been installed!"
}
function update_tmux() {
printf "==> Updating Tmux plugins via TPM\n"
if [ -d ~/.tmux/plugins/tpm/bin/ ]; then
update_tpm "~/.tmux"
elif [ -d ~/.config/tmux/plugins/tpm/bin/ ]; then
update_tpm "/home/$USER/.config/tmux"
else
format_output "red" "Tmux Plugin Manager not found\n"
fi
}
function update_tpm() {
sh "$1/plugins/tpm/bin/update_plugins" all
format_output "yellow" "Your Tmux plugins are now up to date!"
}
function update_everything() {
format_output "yellow" "==> Updating entire system"
update_gnulinux
printf "\n"
update_node
printf "\n"
update_npm_global_packages
printf "\n"
update_oh_my_zsh
printf "\n"
update_tmux
format_output "yellow" "\nThe entire system is up-to-date!"
}
function update_nothing() {
printf "Cancelling update process.\n"
printf "No changes to the system were made.\n"
exit 1
}
function update_not_sure() {
printf "Ummm... okay, let's do this again.\n"
print_greeting
read_command
}
function main() {
print_greeting
read_command
}
main