ns2server 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. # Natural Selection 2
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: http://gameservermanagers.com
  6. version="121215"
  7. #### Variables ####
  8. # Notification Email
  9. # (on|off)
  10. emailnotification="off"
  11. email="email@example.com"
  12. # Steam login
  13. steamuser="username"
  14. steampass="password"
  15. # Start Variables
  16. defaultmap="ns2_summit"
  17. port="27015"
  18. maxplayers="24"
  19. ip="0.0.0.0"
  20. updateonstart="off"
  21. servername="NS2 Server"
  22. webadminuser="admin"
  23. webadminpass="admin"
  24. webadminport="8080"
  25. configpath="server1"
  26. modstorage="server1/Workshop"
  27. mods=""
  28. password=""
  29. # Add the following line to the parms if you want a private server. Ensuring
  30. # that the password variable above is not left empty.
  31. # -password \"${password}\"
  32. # http://wiki.unknownworlds.com/ns2/Dedicated_Server
  33. fn_parms(){
  34. parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${ip} -webuser ${webadminuser} -webpassword \"${webadminpass}\" -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -config_path \"${rootdir}/${configpath}\" -modstorage \"${rootdir}/${modstorage}\" -mods \"${mods}\""
  35. }
  36. #### Advanced Variables ####
  37. # Github Branch Select
  38. # Allows for the use of different function files
  39. # from a different repo and/or branch.
  40. githubuser="dgibbs64"
  41. githubrepo="linuxgsm"
  42. githubbranch="master"
  43. # Steam
  44. appid="4940"
  45. # Server Details
  46. servicename="ns2-server"
  47. gamename="Natural Selection 2"
  48. engine="spark"
  49. # Directories
  50. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  51. selfname=$(basename $(readlink -f "${BASH_SOURCE[0]}"))
  52. lockselfname=".${servicename}.lock"
  53. filesdir="${rootdir}/serverfiles"
  54. systemdir="${filesdir}"
  55. executabledir="${filesdir}"
  56. executable="./server_linux32"
  57. backupdir="${rootdir}/backups"
  58. # Logging
  59. logdays="7"
  60. gamelogdir="${systemdir}/logs"
  61. scriptlogdir="${rootdir}/log/script"
  62. consolelogdir="${rootdir}/log/console"
  63. scriptlog="${scriptlogdir}/${servicename}-script.log"
  64. consolelog="${consolelogdir}/${servicename}-console.log"
  65. emaillog="${scriptlogdir}/${servicename}-email.log"
  66. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  67. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  68. ##### Script #####
  69. # Do not edit
  70. fn_getgithubfile(){
  71. filename=$1
  72. exec=$2
  73. fileurl=${3:-$filename}
  74. filepath="${rootdir}/${filename}"
  75. filedir=$(dirname "${filepath}")
  76. # If the function file is missing, then download
  77. if [ ! -f "${filepath}" ]; then
  78. if [ ! -d "${filedir}" ]; then
  79. mkdir "${filedir}"
  80. fi
  81. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
  82. echo -e " fetching ${filename}...\c"
  83. if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then
  84. :
  85. else
  86. echo -e "\e[0;31mFAIL\e[0m\n"
  87. echo "Curl is not installed!"
  88. echo -e ""
  89. exit
  90. fi
  91. curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1)
  92. if [ $? -ne 0 ]; then
  93. echo -e "\e[0;31mFAIL\e[0m\n"
  94. echo " ${curl}"|grep "curl:"
  95. echo -e "${githuburl}\n"
  96. exit
  97. else
  98. echo -e "\e[0;32mOK\e[0m"
  99. fi
  100. if [ "${exec}" ]; then
  101. chmod +x "${filepath}"
  102. fi
  103. fi
  104. if [ "${exec}" ]; then
  105. source "${filepath}"
  106. fi
  107. }
  108. fn_runfunction(){
  109. fn_getgithubfile "functions/${functionfile}" 1
  110. }
  111. fn_functions(){
  112. # Functions are defined in fn_functions.
  113. functionfile="${FUNCNAME}"
  114. fn_runfunction
  115. }
  116. fn_functions
  117. getopt=$1
  118. fn_getopt