Browse Source

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
pull/4254/head
Daniel Gibbs 2 years ago
parent
commit
2ff6b68239
  1. 4
      lgsm/modules/check.sh
  2. 2
      lgsm/modules/check_deps.sh
  3. 4
      lgsm/modules/check_permissions.sh
  4. 2
      lgsm/modules/check_root.sh
  5. 2
      lgsm/modules/command_install.sh
  6. 2
      lgsm/modules/core_exit.sh
  7. 2
      linuxgsm.sh

4
lgsm/modules/check.sh

@ -21,7 +21,7 @@ fi
check_tmuxception.sh check_tmuxception.sh
if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then if [ "$(whoami)" != "root" ]; then
if [ "${commandname}" != "MONITOR" ]; then if [ "${commandname}" != "MONITOR" ]; then
check_permissions.sh check_permissions.sh
fi fi
@ -38,7 +38,7 @@ for allowed_command in "${allowed_commands_array[@]}"; do
fi fi
done done
if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then if [ "$(whoami)" != "root" ]; then
allowed_commands_array=(DEBUG START INSTALL) allowed_commands_array=(DEBUG START INSTALL)
for allowed_command in "${allowed_commands_array[@]}"; do for allowed_command in "${allowed_commands_array[@]}"; do
if [ "${allowed_command}" == "${commandname}" ]; then if [ "${allowed_command}" == "${commandname}" ]; then

2
lgsm/modules/check_deps.sh

@ -301,7 +301,7 @@ fn_deps_detector() {
} }
if [ "${commandname}" == "INSTALL" ]; then if [ "${commandname}" == "INSTALL" ]; then
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then if [ "$(whoami)" == "root" ]; then
echo -e "" echo -e ""
echo -e "${lightyellow}Checking Dependencies as root${default}" echo -e "${lightyellow}Checking Dependencies as root${default}"
echo -e "=================================" echo -e "================================="

4
lgsm/modules/check_permissions.sh

@ -223,8 +223,8 @@ fn_sys_perm_error_process() {
fi fi
} }
## Run permisions checks when not root or docker. ## Run permisions checks when not root.
if [ "$(whoami)" != "root" ] && [ ! -f /.dockerenv ]; then if [ "$(whoami)" != "root" ]; then
fn_check_ownership fn_check_ownership
fn_check_permissions fn_check_permissions
if [ "${commandname}" == "START" ]; then if [ "${commandname}" == "START" ]; then

2
lgsm/modules/check_root.sh

@ -7,7 +7,7 @@
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then if [ "$(whoami)" == "root" ]; then
if [ "${commandname}" != "INSTALL" ]; then if [ "${commandname}" != "INSTALL" ]; then
fn_print_fail_nl "Do NOT run this script as root!" fn_print_fail_nl "Do NOT run this script as root!"
if [ -d "${lgsmlogdir}" ]; then if [ -d "${lgsmlogdir}" ]; then

2
lgsm/modules/command_install.sh

@ -11,7 +11,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set fn_firstcommand_set
check.sh check.sh
if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then if [ "$(whoami)" == "root" ]; then
check_deps.sh check_deps.sh
else else
install_header.sh install_header.sh

2
lgsm/modules/core_exit.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 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 "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1 find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
fi fi

2
linuxgsm.sh

@ -321,7 +321,7 @@ fn_install_file() {
} }
# Prevent LinuxGSM from running as root. Except if doing a dependency install. # 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 [ "${userinput}" == "install" ] || [ "${userinput}" == "auto-install" ] || [ "${userinput}" == "i" ] || [ "${userinput}" == "ai" ]; then
if [ "${shortname}" == "core" ]; then if [ "${shortname}" == "core" ]; then
echo -e "[ FAIL ] Do NOT run this script as root!" echo -e "[ FAIL ] Do NOT run this script as root!"

Loading…
Cancel
Save