check_root.sh 592 B

123456789101112131415161718192021
  1. #!/bin/bash
  2. # LinuxGSM check_root.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Checks if the user tried to run the script as root.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. if [ "$(whoami)" == "root" ]; then
  9. if [ "${commandname}" != "INSTALL" ]; then
  10. fn_print_fail_nl "Do NOT run as root!"
  11. if [ -d "${lgsmlogdir}" ]; then
  12. fn_script_log_fail "${selfname} attempted to run as root."
  13. else
  14. # Forces exit code is log does not yet exist.
  15. exitcode=1
  16. fi
  17. core_exit.sh
  18. fi
  19. fi