Skip to content

Commit 2ff6b68

Browse files
committed
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
1 parent f2779d1 commit 2ff6b68

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

lgsm/modules/check.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fi
2121

2222
check_tmuxception.sh
2323

24-
if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then
24+
if [ "$(whoami)" != "root" ]; then
2525
if [ "${commandname}" != "MONITOR" ]; then
2626
check_permissions.sh
2727
fi
@@ -38,7 +38,7 @@ for allowed_command in "${allowed_commands_array[@]}"; do
3838
fi
3939
done
4040

41-
if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then
41+
if [ "$(whoami)" != "root" ]; then
4242
allowed_commands_array=(DEBUG START INSTALL)
4343
for allowed_command in "${allowed_commands_array[@]}"; do
4444
if [ "${allowed_command}" == "${commandname}" ]; then

lgsm/modules/check_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn_deps_detector() {
301301
}
302302

303303
if [ "${commandname}" == "INSTALL" ]; then
304-
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
304+
if [ "$(whoami)" == "root" ]; then
305305
echo -e ""
306306
echo -e "${lightyellow}Checking Dependencies as root${default}"
307307
echo -e "================================="

lgsm/modules/check_permissions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ fn_sys_perm_error_process() {
223223
fi
224224
}
225225

226-
## Run permisions checks when not root or docker.
227-
if [ "$(whoami)" != "root" ] && [ ! -f /.dockerenv ]; then
226+
## Run permisions checks when not root.
227+
if [ "$(whoami)" != "root" ]; then
228228
fn_check_ownership
229229
fn_check_permissions
230230
if [ "${commandname}" == "START" ]; then

lgsm/modules/check_root.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
99

10-
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
10+
if [ "$(whoami)" == "root" ]; then
1111
if [ "${commandname}" != "INSTALL" ]; then
1212
fn_print_fail_nl "Do NOT run this script as root!"
1313
if [ -d "${lgsmlogdir}" ]; then

lgsm/modules/command_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1111
fn_firstcommand_set
1212

1313
check.sh
14-
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
14+
if [ "$(whoami)" == "root" ]; then
1515
check_deps.sh
1616
else
1717
install_header.sh

lgsm/modules/core_exit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn_exit_dev_debug() {
1818
}
1919

2020
# If running dependency check as root will remove any files that belong to root user.
21-
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
21+
if [ "$(whoami)" == "root" ]; then
2222
find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
2323
find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
2424
fi

linuxgsm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn_install_file() {
321321
}
322322

323323
# Prevent LinuxGSM from running as root. Except if doing a dependency install.
324-
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
324+
if [ "$(whoami)" == "root" ]; then
325325
if [ "${userinput}" == "install" ] || [ "${userinput}" == "auto-install" ] || [ "${userinput}" == "i" ] || [ "${userinput}" == "ai" ]; then
326326
if [ "${shortname}" == "core" ]; then
327327
echo -e "[ FAIL ] Do NOT run this script as root!"

0 commit comments

Comments
 (0)