mirror of
https://github.com/GameServerManagers/LinuxGSM.git
synced 2025-01-07 03:26:50 +08:00
refactor: refactor check_permissions.sh (#4626)
Refactored the code in check_permissions.sh to improve readability and maintainability. Made changes to variable names for clarity and removed unnecessary comments. Also, refactored the fn_sys_perm_errors_detect function name for consistency.
This commit is contained in:
parent
e060865aef
commit
7ece812c8c
@ -13,6 +13,11 @@ fn_check_ownership() {
|
||||
selfownissue=1
|
||||
fi
|
||||
fi
|
||||
if [ -d "${lgsmdir}" ]; then
|
||||
if [ "$(find "${lgsmdir}" -not -user "$(whoami)" | wc -l)" -ne "0" ]; then
|
||||
lgsmownissue=1
|
||||
fi
|
||||
fi
|
||||
if [ -d "${modulesdir}" ]; then
|
||||
if [ "$(find "${modulesdir}" -not -name '*.swp' -not -user "$(whoami)" | wc -l)" -ne "0" ]; then
|
||||
funcownissue=1
|
||||
@ -23,18 +28,18 @@ fn_check_ownership() {
|
||||
filesownissue=1
|
||||
fi
|
||||
fi
|
||||
if [ "${selfownissue}" == "1" ] || [ "${funcownissue}" == "1" ] || [ "${filesownissue}" == "1" ]; then
|
||||
if [ "${selfownissue}" == "1" ] || [ "${lgsmownissue}" == "1" ] || [ "${filesownissue}" == "1" ]; then
|
||||
fn_print_fail_nl "Ownership issues found"
|
||||
fn_script_log_fail "Ownership issues found"
|
||||
fn_print_information_nl "The current user ($(whoami)) does not have ownership of the following files:"
|
||||
fn_script_log_info "The current user ($(whoami)) does not have ownership of the following files:"
|
||||
{
|
||||
echo -e "User\tGroup\tFile\n"
|
||||
echo -en "User\tGroup\tFile:"
|
||||
if [ "${selfownissue}" == "1" ]; then
|
||||
find "${rootdir}/${selfname}" -not -user "$(whoami)" -printf "%u\t%g\t%p\n"
|
||||
fi
|
||||
if [ "${funcownissue}" == "1" ]; then
|
||||
find "${modulesdir}" -not -user "$(whoami)" -printf "%u\t%g\t%p\n"
|
||||
if [ "${lgsmownissue}" == "1" ]; then
|
||||
find "${lgsmdir}" -not -user "$(whoami)" -printf "%u\t%g\t%p\n"
|
||||
fi
|
||||
if [ "${filesownissue}" == "1" ]; then
|
||||
find "${serverfiles}" -not -user "$(whoami)" -printf "%u\t%g\t%p\n"
|
||||
@ -53,15 +58,18 @@ fn_check_ownership() {
|
||||
}
|
||||
|
||||
fn_check_permissions() {
|
||||
# Check modules files are executable.
|
||||
if [ -d "${modulesdir}" ]; then
|
||||
if [ "$(find "${modulesdir}" -type f -not -executable | wc -l)" -ne "0" ]; then
|
||||
findnotexecutable="$(find "${modulesdir}" -type f -not -executable)"
|
||||
findnotexecutablewc="$(echo "${findnotexecutable}" | wc -l)"
|
||||
if [ "${findnotexecutablewc}" -ne "0" ]; then
|
||||
fn_print_fail_nl "Permissions issues found"
|
||||
fn_script_log_fail "Permissions issues found"
|
||||
fn_print_information_nl "The following files are not executable:"
|
||||
fn_script_log_info "The following files are not executable:"
|
||||
{
|
||||
echo -e "File\n"
|
||||
find "${modulesdir}" -type f -not -executable -printf "%p\n"
|
||||
echo -en "File:"
|
||||
echo -en "${findnotexecutable}"
|
||||
} | column -s $'\t' -t | tee -a "${lgsmlog}"
|
||||
if [ "${monitorflag}" == 1 ]; then
|
||||
alert="permissions"
|
||||
@ -72,8 +80,8 @@ fn_check_permissions() {
|
||||
fi
|
||||
|
||||
# Check rootdir permissions.
|
||||
if [ "${rootdir}" ]; then
|
||||
# Get permission numbers on directory under the form 775.
|
||||
if [ -d "${rootdir}" ]; then
|
||||
# Get permission numbers on directory should return 775.
|
||||
rootdirperm=$(stat -c %a "${rootdir}")
|
||||
# Grab the first and second digit for user and group permission.
|
||||
userrootdirperm="${rootdirperm:0:1}"
|
||||
@ -92,6 +100,7 @@ fn_check_permissions() {
|
||||
core_exit.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if executable is executable and attempt to fix it.
|
||||
# First get executable name.
|
||||
execname=$(basename "${executable}")
|
||||
@ -141,7 +150,7 @@ fn_check_permissions() {
|
||||
fi
|
||||
}
|
||||
|
||||
## The following fn_sys_perm_* modules checks for permission errors in /sys directory.
|
||||
## The following fn_sys_perm_* function checks for permission errors in /sys directory.
|
||||
|
||||
# Checks for permission errors in /sys directory.
|
||||
fn_sys_perm_errors_detect() {
|
||||
|
Loading…
Reference in New Issue
Block a user