4
0

lgsminstall 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2017 Daniel Gibbs
  5. # Purpose: Counter-Strike: Global Offensive | 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="170305"
  16. sname="core"
  17. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  18. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  19. servicename="${selfname}"
  20. ## Github Branch Select
  21. # Allows for the use of different function files
  22. # from a different repo and/or branch.
  23. githubuser="GameServerManagers"
  24. githubrepo="LinuxGSM"
  25. githubbranch="config"
  26. source lgsm/config/_default.cfg
  27. source lgsm/config/common.cfg
  28. source lgsm/config/${servicename.cfg
  29. # LinuxGSM installer
  30. if [ "${sname}" == "core" ]; then
  31. userinput=$1
  32. if [ -z "${userinput}" ]; then
  33. userinput="empty"
  34. fi
  35. serverslist=$(grep "${userinput}" lgsm/data/serverlist.csv|awk -F "," '{print $2}')
  36. echo "USERINPUT: $userinput"
  37. echo "SERVERLIST: $serverslist"
  38. if [ "${userinput}" == "${serverslist}" ]; then
  39. echo "installing"
  40. sname=$(grep $userinput lgsm/data/serverlist.csv|awk -F "," '{print $1}')
  41. servername=$(grep $userinput lgsm/data/serverlist.csv|awk -F "," '{print $2}')
  42. if [ -e "${servername}" ]; then
  43. i=2
  44. while [ -e "$servername-$i" ] ; do
  45. let i++
  46. done
  47. servername="${servername}-$i"
  48. fi
  49. cp "${selfname}" "${servername}"
  50. sed -i -e "s/sname=\"core\"/sname=\"${sname}\"/g" "${servername}"
  51. exit
  52. elif [ "$userinput" == "list" ]; then
  53. {
  54. awk -F "," '{print $2 "\t" $3}' "lgsm/data/serverlist.csv"
  55. } | column -s $'\t' -t
  56. exit
  57. else
  58. echo "Usage: ./${selfname} list"
  59. echo "For a complete list of available servers"
  60. echo ""
  61. echo "Usage: ./${selfname} [servername]"
  62. echo "To install a server"
  63. exit
  64. fi
  65. fi
  66. ########################
  67. ######## Script ########
  68. ###### Do not edit #####
  69. ########################
  70. # Fetches core_dl for file downloads
  71. fn_fetch_core_dl(){
  72. github_file_url_dir="lgsm/functions"
  73. github_file_url_name="${functionfile}"
  74. filedir="${functionsdir}"
  75. filename="${github_file_url_name}"
  76. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  77. # If the file is missing, then download
  78. if [ ! -f "${filedir}/${filename}" ]; then
  79. if [ ! -d "${filedir}" ]; then
  80. mkdir -p "${filedir}"
  81. fi
  82. echo -e " fetching ${filename}...\c"
  83. # Check curl exists and use available path
  84. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  85. for curlcmd in ${curlpaths}
  86. do
  87. if [ -x "${curlcmd}" ]; then
  88. break
  89. fi
  90. done
  91. # If curl exists download file
  92. if [ "$(basename ${curlcmd})" == "curl" ]; then
  93. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  94. if [ $? -ne 0 ]; then
  95. echo -e "\e[0;31mFAIL\e[0m\n"
  96. echo "${curlfetch}"
  97. echo -e "${githuburl}\n"
  98. exit 1
  99. else
  100. echo -e "\e[0;32mOK\e[0m"
  101. fi
  102. else
  103. echo -e "\e[0;31mFAIL\e[0m\n"
  104. echo "Curl is not installed!"
  105. echo -e ""
  106. exit 1
  107. fi
  108. chmod +x "${filedir}/${filename}"
  109. fi
  110. source "${filedir}/${filename}"
  111. }
  112. core_dl.sh(){
  113. # Functions are defined in core_functions.sh.
  114. functionfile="${FUNCNAME}"
  115. fn_fetch_core_dl
  116. }
  117. core_functions.sh(){
  118. # Functions are defined in core_functions.sh.
  119. functionfile="${FUNCNAME}"
  120. fn_fetch_core_dl
  121. }
  122. # Prevent from running this script as root.
  123. if [ "$(whoami)" = "root" ]; then
  124. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  125. echo "[ FAIL ] Do NOT run this script as root!"
  126. exit 1
  127. else
  128. core_functions.sh
  129. check_root.sh
  130. fi
  131. fi
  132. core_dl.sh
  133. core_functions.sh
  134. getopt=$1
  135. core_getopt.sh