check_permissions.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # LGSM check_permissions.sh
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Checks ownership & permissions of scripts, files and folders.
  7. local commandname="CHECK"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_check_ownership(){
  10. if [ -f "${rootdir}/${selfname}" ]; then
  11. if [ $(find "${rootdir}/${selfname}" -not -user $(whoami)|wc -l) -ne "0" ]; then
  12. selfownissue=1
  13. fi
  14. fi
  15. if [ -d "${functionsdir}" ]; then
  16. if [ $(find "${functionsdir}" -not -user $(whoami)|wc -l) -ne "0" ]; then
  17. funcownissue=1
  18. fi
  19. fi
  20. if [ -d "${filesdir}" ]; then
  21. if [ $(find "${filesdir}" -not -user $(whoami)|wc -l) -ne "0" ]; then
  22. filesownissue=1
  23. fi
  24. fi
  25. if [ "${selfownissue}" == "1" ]||[ "${funcownissue}" == "1" ]||[ "${filesownissue}" == "1" ]; then
  26. fn_print_fail_nl "Ownership issues found"
  27. fn_script_log_fatal "Ownership issues found"
  28. fn_print_information_nl "The current user ($(whoami)) does not have ownership of the following files:"
  29. fn_script_log_info "The current user ($(whoami)) does not have ownership of the following files:"
  30. {
  31. echo -e "User\tGroup\tFile\n"
  32. if [ "${selfownissue}" == "1" ]; then
  33. find "${rootdir}/${selfname}" -not -user $(whoami) -printf "%u\t\t%g\t%p\n"
  34. fi
  35. if [ "${funcownissue}" == "1" ]; then
  36. find "${functionsdir}" -not -user $(whoami) -printf "%u\t\t%g\t%p\n"
  37. fi
  38. if [ "${funcownissue}" == "1" ]; then
  39. find "${filesdir}" -not -user $(whoami) -printf "%u\t\t%g\t%p\n"
  40. fi
  41. } | column -s $'\t' -t | tee -a "${scriptlog}"
  42. echo ""
  43. fn_print_information_nl "For more information, please see https://github.com/GameServerManagers/LinuxGSM/wiki/FAQ#-fail--starting-game-server-permissions-issues-found"
  44. fn_script_log "For more information, please see https://github.com/GameServerManagers/LinuxGSM/wiki/FAQ#-fail--starting-game-server-permissions-issues-found"
  45. core_exit.sh
  46. fi
  47. }
  48. fn_check_permissions(){
  49. if [ -d "${functionsdir}" ]; then
  50. if [ $(find "${functionsdir}" -type f -not -executable|wc -l) -ne "0" ]; then
  51. fn_print_fail_nl "Permissions issues found"
  52. fn_script_log_fatal "Permissions issues found"
  53. fn_print_information_nl "The following files are not executable:"
  54. fn_script_log_info "The following files are not executable:"
  55. {
  56. echo -e "File\n"
  57. find "${functionsdir}" -type f -not -executable -printf "%p\n"
  58. } | column -s $'\t' -t | tee -a "${scriptlog}"
  59. core_exit.sh
  60. fi
  61. fi
  62. # Check rootdir permissions
  63. if [ -n "${rootdir}" ]; then
  64. # Get permission numbers on folder under the form 775
  65. rootdirperm="$(stat -c %a "${rootdir}")"
  66. # Grab the first and second digit for user and group permission
  67. userrootdirperm="${rootdirperm:0:1}"
  68. grouprootdirperm="${rootdirperm:1:1}"
  69. if [ "${userrootdirperm}" != "7" ] && [ "${grouprootdirperm}" != "7" ]; then
  70. fn_print_fail_nl "Permissions issues found"
  71. fn_script_log_fatal "Permissions issues found"
  72. fn_print_information_nl "The following directorys does not have the correct permissions:"
  73. fn_script_log_info "The following directorys does not have the correct permissions:"
  74. ls -l "${rootdir}"
  75. core_exit.sh
  76. fi
  77. fi
  78. }
  79. fn_check_ownership
  80. fn_check_permissions