mcserver 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2017 Daniel Gibbs
  5. # Purpose: Minecraft | Server Management Script
  6. # Contributors: https://github.com/GameServerManagers/LinuxGSM/graphs/contributors
  7. # Documentation: https://github.com/GameServerManagers/LinuxGSM/wiki
  8. # Website: https://gameservermanagers.com
  9. # Debugging
  10. if [ -f ".dev-debug" ]; then
  11. exec 5>dev-debug.log
  12. BASH_XTRACEFD="5"
  13. set -x
  14. fi
  15. version="170212"
  16. ##########################
  17. ######## Settings ########
  18. ##########################
  19. #### Server Settings ####
  20. ## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
  21. javaram="1024" # -Xmx$1024M
  22. ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
  23. fn_parms(){
  24. parms="nogui"
  25. }
  26. #### LinuxGSM Settings ####
  27. ## Notification Alerts
  28. # (on|off)
  29. # Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
  30. emailalert="off"
  31. email="email@example.com"
  32. emailfrom=""
  33. # Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
  34. pushbulletalert="off"
  35. pushbullettoken="accesstoken"
  36. channeltag=""
  37. ## Updating | https://github.com/GameServerManagers/LinuxGSM/wiki/Update
  38. updateonstart="off"
  39. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  40. maxbackups="4"
  41. maxbackupdays="30"
  42. stoponbackup="on"
  43. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  44. consolelogging="on"
  45. logdays="7"
  46. #### LinuxGSM Advanced Settings ####
  47. ## Github Branch Select
  48. # Allows for the use of different function files
  49. # from a different repo and/or branch.
  50. githubuser="GameServerManagers"
  51. githubrepo="LinuxGSM"
  52. githubbranch="master"
  53. ## LinuxGSM Server Details
  54. # Do not edit
  55. gamename="Minecraft"
  56. engine="lwjgl2"
  57. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  58. servicename="mc-server"
  59. #### Directories ####
  60. # Edit with care
  61. ## Work Directories
  62. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  63. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  64. lockselfname=".${servicename}.lock"
  65. lgsmdir="${rootdir}/lgsm"
  66. functionsdir="${lgsmdir}/functions"
  67. filesdir="${rootdir}/serverfiles"
  68. ## Server Specific Directories
  69. systemdir="${filesdir}"
  70. executabledir="${filesdir}"
  71. executable="java -Xmx${javaram}M -jar ${filesdir}/minecraft_server.jar"
  72. servercfg="server.properties"
  73. servercfgdefault="server.properties"
  74. servercfgdir="${filesdir}"
  75. servercfgfullpath="${servercfgdir}/${servercfg}"
  76. ## Backup Directory
  77. backupdir="${rootdir}/backups"
  78. ## Logging Directories
  79. gamelogdir="${systemdir}/logs"
  80. scriptlogdir="${rootdir}/log/script"
  81. consolelogdir="${rootdir}/log/console"
  82. scriptlog="${scriptlogdir}/${servicename}-script.log"
  83. consolelog="${consolelogdir}/${servicename}-console.log"
  84. emaillog="${scriptlogdir}/${servicename}-email.log"
  85. ## Logs Naming
  86. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  87. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
  88. ########################
  89. ######## Script ########
  90. ###### Do not edit #####
  91. ########################
  92. # Fetches core_dl for file downloads
  93. fn_fetch_core_dl(){
  94. github_file_url_dir="lgsm/functions"
  95. github_file_url_name="${functionfile}"
  96. filedir="${functionsdir}"
  97. filename="${github_file_url_name}"
  98. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  99. # If the file is missing, then download
  100. if [ ! -f "${filedir}/${filename}" ]; then
  101. if [ ! -d "${filedir}" ]; then
  102. mkdir -p "${filedir}"
  103. fi
  104. echo -e " fetching ${filename}...\c"
  105. # Check curl exists and use available path
  106. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  107. for curlcmd in ${curlpaths}
  108. do
  109. if [ -x "${curlcmd}" ]; then
  110. break
  111. fi
  112. done
  113. # If curl exists download file
  114. if [ "$(basename ${curlcmd})" == "curl" ]; then
  115. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  116. if [ $? -ne 0 ]; then
  117. echo -e "\e[0;31mFAIL\e[0m\n"
  118. echo "${curlfetch}"
  119. echo -e "${githuburl}\n"
  120. exit 1
  121. else
  122. echo -e "\e[0;32mOK\e[0m"
  123. fi
  124. else
  125. echo -e "\e[0;31mFAIL\e[0m\n"
  126. echo "Curl is not installed!"
  127. echo -e ""
  128. exit 1
  129. fi
  130. chmod +x "${filedir}/${filename}"
  131. fi
  132. source "${filedir}/${filename}"
  133. }
  134. core_dl.sh(){
  135. # Functions are defined in core_functions.sh.
  136. functionfile="${FUNCNAME}"
  137. fn_fetch_core_dl
  138. }
  139. core_functions.sh(){
  140. # Functions are defined in core_functions.sh.
  141. functionfile="${FUNCNAME}"
  142. fn_fetch_core_dl
  143. }
  144. # Prevent from running this script as root.
  145. if [ "$(whoami)" = "root" ]; then
  146. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  147. echo "[ FAIL ] Do NOT run this script as root!"
  148. exit 1
  149. else
  150. core_functions.sh
  151. check_root.sh
  152. fi
  153. fi
  154. core_dl.sh
  155. core_functions.sh
  156. getopt=$1
  157. core_getopt.sh