This repository has been archived by the owner on Mar 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwowutils
executable file
·427 lines (388 loc) · 10.2 KB
/
wowutils
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/bin/bash
# WoWutils, WoW addon handler.
# Copyright (C) 2015 Kaan Genç
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# Set the defaults
WOW_DIR=
BACKUP_DIR="."
URL_PREFIX="http://www.curse.com/addons/wow/"
URL_SUFFIX="/download"
DOWNLOAD_EXTRACT_REGEXP='(?<=data-href=")\S*(?=")'
USER_AGENT=
WGET_ARGS="--no-verbose"
UNZIP_ARGS="-q -u -o"
TAR_ARGS="-acf"
UNTAR_ARGS="--keep-newer-files -xf"
BACKUP_DATE="+%F_%H.%M.%S"
BACKUP_SUFFIX="_wowutil_backup.tar.gz"
SCRIPT_NAME=$(basename $0)
# Load the configuration
[[ -f "$HOME/.wowutils" ]] && . "$HOME/.wowutils"
[[ -f "$HOME/.config/wowutils" ]] && . "$HOME/.config/wowutils"
[[ -n "$XDG_CONFIG_HOME" && -f "$XDG_CONFIG_HOME/wowutils" ]] && . "$XDG_CONFIG_HOME/wowutils"
[[ -n $USER_AGENT ]] && WGET_ARGS+=" --user-agent='$USER_AGENT'"
WOW_ADDON_SUF="Interface/AddOns"
WOW_CACHE_SUF="Cache"
WOW_WTF_SUF="WTF"
WOW_ADDON_DIR="$WOW_DIR/$WOW_ADDON_SUF"
WOW_CACHE_DIR="$WOW_DIR/$WOW_CACHE_SUF"
WOW_WTF_DIR="$WOW_DIR/$WOW_WTF_SUF"
help () {
case "$1" in
"download")
cat <<EOF
Usage: $SCRIPT_NAME download <addons>...
Description:
Download the addons from Curse into the current folder.
EOF
;;
"extract")
cat <<EOF
Usage: $SCRIPT_NAME extract <addon_file.zip>...
Description:
Extract the addon archives into the World of Warcraft folder.
EOF
;;
"install")
cat <<EOF
Usage: $SCRIPT_NAME install <addons>...
Description:
Download and extract the addons into World of Warcraft folder.
EOF
;;
"update")
cat <<EOF
Usage: $SCRIPT_NAME update
Description:
Update all Curse Project addons.
Not all addons hosted at Curse are Curse Project addons,
so this command may miss some addons. Also, the command
doesn't check if there are new versions, just tries to
update all addons.
EOF
;;
"list")
cat <<EOF
Usage: $SCRIPT_NAME list
Description:
List all Curse Project addons.
Not all addons hosted at Curse are Curse Project addons,
so this command may miss some addons. The addons listed
here are the ones that will be updated by the update
command.
EOF
;;
"describe")
cat <<EOF
Usage: $SCRIPT_NAME describe <addon_name>
Description:
Print information about an addon, such as the addon description,
addon web page etc.
EOF
;;
"backup")
cat <<EOF
Usage: $SCRIPT_NAME backup
Description:
Creates a backup of all installed addons and addon settings.
The backup will be created at '$BACKUP_DIR'.
If this path is relative, it will start at '$WOW_DIR'.
EOF
;;
"restore")
cat <<EOF
Usage: $SCRIPT_NAME restore <*$BACKUP_SUFFIX>
Description:
Restore the backup archive, extracting it into your
World of Warcraft directory.
EOF
;;
"clean")
cat <<EOF
Usage: $SCRIPT_NAME clean
Description:
Cleans your World of Warcraft Cache directory, which contains
temporary files used by the game.
EOF
;;
"purge")
cat <<EOF
Usage: $SCRIPT_NAME purge
Description:
Deletes all installed addons, addon settings and cache.
Please note that this is not reversible, all addons and
addon settings will be fully deleted.
EOF
;;
"config")
cat <<EOF
Configuration:
$SCRIPT_NAME can be configured via configuration files placed at:
* \$XDG_CONFIG_HOME/wowutils
* $HOME/.config/wowutils
* $HOME/.wowutils
$SCRIPT_NAME will execute these files in the given order if they exist.
Please note that these files will be executed with bash.
You can get an example configutaion file by executing
# $SCRIPT_NAME config > ~/.wowutils
Only one variable in the configuration file is mandatory: WOW_DIR.
WOW_DIR must be set to the directory containing your WoW installation.
This is the folder that contains the Wow.exe.
EOF
;;
"curse")
cat <<EOF
Usage: $SCRIPT_NAME curse <curse://addon/uri>
Description:
Downloads and installs an addon like install command, however curse
command accepts a Curse URI. This command is intended to
be used together with a desktop file to handle the URI scheme, so
that the user can click on the "Download with Curse Client" button
and download the addon with WoWUtils.
EOF
;;
*)
cat <<EOF
Command line updater for WoW addons, using Curse addons.
Usage: $SCRIPT_NAME <command> [<args>...]
Commands:
download Download the addons.
extract Extract the given file into addons folder.
install Download and install addons.
update Update all installed addons.
list List installed addons.
describe Print information about an installed addon.
backup Create a backup of all installed addons and addon settings.
restore Restore a backup.
clean Delete the WoW cache.
purge Delete the WoW cache, all installed addons and addon settings.
config Print an example configuration file.
curse Download and install addon, intended to handle curse:// protocol.
help Print this help.
Run $SCRIPT_NAME help <command> to see details for each command.
EOF
;;
esac
}
config () {
cat <<EOF
# Path to your WoW install, the directory containing Wow.exe.
WOW_DIR="/example/dir"
# The directory where the backups will be saved. Note that relative
# paths will start from WOW_DIR. Saved to WOW_DIR by default.
BACKUP_DIR="."
# The file suffix used for backups.
# You can change the file extension to change the compression format.
BACKUP_SUFFIX="_wowutil_backup.tar.gz"
# The format string used while naming backups. See 'man date' for details.
BACKUP_DATE="+%F_%H.%M.%S"
# User agent used while downloading the addons. Passed to wget with --user-agent.
# Leave it empty to use the default.
USER_AGENT=
EOF
}
check_wow_dir () {
[[ -d "$WOW_ADDON_DIR" && \
-d "$WOW_CACHE_DIR" && \
-d "$WOW_WTF_DIR" ]] && return 0
return 1
}
check_backup_dir () {
if ! [[ -d "$BACKUP_DIR" ]]; then
echo "BACKUP_DIR doesn't exist or is not a directory. Please check your config." >&2
exit 1
fi
}
check () {
# Make sure the WoW directory is correct
if [[ -z "$WOW_DIR" ]]; then
echo "WOW_DIR is not set. See $SCRIPT_NAME help for details." >&2
exit 1
elif ! check_wow_dir ; then
echo "WOW_DIR does not point to a WoW installation. See $SCRIPT_NAME help for details." >&2
exit 1
fi
}
download () {
local NAME=$1
local DIRECTORY=$2
local URL=$URL_PREFIX$NAME$URL_SUFFIX
local TEMP_FILE=$(mktemp --tmpdir="$DIRECTORY" "$SCRIPT_NAME.$NAME.XXXXXXXXXX")
wget $WGET_ARGS -O - "$URL" | \
grep -Po "$DOWNLOAD_EXTRACT_REGEXP" | \
wget $WGET_ARGS -i - -O "$TEMP_FILE"
echo $TEMP_FILE
}
extract () {
local FILE_NAME=$1
echo "Extracting archive $FILE_NAME"
unzip $UNZIP_ARGS -d "$WOW_ADDON_DIR" "$FILE_NAME"
}
install () {
local NAME=$1
echo "Installing $NAME"
local TEMP_FILE="$(download $NAME)"
extract "$TEMP_FILE"
rm "$TEMP_FILE"
}
backup () {
local BACKUP_NAME="$(date $BACKUP_DATE)$BACKUP_SUFFIX"
local PWD="$(pwd)"
cd "$WOW_DIR"
echo "Creating backup archive $BACKUP_DIR/$BACKUP_NAME"
tar $TAR_ARGS "$BACKUP_DIR/$BACKUP_NAME" "$WOW_ADDON_SUF" "$WOW_WTF_SUF"
check_backup "$BACKUP_DIR/$BACKUP_NAME"
cd "$PWD"
}
check_backup () {
local BACKUP_NAME=$1
if tar -t -f "$BACKUP_NAME" "$WOW_ADDON_SUF" "$WOW_WTF_SUF" 1>/dev/null ; then
echo "Backup seems correct."
else
echo "Backup is incorrect or corrupted." >&2
exit 1
fi
}
restore () {
local BACKUP_NAME=$1
local PWD="$(pwd)"
cd "$WOW_DIR"
echo "Restoring backup archive $BACKUP_NAME"
tar $UNTAR_ARGS "$BACKUP_NAME"
cd "$PWD"
}
get_version () {
# Extact the version from the given .toc file
local TOC=$1
sed -nr "s/^## X-Curse-Packaged-Version: //gp" "$TOC"
}
get_name () {
# Extract the name from the given .toc file
local TOC=$1
sed -nr "s/^## X-Curse-Project-ID: //gp" "$TOC" 2>/dev/null
}
get_description () {
# Construct a human readable description for the addon based on given .toc file
local TOC="$WOW_ADDON_DIR/$1/$1.toc"
local TITLE=$(sed -nr "s/^## X-Curse-Project-Name: //gp" "$TOC")
local VERSION=$(get_version "$TOC")
local CATEGORY=$(sed -nr "s/^## X-Category: //gp" "$TOC")
local NOTES=$(sed -nr "s/^## Notes: //gp" "$TOC")
local WEBSITE=$(sed -nr "s/^## X-Website: //gp" "$TOC")
cat <<EOF
--> $TITLE
Version: $VERSION
Category: $CATEGORY
Website: $WEBSITE
$NOTES
EOF
}
list_names () {
for TOC in "$WOW_ADDON_DIR"/*/*.toc ; do
[[ -n "$(get_name $TOC)" ]] && basename -s ".toc" "$TOC"
done
}
update () {
for ADDON in $(grep --no-filename -oP "(?<=^## X-Curse-Project-ID: )\S*" "$WOW_ADDON_DIR"/*/*.toc | awk '!a[$0]++') ; do
install "$ADDON"
done
}
COMMAND=$1
shift
case $COMMAND in
"download")
while (( "$#" )); do
download "$1" "."
shift
done
;;
"extract")
check
while (( "$#" )); do
extract "$1"
shift
done
;;
"install")
while (( "$#" )); do
install "$1"
shift
done
;;
"update")
update
echo "Updates done."
exit 0
;;
"list")
check
list_names
exit 0
;;
"describe")
check
while (( "$#" )); do
get_description $1
shift
done
exit 0
;;
"backup")
check
check_backup_dir
backup
;;
"restore")
check
check_backup $1
restore $1
exit 0
;;
"clean")
check
rm -rf "$WOW_CACHE_DIR"/*
;;
"purge")
check
echo "All addons and addon settings will be DELETED. Are you sure?"
select YN in "yes" "no"; do
case $YN in
"yes")
rm -rf "$WOW_CACHE_DIR"/*
rm -rf "$WOW_ADDON_DIR"/*
rm -rf "$WOW_WTF_DIR"/*
exit 0
;;
"no")
exit 0
;;
esac
done
;;
"config")
config
exit 0
;;
"curse")
install $(echo "$1" | grep -oP "(?<=wow-addons/)\S*?(?=/)")
sleep 2
exit 0
;;
"help"|*)
help $1
exit 0
;;
esac
exit 0