#!/bin/bash root="$(pwd)" # Ensure servers folders exist. # If none, say so. If one, use it. If more, ask for selection if none provided. input=$1 server_count="$(ls -lR|grep ^d|grep server|wc -l)" if [ "$server_count" = "0" ];then echo "No servers found." exit 1 elif [ "$server_count" = "1" ];then for list in server_*;do server="$(echo $list|cut -f2 -d"_")" done else valid=0 until [ "$valid" = "1" ];do if [ "$input" = "" ];then echo "Available Servers:" for list in server_*;do echo "- $list"|cut -f2 -d"_" done until [ "$valid" = "1" ];do echo -n "Start: " read server if [ -d "server_$server" ];then valid=1 else echo "No such server '$server'" fi done else if [ -d "server_$input" ];then server=$input valid=1 else echo "No such server '$1'" unset input fi fi done fi unset input server_count list valid # See what server executables we have (Spigot/Bukkit). # If none, exit. If one, use it. If both, ask which to use. cd executables bukkit_amount="$(ls craftbukkit*.jar|wc -l)" spigot_amount="$(ls spigot*.jar|wc -l)" if [ "$bukkit_amount" != "0" ] && [ "$spigot_amount" != "0" ];then echo "Both Spigot and Bukkit executables found." valid=0 until [ "$valid" = "1" ];do echo -n "[S/B] Use: " read -n1 jar if [ "${jar,,}" = "s" ]; then jar="spigot" valid=1 echo elif [ "${jar,,}" = "b" ];then jar="craftbukkit" valid=1 echo else echo -ne " "\\r unset jar fi done elif [ "$bukkit_amount" != "0" ];then jar="craftbukkit" elif [ "$spigot_amount" != "0" ];then jar="spigot" else echo "No Bukkit or Spigot executables found." echo -e "Ensure they're located at \e[33m$root/executables\e[0m, and are titled" echo -e "\e[33mcraftbukkit-version.jar\e[0m or \e[33mspigot-version.jar\e[0m respectively." exit 1 fi unset bukkit_amount spigot_amount valid # If multiple JAR files of the selected executable exists, move them all # into the folder 'old-versions', then pull the last (latest, if named by version) back out. echo "Moving any old versions into backup folder..." if [ ! -d "old-versions" ];then mkdir old-versions;fi for list in $jar*.jar;do mv $list old-versions/ done jar="$list" mv old-versions/$jar . echo "Done." unset list # Ask if user wants the script to auto-restart the server upon exit. valid=0 until [ "$valid" = "1" ];do echo -n "[Y/N] Auto-restart? " read -n1 input if [ "${input,,}" = "y" ];then keepalive=1 valid=1 echo elif [ "${input,,}" = "n" ];then keepalive=0 valid=1 echo else echo -n " "\\r fi done unset valid input # Execute server. cd ../server_$server echo "eula=true">eula.txt loop=1 while [ "$loop" = "1" ];do # Disable the while loop we're in if user requested no auto-restart. if [ "$keepalive" = "0" ];then loop=0;fi unset keepalive # Give user time to ^C out of this script to prevent the next start. x=5 while [ "$x" -gt "0" ];do echo -ne "Starting server in: $x "\\r let x-=1 sleep 1 done unset x /usr/bin/java -jar ../executables/$jar;err=$? echo echo -n "Server exited, code " if [ "$err" = "0" ];then echo -e "\e[32m$err\e[0m." else echo -e "\e[31m$err\e[0m." fi echo done