check_root.sh 473 B

12345678910111213141516
  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. fn_print_fail_nl "Do NOT run this script as root!"
  10. if [ -d "${lgsmlogdir}" ]; then
  11. fn_script_log_fatal "${selfname} attempted to run as root."
  12. fi
  13. core_exit.sh
  14. fi