mcserver 5.0 KB

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