Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- Start() {
- if "$Online" && [ "$USER" != "plg" ]; then
- SendStats
- fi
- if "$MinimalMode"; then
- if [ "$BackupAt" == "All" ] || [ "$BackupAt" == "Start" ]; then
- ./script/Utilities.sh Backup Start
- fi
- java -server -Xms512M -Xmx$RAM -jar $jar $mode $arguments
- echo
- if [ "$BackupAt" == "All" ] || [ "$BackupAt" == "Stop" ]; then
- ./script/Utilities.sh Backup Stop
- fi
- rm -rf ./script/temp
- else
- if [ ! -f ./script/temp/dummies/_Closed ]; then
- if "$Schedule"; then
- touch ./script/temp/dummies/_Schedule
- if [ ! -f server.log.lck ]; then
- mv -f ./server.log ./script/temp/server.log
- fi
- if "$RAMDisk"; then
- if "$Linux"; then
- SudoAuthorization "to mount the RAMDisk"
- fi
- touch ./script/temp/dummies/_RAMDisk
- ./script/Utilities.sh RAMDisk Mount
- fi
- screen -dmS Minecraft-Schedule -c ./script/temp/screen/Schedule.conf
- elif [ ! -f server.log.lck ]; then
- mv -f ./server.log ./script/temp/server.log
- if ! "$RAMDisk"; then
- screen -dmS "$ServerScreen" -c ./script/temp/screen/Server.conf
- else
- if "$Linux"; then
- SudoAuthorization "to mount the RAMDisk"
- fi
- touch ./script/temp/dummies/_RAMDisk
- ./script/Utilities.sh RAMDisk Mount
- screen -dmS "$ServerScreen" -c ./script/temp/screen/Server.conf
- fi
- fi
- else
- rm -rf ./script/temp/dummies/_Closed
- fi
- clear
- screen -S GTB-Script -c ./script/temp/screen/Main.conf
- if [ -f ./script/temp/dummies/_Closed ]; then
- echo -e "${Blue}Resume the script be relaunching it${None}"
- exit
- fi
- if "$RAMDisk"; then
- if "$Linux"; then
- SudoAuthorization "to unmount the RAMDisk"
- fi
- ./script/Utilities.sh RAMDisk Eject
- fi
- fi
- }
- Daemon() {
- if [ "$1" == "--start" ]; then
- if [ ! -f server.log.lck ] && [ -z "$(screen -ls | grep "$ServerScreen")" ]; then
- screen -dmS "$ServerScreen" -c ./script/temp/screen/Server.conf
- echo "The server was started"
- else
- echo "The server is already running"
- fi
- elif [ "$1" == "--stop" ]; then
- if [ -f server.log.lck ] && [ ! -z "$(screen -ls | grep "$ServerScreen")" ]; then
- screen -S "$ServerScreen" -p 1 -X eval "stuff 'stop'\015"
- rm -rf ./script/temp
- echo "The server was stopped"
- else
- echo "The server is not running"
- fi
- fi
- exit
- }
- ExportVars() {
- echo "AfterRestart='$AfterRestart'" > ./script/temp/vars.conf
- echo "arguments='$arguments'" >> ./script/temp/vars.conf
- echo "BackupAt='$BackupAt'" >> ./script/temp/vars.conf
- echo "BackupInterval='$BackupInterval'" >> ./script/temp/vars.conf
- echo "BackupLimit='$BackupLimit'" >> ./script/temp/vars.conf
- echo "BackupList='$BackupList'" >> ./script/temp/vars.conf
- echo "BackupPlugins='$BackupPlugins'" >> ./script/temp/vars.conf
- echo "Backups='$Backups'" >> ./script/temp/vars.conf
- echo "BackupTime='$BackupTime'" >> ./script/temp/vars.conf
- echo "BeforeRestart='$BeforeRestart'" >> ./script/temp/vars.conf
- echo "Columns='$Columns'" >> ./script/temp/vars.conf
- echo "CommandPrefix='$CommandPrefix'" >> ./script/temp/vars.conf
- echo "CompressBackups='$CompressBackups'" >> ./script/temp/vars.conf
- echo "Debian='$Debian'" >> ./script/temp/vars.conf
- echo "jar='$jar'" >> ./script/temp/vars.conf
- echo "Jar='$Jar'" >> ./script/temp/vars.conf
- echo "LauncherUpToDate='$LauncherUpToDate'" >> ./script/temp/vars.conf
- echo "Link='$Link'" >> ./script/temp/vars.conf
- echo "Linux='$Linux'" >> ./script/temp/vars.conf
- echo "MenuLines='$MenuLines'" >> ./script/temp/vars.conf
- echo "mode='$mode'" >> ./script/temp/vars.conf
- echo "Online='$Online'" >> ./script/temp/vars.conf
- echo "OnlyScheduled='$OnlyScheduled'" >> ./script/temp/vars.conf
- echo "RAM='$RAM'" >> ./script/temp/vars.conf
- echo "RAMDisk='$RAMDisk'" >> ./script/temp/vars.conf
- echo "RAMDiskList='$RAMDiskList'" >> ./script/temp/vars.conf
- echo "RestartInterval='$RestartInterval'" >> ./script/temp/vars.conf
- echo "Schedule='$Schedule'" >> ./script/temp/vars.conf
- echo "ServerScreen='$ServerScreen'" >> ./script/temp/vars.conf
- echo "ServerUpToDate='$ServerUpToDate'" >> ./script/temp/vars.conf
- echo "ServerVersion='$ServerVersion'" >> ./script/temp/vars.conf
- echo "MinimalMode='$MinimalMode'" >> ./script/temp/vars.conf
- echo "StartTime='$StartTime'" >> ./script/temp/vars.conf
- echo "StopTime='$StopTime'" >> ./script/temp/vars.conf
- echo "Tip='$Tip'" >> ./script/temp/vars.conf
- echo "ThisVersion='$ThisVersion'" >> ./script/temp/vars.conf
- echo "Ubuntu='$Ubuntu'" >> ./script/temp/vars.conf
- echo "ViewLines='$ViewLines'" >> ./script/temp/vars.conf
- echo "World='$World'" >> ./script/temp/vars.conf
- echo "WorldName='$WorldName'" >> ./script/temp/vars.conf
- if [ "$BackupInterval" != "00:00" ]; then
- echo "BackupTime='$(./script/Utlilites.sh In $BackupInterval)'" >> ./script/temp/vars.conf
- else
- echo "BackupTime='never'" >> ./script/temp/vars.conf
- fi
- }
- ServerVersion() {
- if [ -f "$jar" ]; then
- if [ "$jar" == "CraftBukkit.jar" ]; then
- ServerVersion=$(java -jar "$jar" -v | cut -d '-' -f 3,4)
- elif [ "$jar" == "SpiGot.jar" ]; then
- ServerVersion=$(java -jar "$jar" -v | cut -d '-' -f 4,5)
- else
- if "$Online"; then
- ServerVersion=$(curl -s http://mcupdate.tumblr.com | grep 'Permanent link for this post' | \
- sed -n 1p | cut -d '/' -f 6 | cut -d '"' -f 1 | cut -d "-" -f 2-10 | sed 's/-/./g')
- else
- ServerVersion="offline"
- fi
- fi
- fi
- }
- ReadConfig() {
- ServerScreen="GTB-Server"
- source LaunchServer.properties
- CheckConfig
- if [ "$1" == "--start" ] || [ "$1" == "--stop" ] || [ "$1" == "--help" ]; then
- Daemon=true
- else
- Daemon=false
- fi
- if ! "$MinimalMode" && ! "$Daemon"; then
- echo -e "${Blue}Loading...${None}"
- tput civis
- fi
- jar="$Jar.jar"
- if ! "$Backups"; then
- BackupAt='None'
- BackupInterval='00:00'
- BackupTime='never'
- fi
- WorldName="$(grep level-name server.properties | cut -d '=' -f 2)"
- if [ -z "$WorldName" ]; then
- WorldName=world
- fi
- World="./$WorldName"
- Online=true
- mode="-o true"
- if [ -z "$SSH_CLIENT" ]; then
- ping -t 1 -c 1 google.com > /dev/null 2>&1
- if [ "$?" -ne 0 ]; then
- ping -c 1 awardspace.com > /dev/null 2>&1
- if [ "$?" -ne 0 ]; then
- Online=false
- mode="-o false"
- fi
- fi
- fi
- ChangedMode=false
- if [ -z "$(grep 'online-mode=true' server.properties)" ]; then
- if [ "$mode" != "-o false" ]; then
- ChangedMode=false
- fi
- else
- mode="-o false"
- fi
- export LANG=C
- export LC_ALL=en_US.UTF-8
- export LC_CTYPE=en_US.UTF-8
- if [ ! -f .Tips.list ] && "$Online"; then
- curl -sL http://cblauncher.netne.net/Update/Tips.list -o .Tips.list
- fi
- Tip=$(sed -n $(perl -e "print int(rand($(wc -l < .Tips.list))) + 1")p < .Tips.list)
- if [ ! -z "$(echo $* | grep '-help')" ]; then
- echo "$Jar help:"
- java -jar $jar --help; exit
- fi
- if [ "$jar" == "CraftBukkit.jar" ]; then
- if [ "$Builds" == "recommended" ]; then
- Link=http://dl.bukkit.org/downloads/craftbukkit/get/latest-rb/craftbukkit.jar
- elif [ "$Builds" == "beta" ]; then
- Link=http://dl.bukkit.org/downloads/craftbukkit/get/latest-dev/craftbukkit-bet.jar
- elif [ "$Builds" == "developer" ]; then
- Link=http://dl.bukkit.org/downloads/craftbukkit/get/latest-dev/craftbukkit-dev.jar
- fi
- elif [ "$jar" == "Minecraft_Server.jar" ]; then
- arguments="--nogui $arguments"
- Link="https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar"
- elif [ "$jar" == "SpiGot.jar" ]; then
- Part1="http://ci.ecocitycraft.com/job/Spigot"
- Part2="artifact/Spigot/target/"
- if [ "$Builds" == "recommended" ]; then
- Link="$Part1/lastStableBuild/$Part2$(curl -s $Part1/lastStableBuild/$Part2 | grep ".jar" | cut -d '=' -f 16 | cut -d '"' -f 2)" #'
- elif [ "$Builds" == "beta" ] || [ "$Builds" == "developer" ]; then
- Link="$Part1/lastSuccessfulBuild/$Part2$(curl -s $Part1/lastSuccessfulBuild/$Part2 | grep ".jar" | cut -d '=' -f 16 | cut -d '"' -f 2)" #'
- fi
- fi
- }
- ConfigError() {
- echo -e "${Red}$1 setting: '${Purple}$2${Red}', please edit $it${None}"
- Open "LaunchServer.properties" "-a" "TextEdit"
- Exit
- }
- CheckConfig() {
- if [ -z "$DevSupport" ]; then
- ConfigError "Empty" "DevSupport"
- else
- if [ "$DevSupport" != "true" ] && [ "$DevSupport" != "false" ]; then
- ConfigError "Invalid" "DevSupport"
- fi
- fi
- if [ -z "$Jar" ]; then
- ConfigError "Empty" "Jar"
- else
- if [ "$Jar" != "CraftBukkit" ] && [ "$Jar" != "Minecraft_Server" ] && [ "$Jar" != "SpiGot" ]; then
- ConfigError "Invalid" "Jar"
- fi
- fi
- if [ -z "$Builds" ]; then
- ConfigError "Empty" "Builds"
- else
- if [ "$Builds" != "recommended" ] && [ "$Builds" != "beta" ] && [ "$Builds" != "developer" ]; then
- ConfigError "Invalid" "Builds"
- fi
- fi
- if [ -z "$RAM" ]; then
- ConfigError "Empty" "RAM"
- else
- if [ "$(echo "$RAM" | sed 's/^[0-9]*//')" == "$RAM" ]; then
- ConfigError "Invalid" "RAM"
- elif [ -z "$(echo $RAM | grep G)" ] && [ -z "$(echo $RAM | grep M)" ]; then
- ConfigError "Invalid" "RAM"
- fi
- fi
- if [ -z "$RAMDisk" ]; then
- ConfigError "Empty" "RAMDisk"
- else
- if [ "$RAMDisk" != "true" ] && [ "$RAMDisk" != "false" ]; then
- ConfigError "Invalid" "RAMDisk"
- fi
- fi
- if [ -z "$RAMDiskList" ] && [ "$RAMDisk" == "true" ]; then
- ConfigError "Empty" "RAMDiskList"
- else
- if [ ! -z "$(echo "$RAMDiskList" | grep 'script')" ] || [ ! -z "$(echo "$RAMDiskList" | grep 'Backups')" ]; then
- ConfigError "Invalid" "RAMDiskList"
- fi
- fi
- if [ -z "$MinimalMode" ]; then
- ConfigError "Empty" "MinimalMode"
- else
- if [ "$MinimalMode" != "true" ] && [ "$MinimalMode" != "false" ]; then
- ConfigError "Invalid" "MinimalMode"
- fi
- fi
- if [ ! -z "$(echo "$CommandPrefix" | grep ' ')" ]; then
- ConfigError "Invalid" "CommandPrefix"
- fi
- if [ -z "$Protips" ]; then
- ConfigError "Empty" "Protips"
- else
- if [ "$Protips" != "true" ] && [ "$Protips" != "false" ]; then
- ConfigError "Invalid" "Protips"
- fi
- fi
- if [ -z "$Backups" ]; then
- ConfigError "Empty" "Backups"
- else
- if [ "$Backups" != "true" ] && [ "$Backups" != "false" ]; then
- ConfigError "Invalid" "Backups"
- fi
- fi
- if [ -z "$BackupAt" ]; then
- ConfigError "Empty" "BackupAt"
- else
- if [ "$BackupAt" != "Start" ] && [ "$BackupAt" != "Stop" ] && [ "$BackupAt" != "Restart" ] && [ "$BackupAt" != "All" ]; then
- ConfigError "Invalid" "BackupAt"
- fi
- fi
- if [ -z "$OnlyScheduled" ]; then
- ConfigError "Empty" "OnlyScheduled"
- else
- if [ "$OnlyScheduled" != "true" ] && [ "$OnlyScheduled" != "false" ]; then
- ConfigError "Invalid" "OnlyScheduled"
- fi
- fi
- if [ -z "$BackupInterval" ]; then
- ConfigError "Empty" "BackupInterval"
- else
- if [ -z "$(echo "$BackupInterval" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#BackupInterval}" -ne 5 ]; then
- ConfigError "Invalid" "BackupInterval"
- fi
- fi
- if [ -z "$BackupLimit" ]; then
- ConfigError "Empty" "BackupLimit"
- else
- if [ "$(echo "$BackupLimit" | sed 's/^[-+0-9][0-9]*//' | wc -c)" -ne 1 ]; then
- ConfigError "Invalid" "BackupLimit"
- fi
- fi
- if [ -z "$BackupList" ]; then
- ConfigError "Empty" "BackupList"
- fi
- if [ -z "$BackupPlugins" ]; then
- ConfigError "Empty" "BackupPlugins"
- else
- if [ "$BackupPlugins" != "true" ] && [ "$BackupPlugins" != "false" ]; then
- ConfigError "Invalid" "BackupPlugins"
- fi
- fi
- if [ -z "$CompressBackups" ]; then
- ConfigError "Empty" "CompressBackups"
- else
- if [ "$CompressBackups" != "true" ] && [ "$CompressBackups" != "false" ]; then
- ConfigError "Invalid" "CompressBackups"
- fi
- fi
- if [ -z "$Schedule" ]; then
- ConfigError "Empty" "Schedule"
- else
- if [ "$Schedule" != "true" ] && [ "$Schedule" != "false" ]; then
- ConfigError "Invalid" "Schedule"
- fi
- fi
- if [ -z "$StartTime" ]; then
- ConfigError "Empty" "StartTime"
- else
- if [ -z "$(echo "$StartTime" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#StartTime}" -ne 5 ]; then
- if [ "$StartTime" != "now" ]; then
- ConfigError "Invalid" "StartTime"
- fi
- fi
- fi
- if [ -z "$StopTime" ]; then
- ConfigError "Empty" "StopTime"
- else
- if [ -z "$(echo "$StopTime" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#StopTime}" -ne 5 ]; then
- if [ "$StopTime" != "never" ]; then
- ConfigError "Invalid" "StopTime"
- fi
- fi
- fi
- if [ -z "$RestartInterval" ]; then
- ConfigError "Empty" "RestartInterval"
- else
- if [ -z "$(echo "$RestartInterval" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#RestartInterval}" -ne 5 ]; then
- ConfigError "Invalid" "RestartInterval"
- fi
- fi
- rm -f .IntervalTest
- }
- Configure() {
- echo -e "${Blue}No configuration was found, creating a configuration file and exiting${None}"
- echo -e '# Support the developer by viewing an adf.ly link (http://adf.ly/CNCVe) every time you use the script 5 times' > LaunchServer.properties
- echo -e '# The ad will open in your browser, and will not stop the script' >> LaunchServer.properties
- echo -e '# If you feel nice, turn this on :)' >> LaunchServer.properties
- echo -e 'DevSupport="false"\n' >> LaunchServer.properties
- echo -e '# # # # # # # # # #\n# #\n# Server #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
- echo -e '# Jar file to use' >> LaunchServer.properties
- echo -e '# Options: "CraftBukkit"; "Minecraft_Server"; "SpiGot"' >> LaunchServer.properties
- echo -e 'Jar="CraftBukkit"\n' >> LaunchServer.properties
- echo -e '# What type of build to use (ignored if Jar="Minecraft_Server")' >> LaunchServer.properties
- echo -e '# Options: recommended; beta; developer' >> LaunchServer.properties
- echo -e 'Builds="recommended"\n' >> LaunchServer.properties
- echo -e '# How much RAM the server should be able to use' >> LaunchServer.properties
- echo -e '# Options: any number (more than 2GBs on a small server is pointless)' >> LaunchServer.properties
- echo -e '# Examples: - 1G (=1GB)' >> LaunchServer.properties
- echo -e '# - 512M (=1/2GB)' >> LaunchServer.properties
- echo -e 'RAM="1G"\n' >> LaunchServer.properties
- echo -e '# # # # # # # # # #\n# #\n# Misc #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
- echo -e '# No fancy layout or features, just the updates and the server' >> LaunchServer.properties
- echo -e 'MinimalMode="false"\n' >> LaunchServer.properties
- echo -e '# Prefix for script commands, opposed to server commands' >> LaunchServer.properties
- echo -e "# Options: Can be anything (including nothing), but can't contain spaces" >> LaunchServer.properties
- echo -e 'CommandPrefix=""\n' >> LaunchServer.properties
- echo -e '# Protips on server start' >> LaunchServer.properties
- echo -e 'Protips="true"\n' >> LaunchServer.properties
- echo -e '# Use a RAM Disk makes loading and saving faster' >> LaunchServer.properties
- echo -e '# Not recommened as you might loose or corrupt your worlds if something goes wrong will the server is running' >> LaunchServer.properties
- echo -e 'RAMDisk="false"\n' >> LaunchServer.properties
- echo -e '# Worlds to move to the RAMDisk' >> LaunchServer.properties
- echo -e 'RAMDiskList="world\nworld_nether\nworld_the_end"\n\n' >> LaunchServer.properties
- echo -e '# # # # # # # # # #\n# #\n# Backups #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
- echo -e '# Backup worlds' >> LaunchServer.properties
- echo -e 'Backups="true"\n' >> LaunchServer.properties
- echo -e '# When to backup' >> LaunchServer.properties
- echo -e '# Options: Start (script); Stop (script); Restart (server); All' >> LaunchServer.properties
- echo -e 'BackupAt="Start"\n' >> LaunchServer.properties
- echo -e '# Only backup when the server is (re)started/stopped by the schedule' >> LaunchServer.properties
- echo -e '# (ignored if Schedule="false")' >> LaunchServer.properties
- echo -e 'OnlyScheduled="true"\n' >> LaunchServer.properties
- echo -e '# Only keep X backups (oldest will be deleted)' >> LaunchServer.properties
- echo -e 'BackupLimit="5"\n' >> LaunchServer.properties
- echo -e '# Worlds to backup' >> LaunchServer.properties
- echo -e 'BackupList="world\nworld_nether\nworld_the_end"\n' >> LaunchServer.properties
- echo -e '# Backup plugins'"'"' configurations, but not the plugins themselves (.jar)' >> LaunchServer.properties
- echo -e 'BackupPlugins="false"\n' >> LaunchServer.properties
- echo -e '# Compress backups to save space (uses "'$(which tar)'")' >> LaunchServer.properties
- echo -e 'CompressBackups="true"\n\n' >> LaunchServer.properties
- echo -e '# # # # # # # # # #\n# #\n# Schedule #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
- echo -e '# Use the schedule option (Forces MinimalMode="false")' >> LaunchServer.properties
- echo -e 'Schedule="false"\n' >> LaunchServer.properties
- echo -e '# When the server should automatically start/stop (ignored if Schedule="false")' >> LaunchServer.properties
- echo -e '# Options: HH:MM; $(In HH:MM); now (only for StartTime); never (only for StopTime)' >> LaunchServer.properties
- echo -e '# Examples: - StartTime="18:30" (=Start at 6:30 PM)' >> LaunchServer.properties
- echo -e '# - StartTime="$(In 00:05)" (=Start 5 minutes after the script is opened)' >> LaunchServer.properties
- echo -e 'StartTime="now"' >> LaunchServer.properties
- echo -e 'StopTime="never"\n' >> LaunchServer.properties
- echo -e '# Interval between world backups (ignored if Schedule="false")' >> LaunchServer.properties
- echo -e '# Examples: - 00:00 (=never)' >> LaunchServer.properties
- echo -e '# - 00:10 (=every 10 minutes)' >> LaunchServer.properties
- echo -e '# - 01:30 (=every 1h30)' >> LaunchServer.properties
- echo -e 'BackupInterval="00:00"\n' >> LaunchServer.properties
- echo -e '# Interval between server restarts (ignored if Schedule="false")' >> LaunchServer.properties
- echo -e '# Examples: - 00:00 (=never)' >> LaunchServer.properties
- echo -e '# - 00:10 (=every 10 minutes)' >> LaunchServer.properties
- echo -e '# - 01:30 (=every 1h30)' >> LaunchServer.properties
- echo -e 'RestartInterval="00:00"\n' >> LaunchServer.properties
- echo -e '# Commands to run before/after restarting the server' >> LaunchServer.properties
- echo -e '# One command per line:' >> LaunchServer.properties
- echo -e '# Before/AfterRestart="say First Command' >> LaunchServer.properties
- echo -e '# say Second Command"' >> LaunchServer.properties
- echo -e 'BeforeRestart="say Schedulede restart. See you in a sec!"' >> LaunchServer.properties
- echo -e 'AfterRestart=""' >> LaunchServer.properties
- Open "LaunchServer.properties" "-a" "TextEdit"
- }
- In() {
- if [ -z "$2" ]; then
- Start=$(date +'%R')
- End="$1"
- else
- Start="$1"
- End="$2"
- fi
- Part1=
- Part2=
- N1=$(echo "$Start" | cut -d ':' -f 1 | sed 's/^0*//'); if [ -z "$N1" ]; then N1="0"; fi
- N2=$(echo "$Start" | cut -d ':' -f 2 | sed 's/^0*//'); if [ -z "$N2" ]; then N2="0"; fi
- A1=$(echo "$End" | cut -d ':' -f 1 | sed 's/^0*//'); if [ -z "$A1" ]; then A1="0"; fi
- A2=$(echo "$End" | cut -d ':' -f 2 | sed 's/^0*//'); if [ -z "$A2" ]; then A2="0"; fi
- Part2=$(( $N2 + $A2 ))
- if [ "$A1" == "00" ]; then
- Part1=$N1
- fi
- if [ "$Part2" -gt 60 ]; then
- Part1=$(( (Part2 / 60) + $A1 + $N1 ))
- Part2=$(( Part2 % 60 ))
- elif [ "$Part2" -eq 60 ]; then
- Part2=00
- Part1=$(( 1 + $A1 + $N1 ))
- else
- Part1=$(( $A1 + $N1 ))
- fi
- Part1=$((Part1 % 24))
- Part1=$(echo -n "$Part1" | sed 's/^-*//')
- Part2=$(echo -n "$Part2" | sed 's/^-*//')
- if [ $(echo -n "$Part1" | wc -m) -eq 1 ]; then Part1="0$Part1"; fi; if [ -z "$Part1" ]; then Part1="00"; fi
- if [ $(echo -n "$Part2" | wc -m) -eq 1 ]; then Part2="0$Part2"; fi; if [ -z "$Part2" ]; then Part2="00"; fi
- echo "$Part1:$Part2"
- }
- Do() {
- if [ $"1" == "Undo" ]; then
- if [ -f "$Jar"_Old.jar ]; then
- mv -f "$jar" "$Jar"_New.jar > /dev/null 2>&1
- mv -f "$Jar"_Old.jar "$jar" > /dev/null 2>&1
- clear
- echo -e "${Green}The update was successfully undone${None}"
- fi
- elif [ "$1" == "Redo" ]; then
- if [ -f "$Jar"_New.jar ]; then
- mv -f "$jar" "$Jar"_Old.jar > /dev/null 2>&1
- mv -f "$Jar"_New.jar "$jar" > /dev/null 2>&1
- clear
- echo -e "${Green}The update was successfully redone${None}"
- fi
- fi
- }
- DontDo() {
- if [ "$1" == "Undo" ]; then
- echo -e "\n${Blue}Update was not undone${None}"
- echo -e "${Green}Can I delete ${Jar}_Old.jar (needed to undo the update)? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Delete
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Delete" in
- y | yes) rm -f "$Jar"_Old.jar;;
- n | no ) echo -e "\n${Blue}${Jar}_Old.jar was left, you will be asked agin if you want to undo the update${None}";;
- esac
- elif [ "$1" == "Redo" ]; then
- echo -e "\n${Blue}Update was not redone${None}"
- echo -e "${Green}Can I delete ${Jar}_New.jar (needed to redo the update)? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Delete
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Delete" in
- y | yes) rm -f "$Jar"_New.jar;;
- n | no ) clear; echo -e "\n${Blue}${Jar}_New.jar was left, you will be asked agin if you want to redo the update${None}";;
- esac
- fi
- }
- ChangeLog() {
- ChangeLog=Displayed
- curl -sL http://cblauncher.netne.net/Update/Changelog.list -o ./script/temp/Changelog.list
- if [ "$1" == "Continue" ]; then
- clear
- fi
- echo -e "${Blue}Changelog for version ${Purple}$LatestVersion${Blue} :${None}"
- while read Change; do
- if [ -n "$Change" ]; then
- echo -e "${Blue}\t- $Change${None}"
- fi
- done < ./script/temp/Changelog.list
- if [ "$1" == "Wait" ]; then
- echo -e "\n${Blue}Press enter when done reading.${None}"
- tput cnorm
- read -p ": " NULL
- if ! "$MinimalMode"; then
- tput civis
- fi
- fi
- rm -f ./script/temp/Changelog.list
- }
- CheckForLauncherUpdates() {
- curl -sL http://cblauncher.netne.net/Update/General.list -o ./script/temp/General.list
- source ./script/temp/General.list
- if [ "$ThisVersion" != "$LatestVersion" ] && "$Critical" && ! "$Silent"; then
- echo -e "${Green}A Critical update was found. Proceeding to update${None}"
- UpdateLauncher
- elif [ "$LatestVersion" != "0.4" ] && "$Critical" && "$Silent"; then
- UpdateLauncher Silent
- fi
- if [ "$ThisVersion" != "$LatestVersion" ] && ! "$Critical"; then
- echo -e "${Green}An update for the server launcher is available${None}"
- for (( i = 0; i < 1; j = 0)); do
- echo -e "${Green}Would you like to update now? (${Purple}Yes${Green}/${Purple}No${Green}/[${Purple}C${Green}]hangelog${Green})${None}"
- tput cnorm
- read -p ": " Update
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Update" in
- y | yes ) UpdateLauncher; i=2;;
- n | no ) i=3;;
- c | changelog ) ChangeLog Continue; i=0;;
- esac
- done
- clear
- if [ $i -eq 3 ]; then
- echo -e "${Green}Continuing without updating the launcher${None}"
- fi
- else
- if "$MinimalMode"; then
- echo -e "${Green}Your Server Launcher is up to date! (version ${Purple}$ThisVersion${Green})${None}"
- else
- LauncherUpToDate=true
- fi
- fi
- rm -f ./script/temp/General.list
- }
- UpdateLauncher() {
- if [ "$1" != "Silent" ]; then
- curl -L http://cblauncher.netne.net/Update/LaunchServer.command -o ./script/temp/NewLauncher.command --progress-bar
- else
- curl -sL http://cblauncher.netne.net/Update/LaunchServer.command -o ./script/temp/NewLauncher.command
- fi
- chmod +x ./script/temp/NewLauncher.command
- curl -sL http://cblauncher.netne.net/Update/Tips.list -o .Tips.list
- if [ "$1" != "Silent" ]; then
- clear
- echo -e "${Green}The launcher was successfully updated${None}"
- if [ -z "$ChangeLog" ]; then
- ChangeLog Wait
- fi
- fi
- if "$Reconfigure"; then
- curl -sL http://cblauncher.netne.net/Update/NewOptions.command -o ./script/temp/NewOptions.command
- chmod +x ./script/temp/NewOptions.command
- ./script/temp/NewOptions.command
- rm -f ./script/temp/NewOptions.command
- Open "LaunchServer.properties" "-a" "TextEdit"
- fi
- rm -rf ./script/*.*
- rm "$0"
- mv -f ./script/temp/NewLauncher.command ./LaunchServer.command
- if ! "$Reconfigure"; then
- ./LaunchServer.command
- fi
- exit
- }
- CheckForServerUpdates() {
- if "$Linux"; then
- Local=$(stat -c%s ./"$jar")
- else
- Local=$(stat -f "%z" ./"$jar")
- fi
- Remote=$(curl --connect-timeout 3 --max-time 3 -sLI "$Link" | awk '/Content-Length/ {sub("\r",""); print $2}')
- Remote=$(echo "$Remote" | sed -n $(echo "$Remote" | wc -l)p)
- if [ -z "$Remote" ]; then
- ServerUpToDate=offline
- return 0
- fi
- if [ "$Local" -ne "$Remote" ]; then
- if "$MinimalMode"; then
- echo -e '\n'
- else
- ServerUpToDate=false
- fi
- echo -e "${Green}An update for $Jar is available${None}"
- echo -e "${Green}Do you want to update now? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Update
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Update" in
- y | yes) UpdateServer;;
- n | no ) clear;;
- esac
- ServerVersion
- elif [ "$Local" -eq "$Remote" ]; then
- if "$MinimalMode"; then
- if [ "$Jar" == "Minecraft_Server" ]; then
- echo -e "${Green}$jar is up to date! (version ${Purple}$ServerVersion${Green})${None}"
- else
- echo -e "${Green}$Jar is up to date! (latest ${Purple}$Builds${Green} build: ${Purple}${ServerVersion}${Green})${None}"
- fi
- else
- ServerUpToDate=true
- fi
- fi
- }
- UpdateServer() {
- clear
- echo -e "${Blue}Updating server...${None}"
- echo -e "${Blue}Backed up $jar to ${Jar}_Old.jar in case something goes wrong.${None}\n"
- mv -f "$jar" "$Jar"_Old.jar
- echo -e "${Blue}Downloading $jar:${None}"
- curl -L "$Link" -o "$jar" --progress-bar
- clear
- echo -e "${Green}Your server was updated.${None}"
- echo -e "${Red}WARNING: An update may break plugins! Please ensure all plugins installed are up to date.\n${None}"
- if ! "$MinimalMode"; then
- ServerUpToDate=true
- fi
- }
- PrepareFiles() {
- mkdir -p ./script/temp/dummies
- mkdir -p ./script/temp/screen
- # chflags hidden ./script
- if [ "$1" == "Server" ]; then
- touch banned-players.txt banned-ips.txt ops.txt server.log server.properties white-list.txt
- if [ -f server.log.lck ] && [ -z "$(screen -ls | grep "$ServerScreen")" ]; then
- echo "A server is already running, and it wasn't started with this script, please stop it and try again"
- Exit
- fi
- if [ -f bukkit.yml ]; then
- while read; do
- if [ "$REPLY" == ' enabled: true' ]; then
- printf ' enabled: false\n'
- else
- echo "$REPLY"
- fi
- done < bukkit.yml > ./script/temp/bukkit.yml
- mv -f ./script/temp/bukkit.yml bukkit.yml
- else
- printf 'auto-updater:\n enabled: false\n' >> bukkit.yml
- fi
- elif [ "$1" == "Jar" ]; then
- if [ -f "$Jar"_New.jar ]; then
- echo -e "${Green}Would you like to redo the update? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Redo
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Redo" in
- y | yes) Do Redo;;
- n | no ) DontDo Redo;;
- esac
- elif [ -f "$Jar"_Old.jar ]; then
- clear
- echo -e "${Green}Would you like to undo the update? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Undo
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Undo" in
- y | yes) Do Undo;;
- n | no ) DontDo Undo;;
- esac
- fi
- if ! "$Online"; then
- if [ -f "$jar" ]; then
- if "$MinimalMode"; then
- echo -e "${Red}Could not check for updates, the server will start in offline mode${None}"
- fi
- mode="-o false"
- elif [ ! -f "$jar" ] && [ ! -f "$Jar"_Old.jar ] && [ ! -f "$Jar"_New.jar ]; then
- echo -e "${Red}Could not check for updates, and $jar was not found${None}"
- echo -e "${Red}The server will not start, please connect to the internet to download $jar${None}"
- Exit
- elif [ ! -f "$jar" ] && [ -f "$Jar"_Old.jar ] && [ ! -f "$Jar"_New.jar ]; then
- echo -e "${Red}Could not check for updates, and $jar was not found${None}"
- echo -e "${Green}I found ${Jar}_Old.jar, should I use it instead? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Use
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Use" in
- y | yes) jar="$Jar"_Old.jar; mode="-o false"; return 0;;
- n | no ) echo -e "${Red}The server will not start, please connect to the internet to download $jar${None}"; Exit;;
- esac
- elif [ ! -f "$jar" ] && [ ! -f "$Jar"_Old.jar ] && [ -f "$Jar"_New.jar ]; then
- echo -e "${Red}Could not check for updates, and $jar was not found${None}"
- echo -e "${Green}I found ${Jar}_New.jar, should I use it instead? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
- tput cnorm
- read -p ": " Use
- if ! "$MinimalMode"; then
- tput civis
- fi
- shopt -s nocasematch
- case "$Use" in
- y | yes) jar="$Jar"_New.jar; mode="-o false"; return 0;;
- n | no ) echo -e "${Red}The server will not start, please connect to the internet to download $jar${None}"; Exit;;
- esac
- fi
- fi
- if [ ! -f "$jar" ] && "$Online"; then
- echo -e "${Red}$jar was not found, it will be redownloaded:${None}"
- curl -L "$Link" -o "$jar" --progress-bar
- clear
- fi
- ServerVersion
- elif [ "$1" == "Screen" ]; then
- Columns=$(tput cols)
- Lines=$(tput lines)
- if [ "$Lines" -lt 31 ]; then
- MenuLines=$(( Lines * 1 / 4 ))
- elif [ "$Lines" -gt 30 ]; then
- MenuLines=$(( Lines * 1 / 3 ))
- fi
- ViewLines=$(( Lines - MenuLines ))
- echo -e 'startup_message off' > ./script/temp/screen/Main.conf
- echo -e 'screen -t Script-Menu 2 ./script/Main.sh' >> ./script/temp/screen/Main.conf
- echo -e 'screen -t Server-View 1 ./script/View.sh\n' >> ./script/temp/screen/Main.conf
- echo -e 'split\n' >> ./script/temp/screen/Main.conf
- echo -e "resize $ViewLines" >> ./script/temp/screen/Main.conf
- echo -e 'focus down\n' >> ./script/temp/screen/Main.conf
- echo -e "resize $MenuLines" >> ./script/temp/screen/Main.conf
- echo -e 'select Script-Menu' >> ./script/temp/screen/Main.conf
- echo -e 'startup_message off' > ./script/temp/screen/Schedule.conf
- echo -e 'screen 1 ./script/Schedule.sh' >> ./script/temp/screen/Schedule.conf
- echo -e 'startup_message off' > ./script/temp/screen/Server.conf
- echo -e 'screen 1 ./script/Server.sh' >> ./script/temp/screen/Server.conf
- elif [ "$1" == "Script" ]; then
- if "$Protips"; then
- echo "PROTIP: $Tip" > ./script/temp/Notifications
- fi
- if [ ! -f LauncherAliases.properties ]; then
- echo -e '# Put your aliases here for the launcher to use' >> LauncherAliases.properties
- echo -e '# These are not accesible when MinimalMode="true"' >> LauncherAliases.properties
- echo -e '# The aliases will be checked live, so you can update this file while the server is running' >> LauncherAliases.properties
- echo -e 'Example="say This is an example alias\nsay You can have multiple lines!"' >> LauncherAliases.properties
- fi
- if ! "$MinimalMode"; then
- Missing=0
- touch ./script/temp/dummies/_ScriptIsOn
- touch ./script/temp/dummies/_Run
- if [ ! -f "./script/Main.sh" ]; then
- ((Missing++))
- MissingFiles="$MissingFiles$(echo -e 'Main.sh\t')"
- else
- chmod +x ./script/Main.sh
- fi
- if [ ! -f "./script/MCQuery.py" ]; then
- ((Missing++))
- MissingFiles="$MissingFiles$(echo -e 'MCQuery.py\t')"
- fi
- if [ ! -f "./script/Schedule.sh" ]; then
- ((Missing++))
- MissingFiles="$MissingFiles$(echo -e 'Schedule.sh\t')"
- else
- chmod +x ./script/Schedule.sh
- fi
- if [ ! -f "./script/Server.sh" ]; then
- ((Missing++))
- MissingFiles="$MissingFiles$(echo -e 'Server.sh\t')"
- else
- chmod +x ./script/Server.sh
- fi
- if [ ! -f "./script/Utilities.sh" ]; then
- ((Missing++))
- MissingFiles="$MissingFiles$(echo -e 'Utilities.sh\t')"
- else
- chmod +x ./script/Utilities.sh
- fi
- if [ ! -f "./script/View.sh" ]; then
- ((Missing++))
- MissingFiles="$MissingFiles$(echo -e 'View.sh\t')"
- else
- chmod +x ./script/View.sh
- fi
- if [ "$Missing" -ne 0 ]; then
- echo -e "${Red}Some script files are missing${None}"
- if "$Online"; then
- echo -e "${Blue}Downloading missing files:${None}"
- for ((i=1; i<=Missing; i++)); do
- File="$(echo "$MissingFiles" | cut -f $i)"
- curl -L http://cblauncher.netne.net/Update/script/"$File" -o ./script/"$File" --progress-bar
- chmod +x ./script/"$File"
- done
- ./LaunchServer.command; exit
- else
- echo -e "${Red}Could not download them: you are not connected to the internet${None}"
- Exit
- fi
- fi
- fi
- fi
- }
- Dependencies() {
- if [ -z "$(which curl)" ]; then
- echo -e "${Blue}Installing ${Purple}curl${Blue}:${None}"
- SudoAuthorization "to install curl"
- sudo apt-get install curl
- if [ $? -ne 0 ]; then
- echo -e "${Red}There was an error while installing ${Purple}curl${None}"
- Exit 1
- fi
- clear
- fi
- if [ -z "$(which java)" ]; then
- echo -e "${Red}Java is required to run the Minecraft Server{None}"
- echo -e "You can install it manually here: ${Blue}http://java.com/en/download/linux_manual.jsp${None}"
- echo -e "Or install it from the command line:"
- echo -e "sudo add-apt-repository ppa:webupd8team/java"
- echo -e "sudo apt-get update"
- echo -e "sudo apt-get install oracle-java7-installer"
- Exit 1
- fi
- if [ -z "$(which python)" ]; then
- echo -e "${Blue}Installing ${Purple}python${Blue}:${None}"
- SudoAuthorization "to install python"
- sudo apt-get install python
- if [ $? -ne 0 ]; then
- echo -e "${Red}There was an error while installing ${Purple}python${None}"
- Exit 1
- fi
- clear
- fi
- if [ -z "$(which screen)" ]; then
- echo -e "${Blue}Installing ${Purple}screen${Blue}:${None}"
- SudoAuthorization "to install screen"
- sudo apt-get install screen
- if [ $? -ne 0 ]; then
- echo -e "${Red}There was an error while installing ${Purple}screen${None}"
- Exit 1
- fi
- clear
- fi
- }
- SudoAuthorization() {
- echo -e "${Blue}Please type your password, it is required $1${None}"
- tput cnorm
- sudo printf ""
- if [ "$?" -eq 0 ]; then
- echo -e "${Blue}Thank you${None}"
- else
- echo -e "${Red}Error, aborting!${None}"
- Exit
- fi
- }
- SendStats() {
- Date=$(date)
- if [ "$ThisVersion" == "$LatestVersion" ]; then ThisVersion="$ThisVersion (Latest)"; fi
- if [ ! -f ~/.com.Pierre-Louis.CBlauncher ]; then
- touch ~/.com.Pierre-Louis.CBlauncher
- curl -d "Date=$Date&Action=Install&Version=$ThisVersion&submit=submit" -L http://cblauncher.netne.net/record_stats.php > /dev/null 2>&1
- fi
- curl -d "Date=$Date&Action=Launch&Version=$ThisVersion&submit=submit" -L http://cblauncher.netne.net/record_stats.php > /dev/null 2>&1
- }
- Open() {
- if [ -f "$1" ] || [ ! -z "$(echo $* | grep 'http://')" ]; then
- if [ ! -z "$SSH_CLIENT" ]; then
- if [ -f "$1" ]; then
- if [ -f "$1" ]; then
- echo -e "Press enter to open '$1' with nano"
- echo -e "To cancel, press 'Ctrl + C'"
- tput cnorm
- read -p ": " NULL
- if ! "$MinimalMode"; then
- tput civis
- fi
- nano "$1"
- else
- Exit
- fi
- fi
- elif "$Linux"; then
- xdg-open "$1"
- else
- open "$2" "$3" "$1"
- fi
- fi
- }
- Exit() {
- if [ "$1" == "EndOfScript" ] && "$ChangedMode" && [ "$mode" == "-o false" ]; then
- while read; do
- if [ "$REPLY" == "online-mode=true" ]; then
- echo "online-mode=false"
- else
- echo "$REPLY"
- fi
- done < server.properties > .server.properties
- mv -f .server.properties server.properties
- elif [ "$1" != "EndOfScript" ] && [ ! -z "$1" ]; then
- ExitCode="$1"
- fi
- tput cnorm
- rm -rf ./script/temp
- exit $ExitCode
- }
- Main() {
- clear
- cd "$(dirname "$0")"
- if [ -f ./script/temp/dummies/_Closed ] && [ "$1" != "--stop" ]; then
- echo -e "${Blue}Resuming...${None}"
- touch ./script/temp/dummies/_ScriptIsOn
- source ./script/temp/vars.conf
- Start
- else
- Linux=false
- Debian=false
- Ubuntu=false
- if [ ! -z "$(uname -a | grep Linux)" ]; then
- Linux=true
- if [ ! -z "$(uname -a | grep Debian)" ] || [ "$(lsb_release -i -s)" == "Debian" ]; then
- Debian=true
- elif [ ! -z "$(uname -a | grep Ubuntu)" ] || [ "$(lsb_release -i -s)" == "Ubuntu" ]; then
- Ubuntu=true
- fi
- Dependencies
- fi
- if [ "$1" == "--start" ] || [ "$1" == "--stop" ]; then
- ReadConfig $*
- PrepareFiles Server
- PrepareFiles Screen
- PrepareFiles Script
- ExportVars
- Daemon $*
- else
- PrepareFiles Server
- if [ -f LaunchServer.properties ]; then
- ReadConfig $*
- else
- Configure
- Exit
- fi
- PrepareFiles Screen
- PrepareFiles Script
- PrepareFiles Jar
- if "$Online"; then
- CheckForLauncherUpdates
- CheckForServerUpdates
- if "$DevSupport"; then
- if [ -f .AdCount ]; then
- source .AdCount
- else
- LaunchNumber=5
- fi
- if [ "$LaunchNumber" -ne 5 ]; then
- echo -e "LaunchNumber=$((LaunchNumber + 1))\nAdViewed=$AdViewed" > .AdCount
- else
- echo -e "LaunchNumber=1\nAdViewed=$((AdViewed + 1))" >> .AdCount
- Open http://adf.ly/CNCVe
- fi
- fi
- else
- LauncherUpToDate="offline"
- ServerUpToDate="offline"
- fi
- fi
- ExportVars
- tput cnorm
- Start
- Exit EndOfScript
- fi
- }
- # # # # # # # # # # #
- # #
- # End Of Functions #
- # #
- # # # # # # # # # # #
- ThisVersion="1.0.6"
- None='\033[0m'
- Black='\033[0;30m'
- Blue='\033[0;34m'
- Cyan='\033[0;36m'
- Green='\033[0;32m'
- Purple='\033[0;35m'
- Red='\033[0;31m'
- Yellow='\033[0;33m'
- Main $*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement