tazcraft diff 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 diff
     1.1 --- a/tazcraft	Sun Mar 19 17:43:45 2017 +0100
     1.2 +++ b/tazcraft	Wed Mar 22 19:29:51 2017 +0100
     1.3 @@ -5,7 +5,7 @@
     1.4  # Authors: Kayam Lincoln-Vazquez, Christophe Lincoln
     1.5  # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
     1.6  #
     1.7 -# TODO: add spigot support, rcon handler, properties settings
     1.8 +# TODO: add spigot support, rcon handler ?, properties settings
     1.9  #
    1.10  . /lib/libtaz.sh
    1.11  
    1.12 @@ -13,6 +13,8 @@
    1.13  home="/home/minecraft"
    1.14  server="$home/server"
    1.15  config="$server/server.properties"
    1.16 +ops="$server/ops.json"
    1.17 +whitelist="${server}/whitelist.json"
    1.18  
    1.19  server_jar="minecraft_server.${version}.jar"
    1.20  client_jar="Minecraft.jar"
    1.21 @@ -20,6 +22,7 @@
    1.22  
    1.23  spigot_jar="spigot-${version}.jar"
    1.24  
    1.25 +# Java settings
    1.26  java_version="8u121"
    1.27  java_id="218821"
    1.28  java_md5="e9e7ea248e2c4826b92b3f075a80e441"
    1.29 @@ -37,19 +40,24 @@
    1.30  help() {
    1.31  	cat << EOT
    1.32  
    1.33 -$(colorize 032 Usage:) $(basename $0) command
    1.34 +$(colorize 032 Usage:) $(basename $0) [command|key] [value]
    1.35  
    1.36  $(colorize 032 Commands:)
    1.37 +
    1.38    -d  downlaod      Download the Minecraft server
    1.39    -s  start         Start your Minecraft server
    1.40    -p  play          Launch the Minecraft client
    1.41    -j  java          Install Sun Java Runtime Environment
    1.42 +  -k  key           Get or set a key value in server.properties
    1.43    -i  info          Display server and java information
    1.44 -      motd          Raw display of the Message Of The Day
    1.45 -      ops           Show server operators name
    1.46 +  -m  motd          Raw display of the Message Of The Day
    1.47 +  -o  ops           Show server operators name
    1.48 +  -w  with-list     Show allowed user from white list
    1.49  
    1.50  $(colorize 032 Options:)
    1.51 +
    1.52    --gui             Run the server with a graphical user interface
    1.53 +  --mem             Set the max memory usage for Minecraft server
    1.54  
    1.55  EOT
    1.56  }
    1.57 @@ -76,10 +84,10 @@
    1.58  	fi
    1.59  }
    1.60  
    1.61 -# Get a value in
    1.62 -get_value() {
    1.63 +# Get a key value from server config file
    1.64 +get_key() {
    1.65  	val=$(grep ^${1}= ${config} | cut -d "=" -f 2)
    1.66 -	echo -n "$1"; indent 15 ": $val"
    1.67 +	echo -n "$1"; indent 15 "= $(colorize 033 $val)"
    1.68  }
    1.69  
    1.70  #
    1.71 @@ -90,21 +98,26 @@
    1.72  	-d|downlaod)
    1.73  		if [ ! -f "$server/$jar" ]; then
    1.74  			echo "Downloading Minecraft..."
    1.75 +			
    1.76  			mkdir -p ${server}
    1.77  			wget --no-check-certificate \
    1.78  				https://s3.amazonaws.com/Minecraft.Download/versions/${version}/minecraft_server.${version}.jar \
    1.79  				-O ${server}/minecraft_server.${version}.jar
    1.80 +			
    1.81  		else
    1.82  			colorize 032 "Minecraft is already downloaded :-)"
    1.83  		fi ;;
    1.84  	
    1.85  	-s|start)
    1.86  		check_java || exit 1
    1.87 -		defaut_motd
    1.88 +		[ "$mem" ] || mem="1024"
    1.89 +		
    1.90  		colorize 032 "Starting Minecraft server..."
    1.91  		[ ! "$gui" ] && opts="nogui"
    1.92  		cd ${server}
    1.93 -		${java} -Xmx1024M -Xms1024M -jar ${server_jar} ${opts} ;;
    1.94 +		${java} -Xmx${mem}M -Xms${mem}M -jar ${server_jar} ${opts} 
    1.95 +		
    1.96 +		newline ;;
    1.97  	
    1.98  	-p|play)
    1.99  		if [ ! -f "$client_path" ]; then
   1.100 @@ -135,8 +148,17 @@
   1.101  			colorize 032 "Java Runtime Environment is installed"
   1.102  			${java} -version
   1.103  		fi ;;
   1.104 +		
   1.105 +	-k|key)
   1.106 +		key="$2"
   1.107 +		val="$3"
   1.108 +		if [ "$val" ]; then
   1.109 +			echo "Setting $key to: $val"
   1.110 +			sed -i s"/${key}=.*/${key}=${val}/" ${config}
   1.111 +		fi
   1.112 +		get_key ${key} ;;
   1.113  	
   1.114 -	motd)
   1.115 +	-m|motd)
   1.116  		defaut_motd 
   1.117  		motd=$(grep ^motd= ${config} | sed s'/motd=//')
   1.118  		title "Message Of The Day (motd)"
   1.119 @@ -145,39 +167,21 @@
   1.120  	
   1.121  	-o|ops)
   1.122  		title "Server operators"
   1.123 -		ops_json="$server/ops.json"
   1.124 -		#echo "Config file: $server/ops.json"
   1.125 -		fgrep name ${ops_json} | cut -d '"' -f 4
   1.126 +		fgrep name ${ops} | cut -d '"' -f 4
   1.127 +		newline
   1.128 +		colorize 033 "Config file: $ops"
   1.129  		newline ;;
   1.130  	
   1.131  	-w|white-list)
   1.132 -		# Usage: tazcraft -w [username|--true|--false]
   1.133 -		white_list="${server}/white-list.txt"
   1.134  		title "Minecraft server white list"
   1.135  		
   1.136 -		case "$2" in
   1.137 -		
   1.138 -			--true) 
   1.139 -				echo "Activaction white list support..."
   1.140 -				sed -i s'/white-list=*./white-list=true/' ${config}
   1.141 -				touch ${white_list} ;;
   1.142 -				
   1.143 -			--false) ;;
   1.144 -			*) ;;
   1.145 -		esac
   1.146 -		# Add/remove users
   1.147 -		
   1.148 -		
   1.149 -		# --true
   1.150 -		if [ "$true" ]; then
   1.151 -			
   1.152 -		fi
   1.153 -		
   1.154  		# Display white list users or give settings info
   1.155  		if [ -f "$white_list" ]; then
   1.156 +			users=$(wc -l < $white_list)
   1.157  			cat  ${white_list}
   1.158 +			echo -e "\nAllowed users: $users"
   1.159  		else
   1.160 -			get_value "white-list"
   1.161 +			get_key "white-list"
   1.162  			colorize 031 "White list file is not activated $val"
   1.163  		fi
   1.164  		
   1.165 @@ -192,9 +196,9 @@
   1.166  		
   1.167  		colorize 032 "Server properties"
   1.168  		for var in gamemode server-port level-name difficulty max-players \
   1.169 -			allow-flight
   1.170 +			allow-flight white-list
   1.171  		do
   1.172 -			get_value ${var}
   1.173 +			get_key ${var}
   1.174  		done
   1.175  		newline
   1.176