mtaserver 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2017 Daniel Gibbs
  5. # Purpose: Multi Theft Auto | 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. if [ -f ".dev-debug" ]; then
  10. exec 5>dev-debug.log
  11. BASH_XTRACEFD="5"
  12. set -x
  13. fi
  14. version="1700305"
  15. ##########################
  16. ######## Settings ########
  17. ##########################
  18. #### Server Settings ####
  19. ## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
  20. # None Available
  21. ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
  22. # Edit with care
  23. fn_parms(){
  24. parms=" "
  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. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  38. maxbackups="4"
  39. maxbackupdays="30"
  40. stoponbackup="on"
  41. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  42. consolelogging="on"
  43. logdays="7"
  44. #### LinuxGSM Advanced Settings ####
  45. # Github Branch Select
  46. # Allows for the use of different function files
  47. # from a different repo and/or branch.
  48. githubuser="dgibbs64"
  49. githubrepo="linuxgsm"
  50. githubbranch="master"
  51. ## LinuxGSM Server Details
  52. # Do not edit
  53. gamename="Multi Theft Auto"
  54. engine="renderware"
  55. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  56. servicename="mta-server"
  57. #### Directories ####
  58. # Edit with care
  59. ## Work Directories
  60. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  61. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  62. lockselfname=".${servicename}.lock"
  63. lgsmdir="${rootdir}/lgsm"
  64. functionsdir="${lgsmdir}/functions"
  65. libdir="${lgsmdir}/lib"
  66. tmpdir="${lgsmdir}/tmp"
  67. filesdir="${rootdir}/serverfiles"
  68. ## Server Specific Directories
  69. systemdir="${filesdir}"
  70. resourcesdir="${systemdir}/mods/deathmatch/resources"
  71. executabledir="${systemdir}"
  72. executable="./mta-server64"
  73. servercfg="mtaserver.conf"
  74. servercfgdir="${systemdir}/mods/deathmatch"
  75. servercfgfullpath="${servercfgdir}/${servercfg}"
  76. ## Backup Directory
  77. backupdir="${rootdir}/backups"
  78. ## Logging Directories
  79. gamelogdir="${filesdir}/mods/deathmatch/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 '+%d-%m-%Y-%H-%M-%S').log"
  87. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%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