fctrserver 5.2 KB

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