4
0

rustserver 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2016 Daniel Gibbs
  5. # Purpose: Rust | 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. # More settings available after install in serverfiles/server/rust-server/server.cfg
  22. servername="Rust"
  23. ip="0.0.0.0"
  24. port="28015"
  25. rconport="28016"
  26. rconpassword="CHANGE_ME"
  27. maxplayers="50"
  28. # Advanced Start Settings
  29. seed="" # default random; range : 1 to 2147483647 ; used to change or reproduce a procedural map
  30. worldsize="3000" # default 3000; range : 1000 to 6000 ; map size in meters
  31. saveinterval="300" # Auto-save in seconds
  32. tickrate="30" # default 30; range : 15 to 100
  33. ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
  34. # Edit with care | https://developer.valvesoftware.com/wiki/Rust_Dedicated_Server
  35. fn_parms(){
  36. parms="-batchmode +server.ip ${ip} +server.port ${port} +server.tickrate ${tickrate} +server.hostname \"${servername}\" +server.identity \"${servicename}\" ${conditionalseed} +server.maxplayers ${maxplayers} +server.worldsize ${worldsize} +server.saveinterval ${saveinterval} +rcon.ip ${ip} +rcon.port ${rconport} +rcon.password \"${rconpassword}\" -logfile ${gamelogfile}"
  37. }
  38. # Specific to Rust
  39. if [ -n "${seed}" ]; then
  40. # If set, then add to start parms
  41. conditionalseed="+server.seed ${seed}"
  42. else
  43. # Keep randomness of the number if not set
  44. conditionalseed=""
  45. fi
  46. #### LinuxGSM Settings ####
  47. ## Notification Alerts
  48. # (on|off)
  49. # Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
  50. emailalert="off"
  51. email="email@example.com"
  52. emailfrom=""
  53. # Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
  54. pushbulletalert="off"
  55. pushbullettoken="accesstoken"
  56. # Pushbullet Channel | Do not set unless the channel exists on the
  57. # account associated with the access token. Set without using the '#'
  58. # E.g: "thisisachanneltag" would push to #thisisachanneltag
  59. channeltag=""
  60. ## Updating | https://github.com/GameServerManagers/LinuxGSM/wiki/Update
  61. updateonstart="off"
  62. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  63. maxbackups="4"
  64. maxbackupdays="30"
  65. stoponbackup="on"
  66. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  67. consolelogging="on"
  68. logdays="7"
  69. #### LinuxGSM Advanced Settings ####
  70. ## SteamCMD Settings
  71. # Server appid
  72. appid="258550"
  73. # Steam App Branch Select
  74. # Allows to opt into the various Steam app branches. Default branch is "".
  75. # Example: "-beta latest_experimental"
  76. branch=""
  77. ## Github Branch Select
  78. # Allows for the use of different function files
  79. # from a different repo and/or branch.
  80. githubuser="GameServerManagers"
  81. githubrepo="LinuxGSM"
  82. githubbranch="master"
  83. ## LinuxGSM Server Details
  84. # Do not edit
  85. gamename="Rust"
  86. engine="unity3d"
  87. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  88. servicename="rust-server"
  89. #### Directories ####
  90. # Edit with care
  91. ## Work Directories
  92. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  93. selfname=$(basename $(readlink -f "${BASH_SOURCE[0]}"))
  94. lockselfname=".${servicename}.lock"
  95. lgsmdir="${rootdir}/lgsm"
  96. functionsdir="${lgsmdir}/functions"
  97. libdir="${lgsmdir}/lib"
  98. tmpdir="${lgsmdir}/tmp"
  99. filesdir="${rootdir}/serverfiles"
  100. ## Server Specific Directories
  101. systemdir="${filesdir}"
  102. executabledir="${filesdir}"
  103. executable="LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`dirname $0`/RustDedicated_Data/Plugins/x86_64 ./RustDedicated"
  104. serveridentitydir="${systemdir}/server/${servicename}"
  105. servercfg="server.cfg"
  106. servercfgdefault="server.cfg"
  107. servercfgdir="${serveridentitydir}/cfg"
  108. servercfgfullpath="${servercfgdir}/${servercfg}"
  109. ## Backup Directory
  110. backupdir="${rootdir}/backups"
  111. ## Logging Directories
  112. gamelogdir="${rootdir}/log/server"
  113. scriptlogdir="${rootdir}/log/script"
  114. consolelogdir="${rootdir}/log/console"
  115. gamelog="${gamelogdir}/${servicename}-game.log"
  116. scriptlog="${scriptlogdir}/${servicename}-script.log"
  117. consolelog="${consolelogdir}/${servicename}-console.log"
  118. emaillog="${scriptlogdir}/${servicename}-email.log"
  119. ## Logs Naming
  120. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  121. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
  122. gamelogfile="\"gamelog-$(date '+%Y-%m-%d-%H-%M-%S').log\""
  123. ########################
  124. ######## Script ########
  125. ###### Do not edit #####
  126. ########################
  127. # Fetches core_dl for file downloads
  128. fn_fetch_core_dl(){
  129. github_file_url_dir="lgsm/functions"
  130. github_file_url_name="${functionfile}"
  131. filedir="${functionsdir}"
  132. filename="${github_file_url_name}"
  133. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  134. # If the file is missing, then download
  135. if [ ! -f "${filedir}/${filename}" ]; then
  136. if [ ! -d "${filedir}" ]; then
  137. mkdir -p "${filedir}"
  138. fi
  139. echo -e " fetching ${filename}...\c"
  140. # Check curl exists and use available path
  141. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  142. for curlcmd in ${curlpaths}
  143. do
  144. if [ -x "${curlcmd}" ]; then
  145. break
  146. fi
  147. done
  148. # If curl exists download file
  149. if [ "$(basename ${curlcmd})" == "curl" ]; then
  150. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  151. if [ $? -ne 0 ]; then
  152. echo -e "\e[0;31mFAIL\e[0m\n"
  153. echo "${curlfetch}"
  154. echo -e "${githuburl}\n"
  155. exit 1
  156. else
  157. echo -e "\e[0;32mOK\e[0m"
  158. fi
  159. else
  160. echo -e "\e[0;31mFAIL\e[0m\n"
  161. echo "Curl is not installed!"
  162. echo -e ""
  163. exit 1
  164. fi
  165. chmod +x "${filedir}/${filename}"
  166. fi
  167. source "${filedir}/${filename}"
  168. }
  169. core_dl.sh(){
  170. # Functions are defined in core_functions.sh.
  171. functionfile="${FUNCNAME}"
  172. fn_fetch_core_dl
  173. }
  174. core_functions.sh(){
  175. # Functions are defined in core_functions.sh.
  176. functionfile="${FUNCNAME}"
  177. fn_fetch_core_dl
  178. }
  179. # Prevent from running this script as root.
  180. if [ "$(whoami)" = "root" ]; then
  181. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  182. echo "[ FAIL ] Do NOT run this script as root!"
  183. exit 1
  184. else
  185. core_functions.sh
  186. check_root.sh
  187. fi
  188. fi
  189. core_dl.sh
  190. core_functions.sh
  191. getopt=$1
  192. core_getopt.sh