check_permissions.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "Permissions issues found"
  13. fn_script_log_fatal "Permissions 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. } | column -s $'\t' -t | tee -a "${scriptlog}"
  20. core_exit.sh
  21. fi
  22. fi
  23. }
  24. fn_check_permissions(){
  25. if [ -d "${functionsdir}" ]; then
  26. if [ $(find "${functionsdir}" -type f -not -executable|wc -l) -ne "0" ]; then
  27. fn_print_fail_nl "Permissions issues found"
  28. fn_script_log_fatal "Permissions issues found"
  29. fn_print_infomation_nl "The following files are not executable:"
  30. fn_script_log_info "The following files are not executable:"
  31. {
  32. echo -e "File\n"
  33. find "${functionsdir}" -type f -not -executable -printf "%p\n"
  34. } | column -s $'\t' -t | tee -a "${scriptlog}"
  35. core_exit.sh
  36. fi
  37. fi
  38. # Check rootdir permissions
  39. if [ -n "${rootdir}" ]; then
  40. # Get permission numbers on folder under the form 775
  41. rootdirperm="$(stat -c %a "${rootdir}")"
  42. # Grab the first and second digit for user and group permission
  43. userrootdirperm="${rootdirperm:0:1}"
  44. grouprootdirperm="${rootdirperm:1:1}"
  45. if [ "${userrootdirperm}" != "7" ] && [ "${grouprootdirperm}" != "7" ]; then
  46. fn_print_fail_nl "Permissions issues found"
  47. fn_script_log_fatal "Permissions issues found"
  48. fn_print_infomation_nl "The following directorys does not have the correct permissions:"
  49. fn_script_log_info "The following directorys does not have the correct permissions:"
  50. ls -l "${rootdir}"
  51. core_exit.sh
  52. fi
  53. fi
  54. }
  55. fn_check_ownership
  56. fn_check_permissions