pzserver 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2016 Daniel Gibbs
  5. # Purpose: Project Zomboid | 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. adminpassword="CHANGE_ME"
  22. ip="0.0.0.0"
  23. fn_parms(){
  24. parms="-ip ${ip} -adminpassword \"${adminpassword}\" -servername ${servicename}"
  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. ## Updating | https://github.com/GameServerManagers/LinuxGSM/wiki/Update
  38. updateonstart="off"
  39. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  40. maxbackups="4"
  41. maxbackupdays="30"
  42. stoponbackup="on"
  43. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  44. consolelogging="on"
  45. logdays="7"
  46. #### LinuxGSM Advanced Settings ####
  47. ## SteamCMD Settings
  48. # Server appid
  49. appid="380870"
  50. # Steam App Branch Select
  51. # Allows to opt into the various Steam app branches. Default branch is "".
  52. # Example: "-beta latest_experimental"
  53. branch=""
  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. ## LinuxGSM Server Details
  61. # Do not edit
  62. gamename="Project Zomboid"
  63. engine="projectzomboid"
  64. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  65. servicename="pz-server"
  66. #### Directories ####
  67. # Edit with care
  68. ## Work Directories
  69. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  70. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  71. lockselfname=".${servicename}.lock"
  72. lgsmdir="${rootdir}/lgsm"
  73. functionsdir="${lgsmdir}/functions"
  74. libdir="${lgsmdir}/lib"
  75. tmpdir="${lgsmdir}/tmp"
  76. filesdir="${rootdir}/serverfiles"
  77. ## Server Specific Directories
  78. systemdir="${filesdir}"
  79. executabledir="${filesdir}"
  80. executable="./start-server.sh"
  81. servercfg="${servicename}.ini"
  82. servercfgdefault="server.ini"
  83. servercfgdir="${HOME}/Zomboid/Server"
  84. servercfgfullpath="${servercfgdir}/${servercfg}"
  85. ## Backup Directory
  86. backupdir="${rootdir}/backups"
  87. ## Logging Directories
  88. gamelogdir="${HOME}/Zomboid/Logs"
  89. scriptlogdir="${rootdir}/log/script"
  90. consolelogdir="${rootdir}/log/console"
  91. scriptlog="${scriptlogdir}/${servicename}-script.log"
  92. consolelog="${consolelogdir}/${servicename}-console.log"
  93. emaillog="${scriptlogdir}/${servicename}-email.log"
  94. ## Logs Naming
  95. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  96. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
  97. ########################
  98. ######## Script ########
  99. ###### Do not edit #####
  100. ########################
  101. # Fetches core_dl for file downloads
  102. fn_fetch_core_dl(){
  103. github_file_url_dir="lgsm/functions"
  104. github_file_url_name="${functionfile}"
  105. filedir="${functionsdir}"
  106. filename="${github_file_url_name}"
  107. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  108. # If the file is missing, then download
  109. if [ ! -f "${filedir}/${filename}" ]; then
  110. if [ ! -d "${filedir}" ]; then
  111. mkdir -p "${filedir}"
  112. fi
  113. echo -e " fetching ${filename}...\c"
  114. # Check curl exists and use available path
  115. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  116. for curlcmd in ${curlpaths}
  117. do
  118. if [ -x "${curlcmd}" ]; then
  119. break
  120. fi
  121. done
  122. # If curl exists download file
  123. if [ "$(basename ${curlcmd})" == "curl" ]; then
  124. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  125. if [ $? -ne 0 ]; then
  126. echo -e "\e[0;31mFAIL\e[0m\n"
  127. echo "${curlfetch}"
  128. echo -e "${githuburl}\n"
  129. exit 1
  130. else
  131. echo -e "\e[0;32mOK\e[0m"
  132. fi
  133. else
  134. echo -e "\e[0;31mFAIL\e[0m\n"
  135. echo "Curl is not installed!"
  136. echo -e ""
  137. exit 1
  138. fi
  139. chmod +x "${filedir}/${filename}"
  140. fi
  141. source "${filedir}/${filename}"
  142. }
  143. core_dl.sh(){
  144. # Functions are defined in core_functions.sh.
  145. functionfile="${FUNCNAME}"
  146. fn_fetch_core_dl
  147. }
  148. core_functions.sh(){
  149. # Functions are defined in core_functions.sh.
  150. functionfile="${FUNCNAME}"
  151. fn_fetch_core_dl
  152. }
  153. # Prevent from running this script as root.
  154. if [ "$(whoami)" = "root" ]; then
  155. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  156. echo "[ FAIL ] Do NOT run this script as root!"
  157. exit 1
  158. else
  159. core_functions.sh
  160. check_root.sh
  161. fi
  162. fi
  163. core_dl.sh
  164. core_functions.sh
  165. getopt=$1
  166. core_getopt.sh