check_permissions.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 [ -d "${filesdir}" ]; then
  11. if [ $(find "${filesdir}" -not -user $(whoami)|wc -l) -ne "0" ]||[ $(find "${rootdir}/${selfname}" -not -user $(whoami)|wc -l) -ne "0" ]; then
  12. fn_print_fail_nl "Ownership issues found"
  13. fn_script_log_fatal "Ownership issues found"
  14. fn_print_infomation_nl "The current user ($(whoami)) does not have ownership of the following files:"
  15. fn_script_log_info "The current user ($(whoami)) does not have ownership of the following files:"
  16. {
  17. echo -e "User\tGroup\tFile\n"
  18. find "${filesdir}" -not -user $(whoami) -printf "%u\t\t%g\t%p\n"
  19. find "${rootdir}/${selfname}" -not -user $(whoami) -printf "%u\t\t%g\t%p\n"
  20. } | column -s $'\t' -t | tee -a "${scriptlog}"
  21. core_exit.sh
  22. fn_print_infomation_nl "For more information, please see https://github.com/GameServerManagers/LinuxGSM/wiki/FAQ#-fail--starting-game-server-permissions-issues-found"
  23. fn_script_log "For more information, please see https://github.com/GameServerManagers/LinuxGSM/wiki/FAQ#-fail--starting-game-server-permissions-issues-found"
  24. fi
  25. fi
  26. }
  27. fn_check_permissions(){
  28. if [ -d "${functionsdir}" ]; then
  29. if [ $(find "${functionsdir}" -type f -not -executable|wc -l) -ne "0" ]; then
  30. fn_print_fail_nl "Permissions issues found"
  31. fn_script_log_fatal "Permissions issues found"
  32. fn_print_infomation_nl "The following files are not executable:"
  33. fn_script_log_info "The following files are not executable:"
  34. {
  35. echo -e "File\n"
  36. find "${functionsdir}" -type f -not -executable -printf "%p\n"
  37. } | column -s $'\t' -t | tee -a "${scriptlog}"
  38. core_exit.sh
  39. fi
  40. fi
  41. # Check rootdir permissions
  42. if [ -n "${rootdir}" ]; then
  43. # Get permission numbers on folder under the form 775
  44. rootdirperm="$(stat -c %a "${rootdir}")"
  45. # Grab the first and second digit for user and group permission
  46. userrootdirperm="${rootdirperm:0:1}"
  47. grouprootdirperm="${rootdirperm:1:1}"
  48. if [ "${userrootdirperm}" != "7" ] && [ "${grouprootdirperm}" != "7" ]; then
  49. fn_print_fail_nl "Permissions issues found"
  50. fn_script_log_fatal "Permissions issues found"
  51. fn_print_infomation_nl "The following directorys does not have the correct permissions:"
  52. fn_script_log_info "The following directorys does not have the correct permissions:"
  53. ls -l "${rootdir}"
  54. core_exit.sh
  55. fi
  56. fi
  57. }
  58. fn_check_ownership
  59. fn_check_permissions