-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_server.sh
More file actions
executable file
·78 lines (63 loc) · 2.58 KB
/
update_server.sh
File metadata and controls
executable file
·78 lines (63 loc) · 2.58 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
#!/bin/bash
#
# Downloads newest BuiltTools and builds the latest jar file
# Creates a backup of the last BuildTools, server jar file, and settings files
# handle fatal errors
function fatal_error {
echo "$1" >&2
return 1
}
# path to current folder and BuildTools folder
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bt_dir="${script_dir}/BuildTools"
# latest and local BuildTool.jar build numbers
build_num_file="${bt_dir}/.buildToolsNumber"
build_num_link="$(curl -s https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/buildNumber)"
# link to newest BuildTools.jar
bt_link="https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
# latest and local minecraft versions
latest_ver="$(curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json | jq '.latest.release')"
local_ver="$(unzip -p "${script_dir}"/../spigot-*.jar version.json | jq ".name")"
# create BuildTools directory if it does not exist
if [ ! -d "${bt_dir}" ]
then
mkdir "${bt_dir}"
echo "Created BuildTools Directory"
fi
# if BuildTools.jar exists and local build number is equal to the newest build number
if [ -f "${bt_dir}"/BuildTools.jar ] && \
[ -f "${build_num_file}" ] && \
[ $(cat "${build_num_file}") -eq ${build_num_link} ]
then
echo "BuildTools already on newest version; skipping update"
else
# backup old BuildTools.jar file
if [ -f "${bt_dir}"/BuildTools.jar ]
then
cp "${bt_dir}"/BuildTools.jar "${bt_dir}"/BuildTools.jar.old
echo "Moved old BuildTools.jar file to BuildTools.jar.old"
fi
# download new BuildTools.jar and update local build number
echo "Downloading BuildTools.jar"
curl "${bt_link}" -s -o "${bt_dir}"/BuildTools.jar || fatal_error "Download failed"
echo "${build_num_link}" > "${build_num_file}"
chmod a+x "${bt_dir}"/BuildTools.jar
echo "Download complete"
fi
# generate server.jar file if it's outdated
if [ ! -f "${script_dir}"/../spigot-*.jar ] || ! [ ${local_ver} == ${latest_ver} ]
then
echo "[${local_ver} -> ${latest_ver}] Building Spigot (this will take a while)"
cd "${bt_dir}"
java -Xmx2G -jar BuildTools.jar --rev ${latest_ver} --output-dir ServerJARs > /dev/null 2>&1 || fatal_error 'Build failed'
chmod a+x ServerJARs/*
cd "${script_dir}"
echo 'Build complete'
new_build_path="$(ls -td "${bt_dir}"/ServerJARs/spigot* | head -1)"
cp "${new_build_path}" "$script_dir"/..
python3 "${script_dir}"/backup.py -s
echo "Server Copied"
else
echo "Spigot already on newest version; skipping update"
fi
echo "Done"