ns2server 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. # Natural Selection 2
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: http://danielgibbs.co.uk
  6. # Version: 010115
  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. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  17. defaultmap="ns2_summit"
  18. port="27015"
  19. maxplayers="24"
  20. ip="0.0.0.0"
  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. fn_parms(){
  33. 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}\""
  34. }
  35. #### Advanced Variables ####
  36. # Steam
  37. appid="4940"
  38. # Server Details
  39. servicename="ns2-server"
  40. gamename="Natural Selection 2"
  41. engine="spark"
  42. # Directories
  43. selfname="$0"
  44. lockselfname=$(echo ".${servicename}.lock")
  45. filesdir="${rootdir}/serverfiles"
  46. systemdir="${filesdir}"
  47. executabledir="${filesdir}"
  48. executable="./server_linux32"
  49. backupdir="backups"
  50. # Logging
  51. logdays="7"
  52. gamelogdir="${systemdir}/logs"
  53. scriptlogdir="${rootdir}/log/script"
  54. consolelogdir="${rootdir}/log/console"
  55. scriptlog="${scriptlogdir}/${servicename}-script.log"
  56. consolelog="${consolelogdir}/${servicename}-console.log"
  57. emaillog="${scriptlogdir}/${servicename}-email.log"
  58. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  59. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  60. ##### Script #####
  61. # Do not edit
  62. fn_install(){
  63. fn_rootcheck
  64. fn_header
  65. if [ -z "${autoinstall}" ]; then
  66. fn_serverdirectory
  67. fn_header
  68. fi
  69. fn_steamdl
  70. fn_steaminstall
  71. fn_steamfix
  72. fn_glibcfix
  73. fn_loginstall
  74. fn_getquery
  75. fn_header
  76. fn_details
  77. fn_installcomplete
  78. }
  79. fn_functions(){
  80. # Functions are defines in fn_functions.
  81. functionfile="${FUNCNAME}"
  82. fn_runfunction
  83. }
  84. fn_runfunction(){
  85. # Functions are downloaded and run with this function
  86. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  87. cd "${rootdir}"
  88. if [ ! -d "functions" ]; then
  89. mkdir functions
  90. fi
  91. cd functions
  92. echo -e "loading ${functionfile}...\c"
  93. wget -N --no-check-certificate /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
  94. chmod +x "${functionfile}"
  95. cd "${rootdir}"
  96. sleep 1
  97. fi
  98. source "${rootdir}/functions/${functionfile}"
  99. }
  100. fn_functions
  101. case "$1" in
  102. start)
  103. fn_startserver;;
  104. stop)
  105. fn_stopserver;;
  106. restart)
  107. fn_restartserver;;
  108. update)
  109. norestart=1;
  110. fn_versioncheck;;
  111. update-restart)
  112. fn_versioncheck;;
  113. validate)
  114. fn_validateserver;;
  115. validate-restart)
  116. fn_stopserver
  117. fn_validateserver
  118. fn_startserver;;
  119. monitor)
  120. fn_monitorserver;;
  121. email-test)
  122. fn_emailtest;;
  123. details)
  124. fn_details;;
  125. backup)
  126. fn_backupserver;;
  127. console)
  128. fn_console;;
  129. debug)
  130. fn_debugserver;;
  131. install)
  132. fn_install;;
  133. auto-install)
  134. fn_autoinstall;;
  135. *)
  136. echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install}"
  137. exit 1;;
  138. esac
  139. exit