mirror of
https://github.com/GameServerManagers/LinuxGSM.git
synced 2025-01-08 12:07:37 +08:00
refactor(docker): simplify root user check
The code changes remove the unnecessary check for the presence of a Docker environment in multiple scripts. Instead, they now only check if the current user is not root. This simplifies the logic and improves readability. - Simplify root user check in `check.sh`, `check_deps.sh`, `check_permissions.sh`, `check_root.sh`, `command_install.sh`, `core_exit.sh`, and `linuxgsm.sh` - Remove redundant checks for Docker environment - Improve code readability
This commit is contained in:
parent
f2779d1b2d
commit
2ff6b68239
@ -21,7 +21,7 @@ fi
|
||||
|
||||
check_tmuxception.sh
|
||||
|
||||
if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" != "root" ]; then
|
||||
if [ "${commandname}" != "MONITOR" ]; then
|
||||
check_permissions.sh
|
||||
fi
|
||||
@ -38,7 +38,7 @@ for allowed_command in "${allowed_commands_array[@]}"; do
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" != "root" ]; then
|
||||
allowed_commands_array=(DEBUG START INSTALL)
|
||||
for allowed_command in "${allowed_commands_array[@]}"; do
|
||||
if [ "${allowed_command}" == "${commandname}" ]; then
|
||||
|
@ -301,7 +301,7 @@ fn_deps_detector() {
|
||||
}
|
||||
|
||||
if [ "${commandname}" == "INSTALL" ]; then
|
||||
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" == "root" ]; then
|
||||
echo -e ""
|
||||
echo -e "${lightyellow}Checking Dependencies as root${default}"
|
||||
echo -e "================================="
|
||||
|
@ -223,8 +223,8 @@ fn_sys_perm_error_process() {
|
||||
fi
|
||||
}
|
||||
|
||||
## Run permisions checks when not root or docker.
|
||||
if [ "$(whoami)" != "root" ] && [ ! -f /.dockerenv ]; then
|
||||
## Run permisions checks when not root.
|
||||
if [ "$(whoami)" != "root" ]; then
|
||||
fn_check_ownership
|
||||
fn_check_permissions
|
||||
if [ "${commandname}" == "START" ]; then
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
|
||||
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" == "root" ]; then
|
||||
if [ "${commandname}" != "INSTALL" ]; then
|
||||
fn_print_fail_nl "Do NOT run this script as root!"
|
||||
if [ -d "${lgsmlogdir}" ]; then
|
||||
|
@ -11,7 +11,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
fn_firstcommand_set
|
||||
|
||||
check.sh
|
||||
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" == "root" ]; then
|
||||
check_deps.sh
|
||||
else
|
||||
install_header.sh
|
||||
|
@ -18,7 +18,7 @@ fn_exit_dev_debug() {
|
||||
}
|
||||
|
||||
# If running dependency check as root will remove any files that belong to root user.
|
||||
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" == "root" ]; then
|
||||
find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
|
||||
find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
|
||||
fi
|
||||
|
@ -321,7 +321,7 @@ fn_install_file() {
|
||||
}
|
||||
|
||||
# Prevent LinuxGSM from running as root. Except if doing a dependency install.
|
||||
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
|
||||
if [ "$(whoami)" == "root" ]; then
|
||||
if [ "${userinput}" == "install" ] || [ "${userinput}" == "auto-install" ] || [ "${userinput}" == "i" ] || [ "${userinput}" == "ai" ]; then
|
||||
if [ "${shortname}" == "core" ]; then
|
||||
echo -e "[ FAIL ] Do NOT run this script as root!"
|
||||
|
Loading…
Reference in New Issue
Block a user