fctrserver 5.2 KB

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