core_exit.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # LinuxGSM core_exit.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Handles exiting of LinuxGSM by running and reporting an exit code.
  6. fn_exit_dev_debug(){
  7. if [ -f "${rootdir}/.dev-debug" ]; then
  8. echo ""
  9. echo "${function_selfname} exiting with code: ${exitcode}"
  10. if [ -f "${rootdir}/dev-debug.log" ]; then
  11. grep "functionfile=" "${rootdir}/dev-debug.log" | sed 's/functionfile=//g' > "${rootdir}/dev-debug-function-order.log"
  12. fi
  13. fi
  14. }
  15. # If running dependency check as root will remove any files that belong to root user.
  16. if [ "$(whoami)" == "root" ]; then
  17. find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  18. find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  19. fi
  20. if [ -n "${exitbypass}" ]; then
  21. unset exitbypass
  22. elif [ -n "${exitcode}" ]&&[ "${exitcode}" != "0" ]; then
  23. if [ "${exitcode}" == "1" ]; then
  24. fn_script_log_fatal "${function_selfname} exiting with code: ${exitcode}"
  25. elif [ "${exitcode}" == "2" ]; then
  26. fn_script_log_error "${function_selfname} exiting with code: ${exitcode}"
  27. elif [ "${exitcode}" == "3" ]; then
  28. fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
  29. else
  30. fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
  31. fi
  32. fn_exit_dev_debug
  33. # remove trap.
  34. trap - INT
  35. exit "${exitcode}"
  36. else
  37. fn_script_log_pass "${function_selfname} exiting with code: ${exitcode}"
  38. fn_exit_dev_debug
  39. # remove trap.
  40. trap - INT
  41. exit "${exitcode}"
  42. fi