-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload
executable file
·115 lines (94 loc) · 2.46 KB
/
upload
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
#!/usr/bin/env bash
# Sane defaults.
set -euo pipefail
# Find scripts directory.
script="$0"
if test -L "$script"; then
script="$(readlink -f "$0")"
fi
prefix="$(dirname "$script")"
script="$(basename "$script")"
# Print the manual.
help() {
cat <<-EOF >&2
About
Upload distributable to CurseForge. Depends on jq.
Usage
$script -h
$script [-x] -t <token> <path>
Flags
-h Print this manual.
-x Enable debug mode.
-t CurseForge API token.
EOF
}
# Parse and apply flags.
while getopts ":xht:" option; do
case "$option" in
x)
set -x
;;
h)
help
exit
;;
t)
token="$OPTARG"
;;
?)
echo "$script: unknown flag '$OPTARG', try -h" >&2
exit
;;
esac
done
# Drop flags by shifting arguments.
shift $((OPTIND - 1))
# Test required arguments.
if test -z "$*"; then
echo "$script: missing required argument, see -h" >&2
exit
fi
# Test required flags.
if test -z "${token:-}"; then
echo "$script: missing required flag, see -h" >&2
exit
fi
# Test for jq.
if ! command -v jq >/dev/null; then
echo "$script: missing dependency 'jq'" >&2
exit 1
fi
# Add-on directory path, e.g. ./Add-on.
target="$1"
# Validate target.
"$prefix/inspect" -V "$target"
# Check for .curseforge file.
if ! test -f "$target/.curseforge"; then
echo "$script: '$target/.curseforge' is not a file" >&2
exit 1
fi
# Archive name, e.g. Add-on-v42.zip.
archive="$("$prefix/inspect" -a "$target")"
# Distributable directory, e.g. ./dist.
dist="$target/dist"
# Test archive.
if ! test -f "$dist/$archive"; then
echo "$script: '$dist/$archive' is not a file" >&2
exit 1
fi
# Read project id from .curseforge file.
project_id="$(jq .projectId "$target/.curseforge")"
# ...
interface="$("$prefix/inspect" -i "$target" | jq -Rc '[.]')"
# ...
curl -s "https://wow.curseforge.com/api/game/versions" -H "X-Api-Token: $token" \
| jq -c --argjson interface "$interface" '.[] | select([.apiVersion] | inside($interface)).id' > "$dist/gameVersions"
# Generate metadata. `$changelog` here is a jq variable.
jq --rawfile changelog "$dist/CHANGELOG.md" \
--slurpfile gameVersions "$dist/gameVersions" \
'.changelog = $changelog | .gameVersions = $gameVersions | del(.projectId)' "$target/.curseforge" > "$dist/metadata.json"
# Upload to CurseForge.
curl -vf -X POST "https://wow.curseforge.com/api/projects/$project_id/upload-file" \
-H "X-Api-Token: $token" \
-F "metadata=<$dist/metadata.json" \
-F "file=@$dist/$archive"