-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
start.sh
executable file
·220 lines (197 loc) · 10.9 KB
/
start.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
# Legendary Paper Minecraft Java Server Docker + Geyser/Floodgate server startup script
# Author: James A. Chambers - https://jamesachambers.com/minecraft-java-bedrock-server-together-geyser-floodgate/
# GitHub Repository: https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate
echo "Paper Minecraft Java Server Docker + Geyser/Floodgate script by James A. Chambers"
echo "Latest version always at https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate"
echo "Don't forget to set up port forwarding on your router! The default port is 25565 and the Bedrock port is 19132"
if [ ! -d '/minecraft' ]; then
echo "ERROR: A named volume was not specified for the minecraft server data. Please create one with: docker volume create yourvolumename"
echo "Please pass the new volume to docker like this: docker run -it -v yourvolumename:/minecraft"
exit 1
fi
# Randomizer for user agent
RandNum=$(echo $((1 + $RANDOM % 5000)))
if [ -z "$Port" ]; then
Port="25565"
fi
echo "Port used: $Port"
if [ -z "$BedrockPort" ]; then
Port="19132"
fi
echo "Bedrock port used: $BedrockPort"
# Change directory to server directory
cd /minecraft
# Create backups/downloads folder if it doesn't exist
if [ ! -d "/minecraft/downloads" ]; then
mkdir -p /minecraft/downloads
fi
if [ ! -d "/minecraft/config" ]; then
mkdir -p /minecraft/config
fi
if [ ! -d "/minecraft/backups" ]; then
mkdir -p /minecraft/backups
fi
if [ ! -d "/minecraft/plugins/Geyser-Spigot" ]; then
mkdir -p /minecraft/plugins/Geyser-Spigot
fi
# Check if network interfaces are up
NetworkChecks=0
if [ -e '/sbin/route' ]; then
DefaultRoute=$(/sbin/route -n | awk '$4 == "UG" {print $2}')
else
DefaultRoute=$(route -n | awk '$4 == "UG" {print $2}')
fi
while [ -z "$DefaultRoute" ]; do
echo "Network interface not up, will try again in 1 second"
sleep 1
if [ -e '/sbin/route' ]; then
DefaultRoute=$(/sbin/route -n | awk '$4 == "UG" {print $2}')
else
DefaultRoute=$(route -n | awk '$4 == "UG" {print $2}')
fi
NetworkChecks=$((NetworkChecks + 1))
if [ $NetworkChecks -gt 20 ]; then
echo "Waiting for network interface to come up timed out - starting server without network connection ..."
break
fi
done
# Take ownership of server files and set correct permissions
if [ -z "$NoPermCheck" ]; then
echo "Taking ownership of all server files/folders in /minecraft..."
sudo -n chown -R $(whoami) /minecraft >/dev/null 2>&1
echo "Complete"
else
echo "Skipping permissions check due to NoPermCheck flag"
fi
# Back up server
if [ -d "world" ]; then
if [ -n "$(which pigz)" ]; then
echo "Backing up server (all cores) to cd minecraft/backups folder"
tarArgs=(-I pigz --exclude='./backups' --exclude='./cache' --exclude='./logs' --exclude='./paperclip.jar')
IFS=','
read -ra ADDR <<< "$NoBackup"
for i in "${ADDR[@]}"; do
tarArgs+=(--exclude="./$i")
done
tarArgs+=(-pvcf backups/$(date +%Y.%m.%d.%H.%M.%S).tar.gz ./*)
tar "${tarArgs[@]}"
else
echo "Backing up server (single core, pigz not found) to cd minecraft/backups folder"
tarArgs=(--exclude='./backups' --exclude='./cache' --exclude='./logs' --exclude='./paperclip.jar')
IFS=','
read -ra ADDR <<< "$NoBackup"
for i in "${ADDR[@]}"; do
tarArgs+=(--exclude="./$i")
done
tarArgs+=(-pvcf backups/$(date +%Y.%m.%d.%H.%M.%S).tar.gz ./*)
tar "${tarArgs[@]}"
fi
fi
# Rotate backups
if [ -d /minecraft/backups ]; then
Rotate=$(
pushd /minecraft/backups
ls -1tr | head -n -$BackupCount | xargs -d '\n' rm -f --
popd
)
fi
# Copy config files if this is a brand new server
if [ ! -e "/minecraft/bukkit.yml" ]; then
cp /scripts/bukkit.yml /minecraft/bukkit.yml
fi
if [ ! -e "/minecraft/config/paper-global.yml" ]; then
cp /scripts/paper-global.yml /minecraft/config/paper-global.yml
fi
if [ ! -e "/minecraft/spigot.yml" ]; then
cp /scripts/spigot.yml /minecraft/spigot.yml
fi
if [ ! -e "/minecraft/server.properties" ]; then
cp /scripts/server.properties /minecraft/server.properties
fi
if [ ! -e "/minecraft/plugins/Geyser-Spigot/config.yml" ]; then
cp /scripts/config.yml /minecraft/plugins/Geyser-Spigot/config.yml
fi
# Test internet connectivity first
# Update paperclip.jar
echo "Updating to most recent paperclip version ..."
# Test internet connectivity first
if [ -z "$QuietCurl" ]; then
curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -s https://papermc.io -o /dev/null
else
curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -s https://papermc.io -o /dev/null
fi
if [ "$?" != 0 ]; then
echo "Unable to connect to update website (internet connection may be down). Skipping update ..."
else
# Get latest build
BuildJSON=$(curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" https://papermc.io/api/v2/projects/paper/versions/$Version)
Build=$(echo "$BuildJSON" | rev | cut -d, -f 1 | cut -d']' -f 2 | cut -d'[' -f 1 | rev)
Build=$(($Build + 0))
if [[ $Build != 0 ]]; then
echo "Latest paperclip build found: $Build"
if [ -z "$QuietCurl" ]; then
curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/paperclip.jar "https://papermc.io/api/v2/projects/paper/versions/$Version/builds/$Build/downloads/paper-$Version-$Build.jar"
else
curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/paperclip.jar "https://papermc.io/api/v2/projects/paper/versions/$Version/builds/$Build/downloads/paper-$Version-$Build.jar"
fi
else
echo "Unable to retrieve latest Paper build (got result of $Build)"
fi
# Update Floodgate
echo "Updating Floodgate..."
if [ -z "$QuietCurl" ]; then
curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Floodgate-Spigot.jar "https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot"
else
curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Floodgate-Spigot.jar "https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot"
fi
# Update Geyser
echo "Updating Geyser..."
if [ -z "$QuietCurl" ]; then
curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Geyser-Spigot.jar "https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot"
else
curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Geyser-Spigot.jar "https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot"
fi
if [ -z "$NoViaVersion" ]; then
# Update ViaVersion if new version is available
ViaVersionVersion=$(curl --no-progress-meter -k -L -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/ | grep 'href="ViaVersion' | cut -d'"' -f2)
if [ -n "$ViaVersionVersion" ]; then
ViaVersionMD5=$(curl --no-progress-meter -k -L -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionVersion/*fingerprint*/" | grep breadcrumbs | cut -d'_' -f24- | cut -d'<' -f2 | cut -d'>' -f2)
if [ -n "$ViaVersionMD5" ]; then
LocalMD5=$(md5sum plugins/ViaVersion.jar | cut -d' ' -f1)
if [ -e /minecraft/plugins/ViaVersion.jar ] && [ "$LocalMD5" = "$ViaVersionMD5" ]; then
echo "ViaVersion is up to date"
else
echo "Updating ViaVersion..."
if [ -z "$QuietCurl" ]; then
curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/ViaVersion.jar "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionVersion"
else
curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/ViaVersion.jar "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionVersion"
fi
fi
else
echo "Unable to check for updates to ViaVersion!"
fi
fi
else
echo "ViaVersion is disabled -- skipping"
fi
fi
# Accept EULA
AcceptEULA=$(echo eula=true >eula.txt)
# Change ports in server.properties
sed -i "/server-port=/c\server-port=$Port" /minecraft/server.properties
sed -i "/query\.port=/c\query\.port=$Port" /minecraft/server.properties
# Change Bedrock port in Geyser config
if [ -e /minecraft/plugins/Geyser-Spigot/config.yml ]; then
sed -i -z "s/ port: [0-9]*/ port: $BedrockPort/" /minecraft/plugins/Geyser-Spigot/config.yml
fi
# Start server
echo "Starting Minecraft server..."
if [[ -z "$MaxMemory" ]] || [[ "$MaxMemory" -le 0 ]]; then
exec java -XX:+UnlockDiagnosticVMOptions -XX:-UseAESCTRIntrinsics -DPaper.IgnoreJavaVersion=true -Xms400M -jar /minecraft/paperclip.jar
else
exec java -XX:+UnlockDiagnosticVMOptions -XX:-UseAESCTRIntrinsics -DPaper.IgnoreJavaVersion=true -Xms400M -Xmx${MaxMemory}M -jar /minecraft/paperclip.jar
fi
# Exit container
exit 0