UltimateByte 10 лет назад
Родитель
Сommit
c1c5d2e1fd
1 измененных файлов с 17 добавлено и 11 удалено
  1. 17 11
      lgsm/functions/check_permissions.sh

+ 17 - 11
lgsm/functions/check_permissions.sh

@@ -8,21 +8,25 @@ lgsm_version="150316"
 # Description: Checks script, files and folders ownership and permissions.
 
 # Useful variables
+currentuser="$(whoami)"
+currentgroups="$(groups)"
 scriptfullpath="${rootdir}/${selfname}"
 conclusionpermissionerror="0"
 
 fn_check_ownership(){
 # Check script ownership
 if [ ! -O "${scriptfullpath}" ] && [ ! -G "${scriptfullpath}" ]; then
-  fn_print_fail_nl "Oops ! Permission denied on ${selfname}"
-  echo "	* To check allowed user and group run ls -l ${selfname}"
+  fn_print_fail_nl "Oops ! Ownership issue..."
+  echo "	* ${currentuser} or its group(s) - ${currentgroups} - does not own \"${selfname}\""
+  echo "	* To check the owner and allowed groups, run ls -l \"${selfname}\""
   exit 1
 fi
 
 # Check rootdir ownership
 if [ ! -O "${rootdir}" ] && [ ! -G "${rootdir}" ]; then
-  fn_print_fail_nl "Oops ! Permission denied on ${rootdir}"
-  echo "	* To check allowed user and group run ls -l ${rootdir}"
+  fn_print_fail_nl "Oops ! Ownership issue..."
+  echo "  * ${currentuser} or its group(s) - ${currentgroups} - does not own \"${rootdir}\""
+  echo "	* To check the owner and allowed groups, run ls -dl \"${rootdir}\""
   exit 1
 fi
 
@@ -38,9 +42,9 @@ if [ -n "${functionsdir}" ]; then
   done <<< "$(find "${functionsdir}" -name "*.sh")"
   
   if [ "${funownfail}" == "1" ]; then
-    fn_print_fail_nl "Permission issues found in functions."
-    echo "  * Neither the user or group has full control of some scripts in \"${functionsdir}\""
-    echo "  * You might wanna run : chmod -R 770 \"${functionsdir}\""
+    fn_print_fail_nl "Oops ! Ownership issue..."
+    echo "  * ${currentuser} or its group(s) - ${currentgroups} - does not own all scripts in \"${functionsdir}\""
+    echo "  * To check the owner and allowed groups, run ls -l \"${functionsdir}\""
   fi
 fi
 }
@@ -48,12 +52,14 @@ fi
 fn_check_permissions(){
 # Check rootdir permissions
 if [ -n "${rootdir}" ]; then
+  # Get permission numbers on folder under the form 775
   rootdirperm="$(stat -c %a "${rootdir}")"
+  # Grab the first and second digit for user and group permission
   userrootdirperm="${rootdirperm:0:1}"
   grouprootdirperm="${rootdirperm:1:1}"
   if [ "${userrootdirperm}" != "7" ] && [ "${grouprootdirperm}" != "7" ]; then
-    fn_print_fail_nl "Permission issues found in root directory"
-    echo "  * Neither the user or group has full control of \"${rootdir}\""
+    fn_print_fail_nl "Oops ! Permission issue..."
+    echo "  * ${currentuser} or its group(s) - ${currentgroups} need full control of \"${rootdir}\""
     echo "  * You might wanna run : chmod -R 770 \"${rootdir}\""
     conclusionpermissionerror="1"
   fi
@@ -74,8 +80,8 @@ if [ -n "${functionsdir}" ]; then
   done <<< "$(find "${functionsdir}" -name "*.sh")"
   
   if [ "${funcpermfail}" == "1" ]; then
-    fn_print_fail_nl "Permission issues found in functions."
-    echo "  * Neither the user or group has full control of at least some scripts in \"${functionsdir}\""
+    fn_print_fail_nl "Oops ! Permission issue..."
+    echo "  * ${currentuser} or its group(s) - ${currentgroups} need full control on scripts in \"${functionsdir}\""
     echo "  * You might wanna run : chmod -R 770 \"${functionsdir}\""
   fi
 fi