check_deps.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. else
  41. fn_printfail "Unknown executable"
  42. exit
  43. fi
  44. # Loop though required depenencies
  45. for deptocheck in "${array_deps_required[@]}"
  46. do
  47. fn_deps_detector
  48. done
  49. if [ "${#array_deps_missing[@]}" != "0" ]; then
  50. fn_printwarnnl "Dependency Missing: \e[0;31m${array_deps_missing[@]}\e[0m"
  51. sleep 2
  52. sudo -n true
  53. if [ $? -eq 0 ]; then
  54. fn_printinfonl "Attempting to install missing dependencies automatically"
  55. echo -en ".\r"
  56. sleep 1
  57. echo -en "..\r"
  58. sleep 1
  59. echo -en "...\r"
  60. sleep 1
  61. echo -en " \r"
  62. sudo apt-get install ${array_deps_missing[@]}
  63. else
  64. echo "sudo apt-get install ${array_deps_missing[@]}"
  65. fi
  66. else
  67. fn_printoknl "Checking for missing dependencies"
  68. fi