check_root.sh 543 B

123456789101112131415161718
  1. #!/bin/bash
  2. # LinuxGSM check_root.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Checks if the user tried to run the script as root.
  6. local commandname="CHECK"
  7. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. if [ "$(whoami)" = "root" ]; then
  9. if [ "${function_selfname}" != "command_install.sh" ]; then
  10. fn_print_fail_nl "Do NOT run this script as root!"
  11. if [ -d "${lgsmlogdir}" ]; then
  12. fn_script_log_fatal "${selfname} attempted to run as root."
  13. fi
  14. core_exit.sh
  15. fi
  16. fi