-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·80 lines (67 loc) · 2.25 KB
/
script.sh
File metadata and controls
executable file
·80 lines (67 loc) · 2.25 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
75
76
77
78
79
#!/usr/bin/env bash
set -euo pipefail
toc_file_path="$1"
default_product="$2"
region="us"
# See https://wowdev.wiki/TACT for list of products
# Usage: get_game_version PRODUCT
# PRODUCT - wow, wow_classic, wow_classic_era, etc.
function get_version_tact() {
local product="$1"
curl -s "http://us.patch.battle.net:1119/$product/versions"
}
# Usage: get_game_version TACT REGION
# TACT - contents of version TACT
# REGION - us, eu, cn, kr, tw, sg, or xx
function get_game_version() {
local tact="$1"
local region="$2"
printf "%s" "$tact" | awk -F "|" "\$1 ~ /^$region/{print \$6}"
}
# Usage: game_version_to_toc_version GAME_VERSION
# GAME_VERSION - Game version string such as 10.1.0
# Returns the toc version, such as 100100
function game_version_to_toc_version() {
local game_version="$1"
echo "$game_version" | awk -F "." '{ printf "%d%02d%02d", $1, $2, $3 }'
}
# Usage: update_toc_version TOC_FILE SUFFIX VERSION
# TOC_FILE - path to the toc file
# SUFFIX - the suffix to use for the interface key (e.g. "-Classic")
# VERSION - the replacement version number
function update_toc_version() {
local toc_file="$1"
local suffix="$2"
local version="$3"
sed -i -E "s/(## Interface$suffix: )[0-9]+/\1$version/g" "$toc_file"
}
products=(wow wow_classic_era wow_classic)
declare -A version_suffixes
version_suffixes["wow_classic_era"]="-Classic"
version_suffixes["wow_classic"]="-Mists"
# Usage: is_product_in_toc TOC_FILE SUFFIX
# TOC_FILE - path to the toc file
# SUFFIX - interface version suffix to check for
function is_product_in_toc() {
local toc_file="$1"
local suffix="$2"
if [[ -n "$suffix" && -n $(cat "$toc_file" | grep "## Interface$suffix: ") ]]; then
echo true
else
echo false
fi
}
for product in "${products[@]}"; do
suffix="${version_suffixes[$product]:=}"
if [[ "$product" = "$default_product" || $(is_product_in_toc "$toc_file_path" "$suffix") = "true" ]]; then
tact=$(get_version_tact "$product")
game_version=$(get_game_version "$tact" "$region")
toc_version=$(game_version_to_toc_version "$game_version")
if [[ -n "$suffix" ]]; then
update_toc_version "$toc_file_path" "$suffix" "$toc_version"
fi
if [[ "$product" = "$default_product" ]]; then
update_toc_version "$toc_file_path" "" "$toc_version"
fi
fi
done