-
-
Notifications
You must be signed in to change notification settings - Fork 859
Expand file tree
/
Copy pathupdate_pmc.sh
More file actions
executable file
·199 lines (189 loc) · 7.13 KB
/
update_pmc.sh
File metadata and controls
executable file
·199 lines (189 loc) · 7.13 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
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
#!/bin/bash
# LinuxGSM update_pmc.sh module
# Author: Daniel Gibbs
# Contributors: https://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: Handles updating of PaperMC and Waterfall servers.
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_update_dl() {
# Download and extract files to serverfiles.
fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "chmodx" "norun" "force" "${remotebuildhash}"
cp -f "${tmpdir}/${remotebuildfilename}" "${serverfiles}/${executable#./}"
echo "${remotebuild}" > "${serverfiles}/build.txt"
fn_clear_tmp
}
fn_update_localbuild() {
# Gets local build info.
fn_print_dots "Checking local build: ${remotelocation}"
# Uses build file to get local build.
localbuild=$(head -n 1 "${serverfiles}/build.txt" 2> /dev/null)
if [ -z "${localbuild}" ]; then
fn_print_error "Checking local build: ${remotelocation}: missing local build info"
fn_script_log_error "Missing local build info"
fn_script_log_error "Set localbuild to 0"
localbuild="0"
else
fn_print_ok "Checking local build: ${remotelocation}"
fn_script_log_pass "Checking local build"
fi
}
fn_update_remotebuild() {
jq_versions_all='.versions | to_entries | map(.value[])'
# Gets remote build info.
apiurl="https://fill.papermc.io/v3/projects"
# Get list of projects.
remotebuildresponse=$(curl -s "${apiurl}")
# Get list of Minecraft versions for project.
remotebuildresponseproject=$(curl -s "${apiurl}/${paperproject}")
# Get latest Minecraft: Java Edition version or user specified version.
if [ "${mcversion}" == "latest" ]; then
remotebuildmcversion=$(echo "${remotebuildresponseproject}" | jq -r "$jq_versions_all | first")
else
# Checks if user specified version exists.
remotebuildmcversion=$(echo "${remotebuildresponseproject}" | jq -r -e --arg mcversion "${mcversion}" "$jq_versions_all | .[] | select(. == \$mcversion)")
if [ -z "${remotebuildmcversion}" ]; then
# user passed version does not exist
fn_print_error_nl "Version ${mcversion} not available from ${remotelocation}"
fn_script_log_error "Version ${mcversion} not available from ${remotelocation}"
core_exit.sh
fi
fi
# Get list of paper builds for specific Minecraft: Java Edition version.
remotebuildresponsemcversion=$(curl -s "${apiurl}/${paperproject}/versions/${remotebuildmcversion}")
# Get latest paper build for specific Minecraft: Java Edition version.
remotebuildpaperversion=$(echo "${remotebuildresponsemcversion}" | jq -r '.builds[0]')
# Get various info about the paper build.
remotebuildresponseversion=$(curl -s "${apiurl}/${paperproject}/versions/${remotebuildmcversion}/builds/${remotebuildpaperversion}")
remotebuildfilename=$(echo "${remotebuildresponseversion}" | jq -r '.downloads["server:default"].name')
remotebuildhash=$(echo "${remotebuildresponseversion}" | jq -r '.downloads["server:default"].checksums.sha256')
remotebuildurl=$(echo "${remotebuildresponseversion}" | jq -r '.downloads["server:default"].url')
# Combines Minecraft: Java Edition version and paper build. e.g 1.16.5-456
remotebuild="${remotebuildmcversion}-${remotebuildpaperversion}"
if [ "${firstcommandname}" != "INSTALL" ]; then
fn_print_dots "Checking remote build: ${remotelocation}"
# Checks if remotebuild variable has been set.
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
fn_print_fail "Checking remote build: ${remotelocation}"
fn_script_log_fail "Checking remote build"
core_exit.sh
else
fn_print_ok "Checking remote build: ${remotelocation}"
fn_script_log_pass "Checking remote build"
fi
else
# Checks if remotebuild variable has been set.
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
fn_print_failure "Unable to get remote build"
fn_script_log_fail "Unable to get remote build"
core_exit.sh
fi
fi
}
fn_update_compare() {
fn_print_dots "Checking for update: ${remotelocation}"
# Update has been found or force update.
if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
# Create update lockfile.
date '+%s' > "${lockdir:?}/update.lock"
fn_print_ok_nl "Checking for update: ${remotelocation}"
fn_print "\n"
fn_print_nl "${bold}${underline}Update${default} available"
fn_print_nl "* Local build: ${red}${localbuild}${default}"
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
if [ -n "${branch}" ]; then
fn_print_nl "* Branch: ${branch}"
fi
if [ -f "${rootdir}/.dev-debug" ]; then
fn_print_nl "Remote build info"
fn_print_nl "* apiurl: ${apiurl}"
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
fn_print_nl "* remotebuild: ${remotebuild}"
fi
fn_print "\n"
fn_script_log_info "Update available"
fn_script_log_info "Local build: ${localbuild}"
fn_script_log_info "Remote build: ${remotebuild}"
if [ -n "${branch}" ]; then
fn_script_log_info "Branch: ${branch}"
fi
fn_script_log_info "${localbuild} > ${remotebuild}"
if [ "${commandname}" == "UPDATE" ]; then
date +%s > "${lockdir:?}/last-updated.lock"
unset updateonstart
check_status.sh
# If server stopped.
if [ "${status}" == "0" ]; then
fn_update_dl
if [ "${localbuild}" == "0" ]; then
exitbypass=1
command_start.sh
fn_firstcommand_reset
exitbypass=1
fn_sleep_time_5
command_stop.sh
fn_firstcommand_reset
fi
# If server started.
else
fn_print_restart_warning
exitbypass=1
command_stop.sh
fn_firstcommand_reset
exitbypass=1
fn_update_dl
exitbypass=1
command_start.sh
fn_firstcommand_reset
fi
unset exitbypass
alert="update"
elif [ "${commandname}" == "CHECK-UPDATE" ]; then
alert="check-update"
fi
alert.sh
else
fn_print_ok_nl "Checking for update: ${remotelocation}"
fn_print "\n"
fn_print_nl "${bold}${underline}No update${default} available"
fn_print_nl "* Local build: ${green}${localbuild}${default}"
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
if [ -n "${branch}" ]; then
fn_print_nl "* Branch: ${branch}"
fi
fn_print "\n"
fn_script_log_info "No update available"
fn_script_log_info "Local build: ${localbuild}"
fn_script_log_info "Remote build: ${remotebuild}"
if [ -n "${branch}" ]; then
fn_script_log_info "Branch: ${branch}"
fi
if [ -f "${rootdir}/.dev-debug" ]; then
fn_print_nl "Remote build info"
fn_print_nl "* apiurl: ${apiurl}"
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
fn_print_nl "* remotebuild: ${remotebuild}"
fi
fi
}
# The location where the builds are checked and downloaded.
remotelocation="papermc.io"
if [ "${shortname}" == "pmc" ]; then
paperproject="paper"
elif [ "${shortname}" == "vpmc" ]; then
paperproject="velocity"
elif [ "${shortname}" == "wmc" ]; then
paperproject="waterfall"
fi
if [ "${firstcommandname}" == "INSTALL" ]; then
fn_update_remotebuild
fn_update_dl
else
fn_print_dots "Checking for update"
fn_print_dots "Checking for update: ${remotelocation}"
fn_script_log_info "Checking for update: ${remotelocation}"
fn_update_localbuild
fn_update_remotebuild
fn_update_compare
fi