-
Notifications
You must be signed in to change notification settings - Fork 0
/
papermc-download-latest.sh
executable file
·51 lines (42 loc) · 1.75 KB
/
papermc-download-latest.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
#!/bin/bash
# Script implementing papermc API v2 to get latest release of give project version (paper / velocity / waterfall / ...)
# Author: Michael Gebetsroither <michael@mgeb.org>
# License: Apache 2
# Usage:
# MC_VERSION=1.21 MC_NAME=paper bash ~/papermc-download-latest.sh
# config
name_="${MC_NAME:-paper}"
version_="${MC_VERSION:-1.20}"
# internal
version_group_="$version_"
api_=https://papermc.io/api/v2
prefix_="$api_/projects/$name_"
die() {
echo "## ERROR: $*" >&2
exit 1
}
# get json from latest release from $version_group defined above
latest_build_json_="$(curl -sX GET "$prefix_/version_group/$version_group_/builds" | jq '.builds [-1]')"
# extract info
latest_build_="$(echo $latest_build_json_ |jq -r '.build')"
latest_version_="$(echo $latest_build_json_ |jq -r '.version')"
# write json file
filename_="$(echo $latest_build_json_ |jq -r '.downloads.application.name')"
test -e "$filename_.json" || echo "$latest_build_json_" |jq . >$filename_.json
# write sha256sum file
sha256_="$(echo $latest_build_json_ |jq -r '.downloads.application.sha256')"
test -e "$filename_.sha256sum" || echo "$sha256_ $filename_" >"$filename_.sha256sum"
# download & check sha256sum file
download_url_="$prefix_/versions/$latest_version_/builds/$latest_build_/downloads/$filename_";
if ! sha256sum --status -c "$filename_.sha256sum" &>/dev/null; then
wget --no-verbose "$download_url_" -O "$filename_"
if ! sha256sum --status -c "$filename_.sha256sum"; then
echo "## WARNING: sha256sum of $filename_ does not match, renaming it, manual intervention necessary!"
mv "$filename_" "$filename_.fixme"
exit 1
fi
else
echo "## $filename_ already successfully downloaded"
fi
# activate
test -l server.jar && ln -sfn "$filename_" server.jar