forked from dlord/spigot-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspigot
executable file
·173 lines (154 loc) · 6.96 KB
/
spigot
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
#!/bin/bash
MINECRAFT_HOME="/opt/minecraft"
MINECRAFT_SRC="/usr/src/minecraft"
MINECRAFT_VERSION=${MINECRAFT_VERSION:-1.8.8}
MINECRAFT_JAR=${MINECRAFT_JAR:-"spigot-$MINECRAFT_VERSION.jar"}
MINECRAFT_STARTUP_JAR=${MINECRAFT_STARTUP_JAR:-"$MINECRAFT_JAR"}
MINECRAFT_OPTS=${MINECRAFT_OPTS:-"-server -Xmx1024m -XX:MaxPermSize=256m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC"}
WORLD_DIR="/var/lib/minecraft"
SPIGOT_BUILDTOOLS_URL=${SPIGOT_BUILDTOOLS_URL:-"https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"}
TMUX_SESSION=spigot
check_env() {
# Agree to EULA.
if [ "$MINECRAFT_EULA" == "true" ]; then
echo "Updating $MINECRAFT_HOME/eula.txt"
echo "eula=$MINECRAFT_EULA" > $MINECRAFT_HOME/eula.txt
else
>&2 echo "Mojang requires you to accept their EULA. You need to set the MINECRAFT_EULA variable to true."
exit 1
fi
# Do not allow to run if there is no DEFAULT_OP
if [ -z "$DEFAULT_OP" ]; then
>&2 echo "DEFAULT_OP is required. Please set this variable to continue."
exit 1
fi
}
build_server() {
# Compile spigot if it does not exist.
if [ ! -f "$MINECRAFT_HOME/$MINECRAFT_JAR" ]; then
echo "Building Spigot" && \
mkdir -p /tmp/spigot && \
curl -S $SPIGOT_BUILDTOOLS_URL -o /tmp/spigot/BuildTools.jar && \
pushd /tmp/spigot > /dev/null && \
java -jar BuildTools.jar --rev $MINECRAFT_VERSION && \
cp /tmp/spigot/craftbukkit-*.jar /tmp/spigot/spigot-*.jar $MINECRAFT_HOME && \
popd > /dev/null && \
rm -rf /tmp/spigot
if [ $? -ne 0 ]; then
>&2 echo "Unable to build Spigot."
exit 1
fi
fi
}
first_run() {
# Sync files from $MINECRAFT_SRC to $MINECRAFT_HOME. Do this on container's first run.
if [ -f "/run/first_time" ]; then
# Ensure that only the relevant plugins are enabled on the server.
mkdir -p $MINECRAFT_HOME/plugins
rm $MINECRAFT_HOME/plugins/*.jar*
rsync -avh --exclude '/world*' $MINECRAFT_SRC/ $MINECRAFT_HOME
rm /run/first_time
fi
# Create the server.properties if it doesn't exist
if [ ! -f "$MINECRAFT_HOME/server.properties" ]; then
echo "Creating $MINECRAFT_HOME/server.properties"
echo "generator-settings=$GENERATOR_SETTINGS" >> $MINECRAFT_HOME/server.properties
echo "op-permission-level=${OP_PERMISSION_LEVEL:-4}" >> $MINECRAFT_HOME/server.properties
echo "allow-nether=${ALLOW_NETHER:-true}" >> $MINECRAFT_HOME/server.properties
echo "level-name=${LEVEL_NAME:-world}" >> $MINECRAFT_HOME/server.properties
echo "enable-query=${ENABLE_QUERY:-false}" >> $MINECRAFT_HOME/server.properties
echo "allow-flight=${ALLOW_FLIGHT:-false}" >> $MINECRAFT_HOME/server.properties
echo "announce-player-achievements=${ANNOUNCE_PLAYER_ACHIEVEMENTS:-true}" >> $MINECRAFT_HOME/server.properties
echo "server-port=25565" >> $MINECRAFT_HOME/server.properties
echo "level-type=${LEVEL_TYPE:-DEFAULT}" >> $MINECRAFT_HOME/server.properties
echo "enable-rcon=${ENABLE_RCON:-false}" >> $MINECRAFT_HOME/server.properties
echo "force-gamemode=${FORCE_GAMEMODE:-false}" >> $MINECRAFT_HOME/server.properties
echo "level-seed=$LEVEL_SEED" >> $MINECRAFT_HOME/server.properties
echo "server-ip=$SERVER_IP" >> $MINECRAFT_HOME/server.properties
echo "max-build-height=${MAX_BUILD_HEIGHT:-256}" >> $MINECRAFT_HOME/server.properties
echo "spawn-npcs=${SPAWN_NPCS:-true}" >> $MINECRAFT_HOME/server.properties
echo "white-list=${WHITE_LIST:-true}" >> $MINECRAFT_HOME/server.properties
echo "spawn-animals=${SPAWN_ANIMALS:-true}" >> $MINECRAFT_HOME/server.properties
echo "snooper-enabled=${SNOOPER_ENABLED:-true}" >> $MINECRAFT_HOME/server.properties
echo "online-mode=${ONLINE_MODE:-true}" >> $MINECRAFT_HOME/server.properties
echo "resource-pack=$RESOURCE_PACK" >> $MINECRAFT_HOME/server.properties
echo "pvp=${PVP:-true}" >> $MINECRAFT_HOME/server.properties
echo "difficulty=${DIFFICULTY:-2}" >> $MINECRAFT_HOME/server.properties
echo "enable-command-block=${ENABLE_COMMAND_BLOCK:-true}" >> $MINECRAFT_HOME/server.properties
echo "player-idle-timeout=${PLAYER_IDLE_TIMEOUT:-0}" >> $MINECRAFT_HOME/server.properties
echo "gamemode=${GAMEMODE:-0}" >> $MINECRAFT_HOME/server.properties
echo "max-players=${MAX_PLAYERS:-20}" >> $MINECRAFT_HOME/server.properties
echo "spawn-monsters=${SPAWN_MONSTERS:-true}" >> $MINECRAFT_HOME/server.properties
echo "view-distance=${VIEW_DISTANCE:-10}" >> $MINECRAFT_HOME/server.properties
echo "generate-structures=${GENERATE_STRUCTURES:-true}" >> $MINECRAFT_HOME/server.properties
fi
# Copy world template if level folder is empty.
if ! find $WORLD_DIR -mindepth 1 -print -quit | grep -q . && { find $MINECRAFT_SRC/world -mindepth 1 -print -quit | grep -q .; }; then
echo "World template found in $MINECRAFT_HOME/world"
echo "Creating new world in $WORLD_DIR"
cp -rf $MINECRAFT_SRC/world* $WORLD_DIR
fi
# Create default ops.txt if ops.json does not exist yet.
if [ ! -f $MINECRAFT_HOME/ops.json ]; then
echo "Adding $DEFAULT_OP to ops list."
echo "$DEFAULT_OP" > $MINECRAFT_HOME/ops.txt
echo "$DEFAULT_OP" > $MINECRAFT_HOME/white-list.txt
fi
}
update_permissions() {
echo "Updating file permissions"
chown -R minecraft:minecraft $MINECRAFT_HOME $WORLD_DIR
}
run_spigot() {
echo "TERM is set to $TERM"
pushd $MINECRAFT_HOME > /dev/null
echo "Running Minecraft"
echo "MINECRAFT_OPTS: $MINECRAFT_OPTS"
MINECRAFT_COMMAND="gosu minecraft java $MINECRAFT_OPTS -jar $MINECRAFT_HOME/$MINECRAFT_STARTUP_JAR nogui --world-dir $WORLD_DIR"
PARAMS=$@
echo "Extra parameters: ${PARAMS[@]}"
if [ "$TERM" == "dumb" ]; then
>&2 echo "WARNING! Dumb term detected. Switching to noconsole mode."
>&2 echo "Safe shutdown must be done via /stop chat command."
MINECRAFT_COMMAND="$MINECRAFT_COMMAND --noconsole ${PARAMS[@]}"
exec $MINECRAFT_COMMAND
else
MINECRAFT_COMMAND="$MINECRAFT_COMMAND ${PARAMS[@]}"
tmux new -s $TMUX_SESSION "$MINECRAFT_COMMAND"
fi
}
console_command() {
COMMAND=$@
if [ "$TERM" == "dumb" ]; then
>&2 echo "Console command not supported on a dumb term."
exit 1
else
echo "Executing console command: ${COMMAND[@]}"
tmux send -t $TMUX_SESSION "${COMMAND[@]}" ENTER
fi
}
safe_shutdown() {
echo "Performing safe shutdown..."
console_command stop
}
case "$1" in
run)
shift 1
check_env
build_server
first_run
update_permissions
trap safe_shutdown EXIT
run_spigot $@
;;
permissions)
shift 1
update_permissions
;;
console)
shift 1
console_command $@
;;
*)
exec "$@"
esac