check_permissions.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. permissionfailure="0"
  21. if [ -n "${functionsdir}" ]; then
  22. while read -r filename
  23. do
  24. perm="$(stat -c %a "${filename}")"
  25. shortperm="${perm:0:1}"
  26. if [ "${shortperm}" != "7" ]; then
  27. permissionfailure="1"
  28. fi
  29. done <<< "$(find "${functionsdir}" -name "*.sh")"
  30. if [ "${permissionfailure}" == "1" ]; then
  31. fn_print_warn_nl "Warning, permission issues found in ${functionsdir}"
  32. echo " * Easy fix : chmod -R 755 ${functionsdir}"
  33. fi
  34. fi
  35. }
  36. fn_check_permissions_conclusion(){
  37. if [ "${permissionerror}" == "1" ]; then
  38. exit 1
  39. fi
  40. }
  41. fn_check_ownership
  42. fn_check_permissions
  43. fn_check_permissions_conclusion