check_permissions.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # LGSM check_permissions.sh
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Checks script, files and folders ownership and permissions.
  7. local commandname="CHECK"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_check_ownership(){
  10. if [ $(find "${filesdir}" -not -user $(whoami)|wc -l) -ne "0" ]||[ $(find "${rootdir}/${selfname}" -not -user $(whoami)|wc -l) -ne "0" ]; then
  11. fn_print_fail_nl "Permissions issues found"
  12. fn_script_log_fatal "Permissions issues found"
  13. fn_print_infomation_nl "The current user ($(whoami)) does not have ownership of the following files:"
  14. fn_script_log_info "The current user ($(whoami)) does not have ownership of the following files:"
  15. {
  16. echo -e "User\tGroup\tFile\n"
  17. find "${filesdir}" -not -user $(whoami) -printf "%u\t\t%g\t%p\n"
  18. } | column -s $'\t' -t | tee -a "${scriptlog}"
  19. core_exit.sh
  20. fi
  21. }
  22. fn_check_permissions(){
  23. if [ -n "${functionsdir}" ]; then
  24. if [ $(find "${functionsdir}" -type f -not -executable|wc -l) -ne "0" ]; then
  25. fn_print_fail_nl "Permissions issues found"
  26. fn_script_log_fatal "Permissions issues found"
  27. fn_print_infomation_nl "The following files are not executable:"
  28. fn_script_log_info "The following files are not executable:"
  29. {
  30. echo -e "File\n"
  31. find "${functionsdir}" -type f -not -executable -printf "%p\n"
  32. } | column -s $'\t' -t | tee -a "${scriptlog}"
  33. core_exit.sh
  34. fi
  35. fi
  36. # Check rootdir permissions
  37. if [ -n "${rootdir}" ]; then
  38. # Get permission numbers on folder under the form 775
  39. rootdirperm="$(stat -c %a "${rootdir}")"
  40. # Grab the first and second digit for user and group permission
  41. userrootdirperm="${rootdirperm:0:1}"
  42. grouprootdirperm="${rootdirperm:1:1}"
  43. if [ "${userrootdirperm}" != "7" ] && [ "${grouprootdirperm}" != "7" ]; then
  44. fn_print_fail_nl "Permissions issues found"
  45. fn_script_log_fatal "Permissions issues found"
  46. fn_print_infomation_nl "The following directorys does not have the correct permissions:"
  47. fn_script_log_info "The following directorys does not have the correct permissions:"
  48. ls -l "${rootdir}"
  49. core_exit.sh
  50. fi
  51. fi
  52. }
  53. fn_check_ownership
  54. fn_check_permissions