check_permissions.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # LGSM check_permissions.sh
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: http://gameservermanagers.com
  6. lgsm_version="150316"
  7. # Description: Checks script, files and folders ownership and permissions.
  8. # Initializing useful variables
  9. currentuser="$(whoami)"
  10. scriptfullpath="${rootdir}/${selfname}"
  11. permissionerror="0"
  12. fn_check_ownership(){
  13. if [ "${currentuser}" != "$(stat -c %U "${scriptfullpath}")" ] && [ "${currentuser}" != "$(stat -c %G "${scriptfullpath}")" ]; then
  14. permissionerror="1"
  15. fn_print_fail_nl "Permission denied"
  16. echo " * To check allowed user and group run ls -l ${selfname}"
  17. fi
  18. }
  19. fn_check_permissions(){
  20. if [ -n "${functionsdir}" ]; then
  21. find "${functionsdir}" -name "*.sh" | while read -r filename; do perm="$(stat -c %a "${filename}")"; shortperm="$(echo "${perm:0:1}")";
  22. if [ "${shortperm}" != "7" ]; then
  23. permissionerror="1"
  24. fn_print_warn_nl "Warning, permission issues found in ${functionsdir}"
  25. echo " * Easy fix : chmod -R 755 ${functionsdir}"
  26. fi
  27. done
  28. fi
  29. }
  30. fn_check_permissions_summary(){
  31. if [ "${permissionerror}" == "1" ]; then
  32. exit 1
  33. fi
  34. }
  35. fn_check_ownership
  36. fn_check_permissions
  37. fn_check_permissions_summary