tazcraft rev 3
Add tazcraft utility
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Mar 19 17:43:45 2017 +0100 (2017-03-19) |
parents | afd87b4cc418 |
children | d588912d23cd |
files | tazcraft |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tazcraft Sun Mar 19 17:43:45 2017 +0100 1.3 @@ -0,0 +1,210 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# tazcraft - Minecraft server config & admin tool for SliTaz 1.7 +# 1.8 +# Authors: Kayam Lincoln-Vazquez, Christophe Lincoln 1.9 +# Copyright (C) 2017 SliTaz GNU/Linux - BSD License 1.10 +# 1.11 +# TODO: add spigot support, rcon handler, properties settings 1.12 +# 1.13 +. /lib/libtaz.sh 1.14 + 1.15 +version="1.11.2" 1.16 +home="/home/minecraft" 1.17 +server="$home/server" 1.18 +config="$server/server.properties" 1.19 + 1.20 +server_jar="minecraft_server.${version}.jar" 1.21 +client_jar="Minecraft.jar" 1.22 +client_path="$HOME/.local/share/minecraft/$client_jar" 1.23 + 1.24 +spigot_jar="spigot-${version}.jar" 1.25 + 1.26 +java_version="8u121" 1.27 +java_id="218821" 1.28 +java_md5="e9e7ea248e2c4826b92b3f075a80e441" 1.29 +java_tarball="jre-$java_version-linux-i586.tar.gz" 1.30 + 1.31 +# Prefer Sun Java JRE but support system wide icedtea6-jre if installed 1.32 +java="$home/jre/bin/java" 1.33 +if [ ! -x "$java" ]; then 1.34 + java="/usr/bin/java" 1.35 +fi 1.36 + 1.37 +# 1.38 +# Functions 1.39 +# 1.40 +help() { 1.41 + cat << EOT 1.42 + 1.43 +$(colorize 032 Usage:) $(basename $0) command 1.44 + 1.45 +$(colorize 032 Commands:) 1.46 + -d downlaod Download the Minecraft server 1.47 + -s start Start your Minecraft server 1.48 + -p play Launch the Minecraft client 1.49 + -j java Install Sun Java Runtime Environment 1.50 + -i info Display server and java information 1.51 + motd Raw display of the Message Of The Day 1.52 + ops Show server operators name 1.53 + 1.54 +$(colorize 032 Options:) 1.55 + --gui Run the server with a graphical user interface 1.56 + 1.57 +EOT 1.58 +} 1.59 + 1.60 +# Commands 1.61 +title() { 1.62 + echo ""; colorize 032 "$@"; separator "-" 1.63 +} 1.64 + 1.65 +# Check if Java is installed 1.66 +check_java() { 1.67 + if [ ! -x "$java" ]; then 1.68 + colorize 031 "Can't find Java Runtime Environment (JRE)"; return 1 1.69 + fi 1.70 +} 1.71 + 1.72 +# Change default motd 1.73 +defaut_motd() { 1.74 + if [ -f "$config" ]; then 1.75 + motd=$(grep ^motd= ${config} | sed s'/motd=//') 1.76 + if [ "$motd" == "A Minecraft Server" ]; then 1.77 + sed -i s'#motd=.*#motd=\\u00A72A Tazcraft Server#' ${config} 1.78 + fi 1.79 + fi 1.80 +} 1.81 + 1.82 +# Get a value in 1.83 +get_value() { 1.84 + val=$(grep ^${1}= ${config} | cut -d "=" -f 2) 1.85 + echo -n "$1"; indent 15 ": $val" 1.86 +} 1.87 + 1.88 +# 1.89 +# Commands 1.90 +# 1.91 +case "$1" in 1.92 + 1.93 + -d|downlaod) 1.94 + if [ ! -f "$server/$jar" ]; then 1.95 + echo "Downloading Minecraft..." 1.96 + mkdir -p ${server} 1.97 + wget --no-check-certificate \ 1.98 + https://s3.amazonaws.com/Minecraft.Download/versions/${version}/minecraft_server.${version}.jar \ 1.99 + -O ${server}/minecraft_server.${version}.jar 1.100 + else 1.101 + colorize 032 "Minecraft is already downloaded :-)" 1.102 + fi ;; 1.103 + 1.104 + -s|start) 1.105 + check_java || exit 1 1.106 + defaut_motd 1.107 + colorize 032 "Starting Minecraft server..." 1.108 + [ ! "$gui" ] && opts="nogui" 1.109 + cd ${server} 1.110 + ${java} -Xmx1024M -Xms1024M -jar ${server_jar} ${opts} ;; 1.111 + 1.112 + -p|play) 1.113 + if [ ! -f "$client_path" ]; then 1.114 + dest_dir="$(dirname $client_path)" 1.115 + mkdir -p ${dest_dir} 1.116 + xterm -e "wget \ 1.117 + http://s3.amazonaws.com/Minecraft.Download/launcher/${client_jar} \ 1.118 + -O $client_path" 1.119 + fi 1.120 + ${java} -jar ${client_path} & ;; 1.121 + 1.122 + -j|java) 1.123 + if [ ! -x "$home/jre/bin/java" ]; then 1.124 + echo "Installing Java Runtime Environment ($java_version)..." 1.125 + 1.126 + # Already downloaded 1.127 + if [ ! -f "$home/$java_tarball" ]; then 1.128 + wget \ 1.129 + http://javadl.oracle.com/webapps/download/AutoDL?BundleId=${java_id}_${java_md5} \ 1.130 + -O ${home}/${java_tarball} 1.131 + fi 1.132 + 1.133 + echo "Extracting: ${java_tarball}..." 1.134 + tar xzf ${home}/${java_tarball} -C ${home} || exit 1 1.135 + rm -rf jre 2>/dev/null && mv ${home}/jre*_*/ ${home}/jre 1.136 + 1.137 + else 1.138 + colorize 032 "Java Runtime Environment is installed" 1.139 + ${java} -version 1.140 + fi ;; 1.141 + 1.142 + motd) 1.143 + defaut_motd 1.144 + motd=$(grep ^motd= ${config} | sed s'/motd=//') 1.145 + title "Message Of The Day (motd)" 1.146 + echo "$motd" 1.147 + newline ;; 1.148 + 1.149 + -o|ops) 1.150 + title "Server operators" 1.151 + ops_json="$server/ops.json" 1.152 + #echo "Config file: $server/ops.json" 1.153 + fgrep name ${ops_json} | cut -d '"' -f 4 1.154 + newline ;; 1.155 + 1.156 + -w|white-list) 1.157 + # Usage: tazcraft -w [username|--true|--false] 1.158 + white_list="${server}/white-list.txt" 1.159 + title "Minecraft server white list" 1.160 + 1.161 + case "$2" in 1.162 + 1.163 + --true) 1.164 + echo "Activaction white list support..." 1.165 + sed -i s'/white-list=*./white-list=true/' ${config} 1.166 + touch ${white_list} ;; 1.167 + 1.168 + --false) ;; 1.169 + *) ;; 1.170 + esac 1.171 + # Add/remove users 1.172 + 1.173 + 1.174 + # --true 1.175 + if [ "$true" ]; then 1.176 + 1.177 + fi 1.178 + 1.179 + # Display white list users or give settings info 1.180 + if [ -f "$white_list" ]; then 1.181 + cat ${white_list} 1.182 + else 1.183 + get_value "white-list" 1.184 + colorize 031 "White list file is not activated $val" 1.185 + fi 1.186 + 1.187 + newline ;; 1.188 + 1.189 + -i|info) 1.190 + newline 1.191 + colorize 032 "Minecraft Server" 1.192 + echo "Version : $version" 1.193 + echo "Home : $home" 1.194 + newline 1.195 + 1.196 + colorize 032 "Server properties" 1.197 + for var in gamemode server-port level-name difficulty max-players \ 1.198 + allow-flight 1.199 + do 1.200 + get_value ${var} 1.201 + done 1.202 + newline 1.203 + 1.204 + if check_java; then 1.205 + colorize 032 "Java Runtime Environment" 1.206 + echo "Path: $java" 1.207 + ${java} -version #2>&1 | grep "version" 1.208 + fi 1.209 + newline ;; 1.210 + 1.211 + *) help ;; 1.212 +esac 1.213 +exit 0