check_deps.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # LGSM check_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="170116"
  6. # Description: Checks that the require dependencies are installed for LGSM
  7. fn_deps_detector(){
  8. # Checks is dependency is missing
  9. if [ -n "$(command -v dpkg-query)" ]; then
  10. dpkg-query -W -f='${Status}' ${deptocheck} | grep -q -P '^install ok installed$'
  11. depstatus=$?
  12. if [ "${depstatus}" == "0" ]; then
  13. missingdep=0
  14. echo -en " \e[0;32m${deptocheck}\e[0m"
  15. else
  16. # if missing dependency is flagged
  17. missingdep=1
  18. echo -en " \e[0;31m${deptocheck}\e[0m"
  19. fi
  20. sleep 0.5
  21. fi
  22. # Add missing dependencies are added to array_deps_missing array
  23. if [ "${missingdep}" == "1" ]; then
  24. array_deps_missing+=("${deptocheck}")
  25. fi
  26. }
  27. fn_deps_email(){
  28. # Adds postfix to required dependencies if email notification is enabled
  29. if [ "${emailnotification}" == "on" ]; then
  30. array_deps_required+=("mailutils postfix")
  31. fi
  32. }
  33. cd "${executabledir}"
  34. # Generate array of missing deps
  35. array_deps_missing=()
  36. fn_printdots "Checking for missing dependencies:"
  37. if [ "${executable}" == "./srcds_run" ]||[ "${executable}" == "./dabds.sh" ]||[ "${executable}" == "./srcds_run.sh" ]||[ "${executable}" == "./Jcmp-Server" ] ; then
  38. local array_deps_required=( tmux curl lib32gcc1 libstdc++6:i386 )
  39. fn_deps_email
  40. elif
  41. else
  42. fn_printfail "Unknown executable"
  43. exit
  44. fi
  45. # Loop though required depenencies
  46. for deptocheck in "${array_deps_required[@]}"
  47. do
  48. fn_deps_detector
  49. done
  50. if [ "${#array_deps_missing[@]}" != "0" ]; then
  51. fn_printwarnnl "Dependency Missing: \e[0;31m${array_deps_missing[@]}\e[0m"
  52. sleep 2
  53. sudo -n true
  54. if [ $? -eq 0 ]; then
  55. fn_printinfonl "Attempting to install missing dependencies automatically"
  56. echo -en ".\r"
  57. sleep 1
  58. echo -en "..\r"
  59. sleep 1
  60. echo -en "...\r"
  61. sleep 1
  62. echo -en " \r"
  63. sudo apt-get install ${array_deps_missing[@]}
  64. else
  65. echo "sudo apt-get install ${array_deps_missing[@]}"
  66. fi
  67. else
  68. fn_printoknl "Checking for missing dependencies"
  69. fi