rustserver 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/bin/bash
  2. # Rust
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Contributor: UltimateByte (LGSM adaptation), Wulf (Information)
  6. # Website: https://gameservermanagers.com
  7. if [ -f ".dev-debug" ]; then
  8. exec 5>dev-debug.log
  9. BASH_XTRACEFD="5"
  10. set -x
  11. fi
  12. version="160916"
  13. #### Variables ####
  14. # Notification Alerts
  15. # (on|off)
  16. # Email
  17. emailalert="off"
  18. email="email@example.com"
  19. #emailfrom="email@example.com"
  20. # Pushbullet
  21. # https://www.pushbullet.com/#settings
  22. pushbulletalert="off"
  23. pushbullettoken="accesstoken"
  24. # Steam login (not required)
  25. steamuser="anonymous"
  26. steampass=""
  27. # Server settings
  28. # More settings available after install in serverfiles/server/rust-server/server.cfg
  29. servername="Rust"
  30. ip="0.0.0.0"
  31. updateonstart="off"
  32. port="28015"
  33. rconport="28016"
  34. rconpassword="CHANGE_ME"
  35. maxplayers="50"
  36. # Advanced
  37. seed="" # default random; range : 1 to 2147483647 ; used to change or reproduce a procedural map
  38. worldsize="3000" # default 3000; range : 1000 to 6000 ; map size in meters
  39. saveinterval="300" # Auto-save in seconds
  40. tickrate="30" # default 30; range : 15 to 100
  41. # https://developer.valvesoftware.com/wiki/Rust_Dedicated_Server
  42. fn_parms(){
  43. 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}"
  44. }
  45. # Specific to Rust
  46. if [ -n "${seed}" ]; then
  47. # If set, then add to start parms
  48. conditionalseed="+server.seed ${seed}"
  49. else
  50. # Keep randomness of the number if not set
  51. conditionalseed=""
  52. fi
  53. #### Advanced Variables ####
  54. # Github Branch Select
  55. # Allows for the use of different function files
  56. # from a different repo and/or branch.
  57. githubuser="GameServerManagers"
  58. githubrepo="LinuxGSM"
  59. githubbranch="master"
  60. # Steam
  61. appid="258550"
  62. # Steam App Branch Select
  63. # Allows to opt into the various Steam app branches. Default branch is "".
  64. # Example: "-beta prerelease"
  65. branch=""
  66. # Server Details
  67. servicename="rust-server"
  68. gamename="Rust"
  69. engine="unity3d"
  70. # Directories
  71. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  72. selfname=$(basename $(readlink -f "${BASH_SOURCE[0]}"))
  73. lockselfname=".${servicename}.lock"
  74. lgsmdir="${rootdir}/lgsm"
  75. functionsdir="${lgsmdir}/functions"
  76. libdir="${lgsmdir}/lib"
  77. tmpdir="${lgsmdir}/tmp"
  78. filesdir="${rootdir}/serverfiles"
  79. systemdir="${filesdir}"
  80. executabledir="${filesdir}"
  81. executable="./RustDedicated"
  82. serveridentitydir="${systemdir}/server/${servicename}"
  83. servercfg="server.cfg"
  84. servercfgdefault="server.cfg"
  85. servercfgdir="${serveridentitydir}/cfg"
  86. servercfgfullpath="${servercfgdir}/${servercfg}"
  87. # Backup
  88. maxbackups="4"
  89. maxbackupdays="30"
  90. stoponbackup="on"
  91. backupdir="${rootdir}/backups"
  92. # Logging
  93. logdays="7"
  94. gamelogdir="${rootdir}/log/server"
  95. scriptlogdir="${rootdir}/log/script"
  96. consolelogdir="${rootdir}/log/console"
  97. consolelogging="on"
  98. gamelog="${gamelogdir}/${servicename}-game.log"
  99. scriptlog="${scriptlogdir}/${servicename}-script.log"
  100. consolelog="${consolelogdir}/${servicename}-console.log"
  101. emaillog="${scriptlogdir}/${servicename}-email.log"
  102. gamelogfile="\"gamelog-$(date '+%Y-%m-%d-%H-%M-%S').log\""
  103. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  104. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  105. ##### Script #####
  106. # Do not edit
  107. # Fetches core_dl for file downloads
  108. fn_fetch_core_dl(){
  109. github_file_url_dir="lgsm/functions"
  110. github_file_url_name="${functionfile}"
  111. filedir="${functionsdir}"
  112. filename="${github_file_url_name}"
  113. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  114. # If the file is missing, then download
  115. if [ ! -f "${filedir}/${filename}" ]; then
  116. if [ ! -d "${filedir}" ]; then
  117. mkdir -p "${filedir}"
  118. fi
  119. echo -e " fetching ${filename}...\c"
  120. # Check curl exists and use available path
  121. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  122. for curlcmd in ${curlpaths}
  123. do
  124. if [ -x "${curlcmd}" ]; then
  125. break
  126. fi
  127. done
  128. # If curl exists download file
  129. if [ "$(basename ${curlcmd})" == "curl" ]; then
  130. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  131. if [ $? -ne 0 ]; then
  132. echo -e "\e[0;31mFAIL\e[0m\n"
  133. echo "${curlfetch}"
  134. echo -e "${githuburl}\n"
  135. exit 1
  136. else
  137. echo -e "\e[0;32mOK\e[0m"
  138. fi
  139. else
  140. echo -e "\e[0;31mFAIL\e[0m\n"
  141. echo "Curl is not installed!"
  142. echo -e ""
  143. exit 1
  144. fi
  145. chmod +x "${filedir}/${filename}"
  146. fi
  147. source "${filedir}/${filename}"
  148. }
  149. core_dl.sh(){
  150. # Functions are defined in core_functions.sh.
  151. functionfile="${FUNCNAME}"
  152. fn_fetch_core_dl
  153. }
  154. core_functions.sh(){
  155. # Functions are defined in core_functions.sh.
  156. functionfile="${FUNCNAME}"
  157. fn_fetch_core_dl
  158. }
  159. core_dl.sh
  160. core_functions.sh
  161. getopt=$1
  162. core_getopt.sh