-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_minecraft_bedrock.sh
executable file
·111 lines (97 loc) · 3.5 KB
/
install_minecraft_bedrock.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
#!/bin/bash
# Custom Minecraft server install script for Ubuntu
# $1 = Minecraft user name, to be an operator of the server.
# $2 = difficulty, 0 - Peaceful, 1 - Easy, 2 - Normal, 3 - Hard. See http://minecraft.gamepedia.com/Server.properties
# $3 = level-name, Name of your world. No spaces, single quotes, explanation marks, backslashes
# $4 = gamemode, 0 - Survival, 1 - Creative, 2 - Adventure, 3 - Spectator
# $5 = white-list, set this to true to make this invite-only. (Default: False)
# $6 = enable-command-block, if this is true you can create command blocks in the server. (Default: False)
# $7 = spawn-monsters, controls whether monsters show up at night or not. (Default: True)
# $8 = generate-structures, controls whether your world will have temples and villages. (Default: True)
# $9 = level-seed, Leave this blank to use a random seed.
set -eu -o pipefail
# Basic service and API settings
INSTALL_DIR=/srv/minecraft_server_bedrock
USER=minecraft
GROUP=minecraft
UUID_URL=https://api.mojang.com/users/profiles/minecraft/$1
# Screen scrape the server jar location from the Minecraft server download page
SERVER_JAR_URL="curl -L https://minecraft.net/en-us/download/server/bedrock/ | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_-]*\" | sort | uniq | grep bin-linux"
apt update
apt install -y software-properties-common jq
apt install -y unzip
# Create user and install folder+
printf "Create %s user...\\n" "$USER"
adduser --system --no-create-home --home $INSTALL_DIR $USER
addgroup --system $GROUP
mkdir -pv $INSTALL_DIR
# Download the server jar
printf "Download %s/server.zip...\\n" "$INSTALL_DIR"
wget -q "$(eval "$SERVER_JAR_URL")" -O $INSTALL_DIR/server.zip
unzip $INSTALL_DIR/server.zip -d $INSTALL_DIR/
# Set permissions on install folder
chown -R $USER $INSTALL_DIR
# Create a service
printf "Create service..."
cat <<EOF | tee /etc/systemd/system/minecraft-server-bedrock.service
[Unit]
Description=Minecraft Bedrock Server
After=rc-local.service
[Service]
WorkingDirectory=$INSTALL_DIR
User=$USER
ProtectSystem=full
ProtectHome=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
ExecStart=/bin/bash -c 'LD_LIBRARY_PATH=. ./bedrock_server'
ExecReload=/bin/kill -HUP \$MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=minecraft-server-bedrock.service
EOF
printf "Service create to launch\\n"
# Configure the server
printf "Configure the server..."
echo 'eula=true' | tee $INSTALL_DIR/eula.txt
mojang_output="$(wget -qO- "$UUID_URL")"
rawUUID="$(echo "${mojang_output}" | jq -r '.id')"
UUID=${rawUUID:0:8}-${rawUUID:8:4}-${rawUUID:12:4}-${rawUUID:16:4}-${rawUUID:20:12}
cat <<EOF | tee $INSTALL_DIR/permissions.json
[
{
"xuid": "$UUID",
"name": "$1",
"permission": "operator"
}
]
EOF
chown $USER:$GROUP $INSTALL_DIR/permissions.json
cat <<EOF | tee $INSTALL_DIR/server.properties
# https://minecraft.gamepedia.com/Server.properties#Bedrock_Edition_3
server-name=$3
gamemode=$4
difficulty=$2
allow-cheats=false
max-players=10
online-mode=true
white-list=$5
server-port=19132
server-portv6=19133
view-distance=32
tick-distance=4
player-idle-timeout=30
max-threads=0
level-name=$3
level-seed=$9
default-player-permission-level=visitor
texturepack-required=false
content-log-file-enabled=false
EOF
chown $USER:$GROUP $INSTALL_DIR/server.properties
systemctl daemon-reload
systemctl enable minecraft-server-bedrock && echo "Enable minecraft-server-bedrock..." || echo "minecraft-server-bedrock already enabled. Skipping..."
systemctl start minecraft-server-bedrock