-
Notifications
You must be signed in to change notification settings - Fork 5
/
minecraft_server.sh
executable file
·156 lines (124 loc) · 5.35 KB
/
minecraft_server.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
#!/bin/bash
printf "\033c"
if [ "$(id -u)" != "0" ]; then
echo -e "\n---------------------------------------------------------------------------------\n"
echo -e "PLEASE EXECUTE THIS SCRIPT AS ROOT OR SUDO!\n"
echo "sudo ${0}"
echo -e "\n---------------------------------------------------------------------------------"
exit 1
fi
DEPENDENCIES="ca-certificates screen default-jre-headless wget host"
dpkg -s $DEPENDENCIES &>/dev/null
if [ $? -ne 0 ]; then
echo -e "For Minecraft to work we need to install the following dependencies:\n"
for DEPENDENCY in $DEPENDENCIES; do
echo "- $DEPENDENCY"
done
echo ""
read -r -p "Please insert 'YES' to allow the installation. Otherwise this script will exit here: " ANSWER
if [ "$ANSWER" == "YES" ]; then
apt-get update
apt-get -y install $DEPENDENCIES
if [ $? -ne 0 ]; then
echo -e "\n---------------------------------------------------------------------------------\n"
echo "Installation failed, trying to fix..."
echo -e "\n---------------------------------------------------------------------------------\n"
sleep 3
apt-get -f -y install
if [ $? -ne 0 ]; then
echo "Could not install dependencies. Will exit now."
exit 1
fi
fi
else
echo "Your answer was \"$ANSWER\" and not YES. So this script will exit now."
exit 1
fi
fi
USERNAME=""
while [ -z "$USERNAME" ] || [ "$USERNAME" == "root" ]; do
echo -e "---------------------------------------------------------------------------------\n"
echo "Please insert your desired username that is used to manage the Minecraft server."
echo -e "The server will get created in the home directory of the user entered.\n"
read -r -p "The user gets created if it does not already exist: " USERNAME
done
id -g $USERNAME &>/dev/null
if [ $? -ne 0 ]; then
groupadd "$USERNAME"
fi
id -u $USERNAME &>/dev/null
if [ $? -ne 0 ]; then
echo -e "\n---------------------------------------------------------------------------------\n"
echo "User does not exist! To create this user, we need a password!"
echo -e "\n---------------------------------------------------------------------------------\n"
PASSWORD=""
while [ -z "$PASSWORD" ]; do
read -r -s -p "Please insert the desired password for User $USERNAME: " PASSWORD
done
useradd -g "$USERNAME" -d /home/"$USERNAME" -m -s /bin/bash -p $(echo "$PASSWORD" | openssl passwd -1 -stdin) "$USERNAME"
fi
echo -e "\n---------------------------------------------------------------------------------\n"
echo -e "What Software should the server run on?\n"
echo "[1] VANILLA"
echo "[2] SPIGOT"
echo "[3] CRAFTBUKKIT"
echo "[4] PAPERSPIGOT"
echo ""
CASE=1
while [ $CASE -ne 0 ]; do
read -r -p "Please enter the number of your choice: " TYPE_INT
case $TYPE_INT in
1)
TYPE="minecraft_server"
CASE=0
;;
2)
TYPE="spigot"
CASE=0
;;
3)
TYPE="craftbukkit"
CASE=0
;;
4)
TYPE="paperspigot"
CASE=0
;;
esac
done
echo "Which version would you like to use?"
read -r -p "Please enter the version of your choice [ 1.8.8 / 1.12.2 / 1.15.2 ]: " VERSION
echo -e "\n---------------------------------------------------------------------------------\n"
echo "Your server is getting created... Please wait..."
echo -e "\n---------------------------------------------------------------------------------\n"
rm -f /home/"$USERNAME"/*.jar
wget -q https://minecraft-mirror.io/"$TYPE"-"$VERSION".jar -O /home/"$USERNAME"/"$TYPE"-"$VERSION".jar
echo "eula=true" > /home/"$USERNAME"/eula.txt
cat > /home/"$USERNAME"/start.sh << EOF
#!/bin/bash
screen -S minecraft java -jar $TYPE-$VERSION.jar nogui
EOF
chmod +x /home/"$USERNAME"/start.sh
chown -R "$USERNAME":"$USERNAME" /home/"$USERNAME"
echo -e "\n---------------------------------------------------------------------------------"
echo "---------------------------------------------------------------------------------"
echo -e "---------------------------------------------------------------------------------\n"
echo "SETUP COMPLETED SUCCESSFULLY"
echo -e "\n---------------------------------------------------------------------------------"
echo "---------------------------------------------------------------------------------"
echo -e "---------------------------------------------------------------------------------\n"
PASSWORD_OUTPUT=${PASSWORD:=Password for the user was not created with this script, so it existed before.}
echo "Please connect via SSH (e.g. with Putty or another SSH client) using the following credentials:"
echo -e "\n---------------------------------------------------------------------------------\n"
echo "- Username: $USERNAME"
echo "- Password: $PASSWORD_OUTPUT"
echo -e "\n---------------------------------------------------------------------------------\n"
echo "Then execute this command and the server will start:"
echo -e "\n---------------------------------------------------------------------------------\n"
echo "cd /home/"$USERNAME" && ./start.sh"
echo -e "\n---------------------------------------------------------------------------------\n"
IP=$(host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has address" | awk '{ print $NF }')
echo "Enter this address into your minecraft client and connect to the server:"
echo -e "\n---------------------------------------------------------------------------------\n"
echo "$IP:25565"
echo -e "\n---------------------------------------------------------------------------------\n"