/
minecraft
135 lines (125 loc) · 6.32 KB
/
minecraft
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
#!/bin/bash
MCSERVER_BIN_PATH="/srv/minecraft-bin"
MCFORGE_INSTALLER_URL="http://files.minecraftforge.net/maven/net/minecraftforge/forge/$MINECRAFT_VERSION-$MCFORGE_VERSION/forge-$MINECRAFT_VERSION-$MCFORGE_VERSION-installer.jar"
MC_SERVER_URL="https://s3.amazonaws.com/Minecraft.Download/versions/$MINECRAFT_VERSION/minecraft_server.$MINECRAFT_VERSION.jar"
MC_SERVER_JAR="minecraft_server.$MINECRAFT_VERSION.jar"
MCFORGE_SERVER_JAR="forge-$MINECRAFT_VERSION-$MCFORGE_VERSION-universal.jar"
check_env() {
if [ "$MINECRAFT_EULA" == "true" ]; then
echo "update $MCSERVER_PATH/eula.txt"
echo "eula=$MINECRAFT_EULA" > $MCSERVER_PATH/eula.txt
else
>&2 echo "Mojang: you must agree EULA. then you need set MINECRAFT_EULA 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 necessary. please set it to continue."
exit 1
fi
}
download_installer() {
# Download the Minecraft server installer JAR if it does not exist.
if [ ! -f "$MCSERVER_BIN_PATH/$MCFORGE_SERVER_JAR" ] && [ ! -f "$MCSERVER_BIN_PATH/$MCFORGE_INSTALLER_JAR" ]; then
echo "download Forge installer $MCFORGE_INSTALLER_JAR ($MCFORGE_INSTALLER_URL)"
curl -f -S "$MCFORGE_INSTALLER_URL" -o "$MCSERVER_BIN_PATH/$MCFORGE_INSTALLER_JAR"
if [ ! -f "$MCSERVER_BIN_PATH/$MCFORGE_INSTALLER_JAR" ]; then
>&2 echo "download failure $MCFORGE_INSTALLER_JAR."
exit 1
fi
fi
}
download_mc_server() {
if [ ! -f "$MCSERVER_BIN_PATH/$MCFORGE_SERVER_JAR" ] && [ ! -f "$MCSERVER_BIN_PATH/$MC_SERVER_JAR" ]; then
echo "download Minecraft server $MCFORGE_SERVER_JAR ($MC_SERVER_URL)"
curl -f -S "$MC_SERVER_URL" -o "$MCSERVER_BIN_PATH/$MC_SERVER_JAR"
if [ ! -f "$MCSERVER_BIN_PATH/$MC_SERVER_JAR" ]; then
>&2 echo "download failure $MCFORGE_INSTALLER_JAR."
exit 1
fi
fi
}
install_server() {
# Download the Minecraft server JAR if it does not exist.
if [ ! -f "$MCSERVER_BIN_PATH/$MCFORGE_SERVER_JAR" ] && [ -f "$MCSERVER_BIN_PATH/$MCFORGE_INSTALLER_JAR" ]; then
echo "install forge V$MCFORGE_VERSION"
java -server -jar "$MCSERVER_BIN_PATH/$MCFORGE_INSTALLER_JAR" --installServer
if [ ! -f "$MCSERVER_BIN_PATH/$MCFORGE_SERVER_JAR" ]; then
>&2 echo "forge install failure."
exit 1
fi
else
echo "can not install forge V$MCFORGE_VERSION"
echo "$MCSERVER_BIN_PATH/$MCFORGE_INSTALLER_JAR can not find"
rm "$MCSERVER_BIN_PATH/server-installed"
fi
}
first_run() {
if [ ! -f "$MCSERVER_PATH/$MCFORGE_SERVER_JAR" ]; then
echo "detected the server not exist"
echo "copy server"
cp -sR $MCSERVER_BIN_PATH/* "$MCSERVER_PATH"
fi
if [ ! -f "$MCSERVER_PATH/server.properties" ]; then
echo "detected the server.properties not exist"
echo "create $MCSERVER_PATH/server.properties and configure environment"
echo "generator-settings=$GENERATOR_SETTINGS" | tee -a $MCSERVER_PATH/server.properties
echo "op-permission-level=$OP_PERMISSION_LEVEL" | tee -a $MCSERVER_PATH/server.properties
echo "allow-nether=$ALLOW_NETHER" | tee -a $MCSERVER_PATH/server.properties
echo "level-name=$LEVEL_NAME" | tee -a $MCSERVER_PATH/server.properties
echo "enable-query=$ENABLE_QUERY" | tee -a $MCSERVER_PATH/server.properties
echo "allow-flight=$ALLOW_FLIGHT" | tee -a $MCSERVER_PATH/server.properties
echo "announce-player-achievements=$ANNOUNCE_PLAYER_ACHIEVEMENTS" | tee -a $MCSERVER_PATH/server.properties
echo "server-port=$SERVER_PORT" | tee -a $MCSERVER_PATH/server.properties
echo "level-type=$LEVEL_TYPE" | tee -a $MCSERVER_PATH/server.properties
echo "enable-rcon=$ENABLE_RCON" | tee -a $MCSERVER_PATH/server.properties
echo "rcon.password=$RCON_PASSWORD" | tee -a $MCSERVER_PATH/server.properties
echo "rcon-port=$RCON_PORT" | tee -a $MCSERVER_PATH/server.properties
echo "force-gamemode=$FORCE_GAMEMODE" | tee -a $MCSERVER_PATH/server.properties
echo "level-seed=$LEVEL_SEED" | tee -a $MCSERVER_PATH/server.properties
echo "server-ip=$SERVER_IP" | tee -a $MCSERVER_PATH/server.properties
echo "max-build-height=$MAX_BUILD_HEIGHT" | tee -a $MCSERVER_PATH/server.properties
echo "spawn-npcs=$SPAWN_NPCS" | tee -a $MCSERVER_PATH/server.properties
echo "white-list=$WHITE_LIST" | tee -a $MCSERVER_PATH/server.properties
echo "spawn-animals=$SPAWN_ANIMALS" | tee -a $MCSERVER_PATH/server.properties
echo "snooper-enabled=$SNOOPER_ENABLED" | tee -a $MCSERVER_PATH/server.properties
echo "online-mode=$ONLINE_MODE" | tee -a $MCSERVER_PATH/server.properties
echo "resource-pack=$RESOURCE_PACK" | tee -a $MCSERVER_PATH/server.properties
echo "pvp=$PVP" | tee -a $MCSERVER_PATH/server.properties
echo "difficulty=$DIFFICULTY" | tee -a $MCSERVER_PATH/server.properties
echo "enable-command-block=$ENABLE_COMMAND_BLOCK" | tee -a $MCSERVER_PATH/server.properties
echo "player-idle-timeout=$PLAYER_IDLE_TIMEOUT" | tee -a $MCSERVER_PATH/server.properties
echo "gamemode=$GAMEMODE" | tee -a $MCSERVER_PATH/server.properties
echo "max-players=$MAX_PLAYERS" | tee -a $MCSERVER_PATH/server.properties
echo "spawn-monsters=$SPAWN_MONSTERS" | tee -a $MCSERVER_PATH/server.properties
echo "view-distance=$VIEW_DISTANCE" | tee -a $MCSERVER_PATH/server.properties
echo "generate-structures=$GENERATE_STRUCTURES" | tee -a $MCSERVER_PATH/server.properties
echo "configure complete"
fi
if [ ! -f $MCSERVER_PATH/ops.json ]; then
echo "add $DEFAULT_OP in OP list."
echo "$DEFAULT_OP" > $MCSERVER_PATH/ops.txt
fi
}
update_permissions() {
chown -R minecraft:minecraft $MCSERVER_PATH
}
server_start() {
echo "start server"
java $MINECRAFT_OPTS -jar "$MCSERVER_PATH/$MCFORGE_SERVER_JAR" || echo "server error return code $? , please check the environment"
}
echo "Minecraft Forge Server Docker ver - execute script, arguments is $1"
case "$1" in
install)
download_installer
download_mc_server
install_server
;;
run)
check_env
first_run
server_start
;;
*)
exec "$@"
esac