tazcraft view tazcraft @ rev 7

Add link to village finder
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 22 19:29:51 2017 +0100 (2017-03-22)
parents 525121d3c8e8
children e2ad8436c2dd
line source
1 #!/bin/sh
2 #
3 # tazcraft - Minecraft server config & admin tool for SliTaz
4 #
5 # Authors: Kayam Lincoln-Vazquez, Christophe Lincoln
6 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
7 #
8 # TODO: add spigot support, rcon handler ?, properties settings
9 #
10 . /lib/libtaz.sh
12 version="1.11.2"
13 home="/home/minecraft"
14 server="$home/server"
15 config="$server/server.properties"
16 ops="$server/ops.json"
17 whitelist="${server}/whitelist.json"
19 server_jar="minecraft_server.${version}.jar"
20 client_jar="Minecraft.jar"
21 client_path="$HOME/.local/share/minecraft/$client_jar"
23 spigot_jar="spigot-${version}.jar"
25 # Java settings
26 java_version="8u121"
27 java_id="218821"
28 java_md5="e9e7ea248e2c4826b92b3f075a80e441"
29 java_tarball="jre-$java_version-linux-i586.tar.gz"
31 # Prefer Sun Java JRE but support system wide icedtea6-jre if installed
32 java="$home/jre/bin/java"
33 if [ ! -x "$java" ]; then
34 java="/usr/bin/java"
35 fi
37 #
38 # Functions
39 #
40 help() {
41 cat << EOT
43 $(colorize 032 Usage:) $(basename $0) [command|key] [value]
45 $(colorize 032 Commands:)
47 -d downlaod Download the Minecraft server
48 -s start Start your Minecraft server
49 -p play Launch the Minecraft client
50 -j java Install Sun Java Runtime Environment
51 -k key Get or set a key value in server.properties
52 -i info Display server and java information
53 -m motd Raw display of the Message Of The Day
54 -o ops Show server operators name
55 -w with-list Show allowed user from white list
57 $(colorize 032 Options:)
59 --gui Run the server with a graphical user interface
60 --mem Set the max memory usage for Minecraft server
62 EOT
63 }
65 # Commands
66 title() {
67 echo ""; colorize 032 "$@"; separator "-"
68 }
70 # Check if Java is installed
71 check_java() {
72 if [ ! -x "$java" ]; then
73 colorize 031 "Can't find Java Runtime Environment (JRE)"; return 1
74 fi
75 }
77 # Change default motd
78 defaut_motd() {
79 if [ -f "$config" ]; then
80 motd=$(grep ^motd= ${config} | sed s'/motd=//')
81 if [ "$motd" == "A Minecraft Server" ]; then
82 sed -i s'#motd=.*#motd=\\u00A72A Tazcraft Server#' ${config}
83 fi
84 fi
85 }
87 # Get a key value from server config file
88 get_key() {
89 val=$(grep ^${1}= ${config} | cut -d "=" -f 2)
90 echo -n "$1"; indent 15 "= $(colorize 033 $val)"
91 }
93 #
94 # Commands
95 #
96 case "$1" in
98 -d|downlaod)
99 if [ ! -f "$server/$jar" ]; then
100 echo "Downloading Minecraft..."
102 mkdir -p ${server}
103 wget --no-check-certificate \
104 https://s3.amazonaws.com/Minecraft.Download/versions/${version}/minecraft_server.${version}.jar \
105 -O ${server}/minecraft_server.${version}.jar
107 else
108 colorize 032 "Minecraft is already downloaded :-)"
109 fi ;;
111 -s|start)
112 check_java || exit 1
113 [ "$mem" ] || mem="1024"
115 colorize 032 "Starting Minecraft server..."
116 [ ! "$gui" ] && opts="nogui"
117 cd ${server}
118 ${java} -Xmx${mem}M -Xms${mem}M -jar ${server_jar} ${opts}
120 newline ;;
122 -p|play)
123 if [ ! -f "$client_path" ]; then
124 dest_dir="$(dirname $client_path)"
125 mkdir -p ${dest_dir}
126 xterm -e "wget \
127 http://s3.amazonaws.com/Minecraft.Download/launcher/${client_jar} \
128 -O $client_path"
129 fi
130 ${java} -jar ${client_path} & ;;
132 -j|java)
133 if [ ! -x "$home/jre/bin/java" ]; then
134 echo "Installing Java Runtime Environment ($java_version)..."
136 # Already downloaded
137 if [ ! -f "$home/$java_tarball" ]; then
138 wget \
139 http://javadl.oracle.com/webapps/download/AutoDL?BundleId=${java_id}_${java_md5} \
140 -O ${home}/${java_tarball}
141 fi
143 echo "Extracting: ${java_tarball}..."
144 tar xzf ${home}/${java_tarball} -C ${home} || exit 1
145 rm -rf jre 2>/dev/null && mv ${home}/jre*_*/ ${home}/jre
147 else
148 colorize 032 "Java Runtime Environment is installed"
149 ${java} -version
150 fi ;;
152 -k|key)
153 key="$2"
154 val="$3"
155 if [ "$val" ]; then
156 echo "Setting $key to: $val"
157 sed -i s"/${key}=.*/${key}=${val}/" ${config}
158 fi
159 get_key ${key} ;;
161 -m|motd)
162 defaut_motd
163 motd=$(grep ^motd= ${config} | sed s'/motd=//')
164 title "Message Of The Day (motd)"
165 echo "$motd"
166 newline ;;
168 -o|ops)
169 title "Server operators"
170 fgrep name ${ops} | cut -d '"' -f 4
171 newline
172 colorize 033 "Config file: $ops"
173 newline ;;
175 -w|white-list)
176 title "Minecraft server white list"
178 # Display white list users or give settings info
179 if [ -f "$white_list" ]; then
180 users=$(wc -l < $white_list)
181 cat ${white_list}
182 echo -e "\nAllowed users: $users"
183 else
184 get_key "white-list"
185 colorize 031 "White list file is not activated $val"
186 fi
188 newline ;;
190 -i|info)
191 newline
192 colorize 032 "Minecraft Server"
193 echo "Version : $version"
194 echo "Home : $home"
195 newline
197 colorize 032 "Server properties"
198 for var in gamemode server-port level-name difficulty max-players \
199 allow-flight white-list
200 do
201 get_key ${var}
202 done
203 newline
205 if check_java; then
206 colorize 032 "Java Runtime Environment"
207 echo "Path: $java"
208 ${java} -version #2>&1 | grep "version"
209 fi
210 newline ;;
212 *) help ;;
213 esac
214 exit 0