core_exit.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 [ -n "${exitbypass}" ]; then
  16. unset exitbypass
  17. elif [ -n "${exitcode}" ]&&[ "${exitcode}" != "0" ]; then
  18. if [ "${exitcode}" == "1" ]; then
  19. fn_script_log_fatal "${function_selfname} exiting with code: ${exitcode}"
  20. elif [ "${exitcode}" == "2" ]; then
  21. fn_script_log_error "${function_selfname} exiting with code: ${exitcode}"
  22. elif [ "${exitcode}" == "3" ]; then
  23. fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
  24. else
  25. fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
  26. fi
  27. fn_exit_dev_debug
  28. # remove trap.
  29. trap - INT
  30. exit "${exitcode}"
  31. else
  32. exitcode=0
  33. fn_script_log_pass "${function_selfname} exiting with code: ${exitcode}"
  34. fn_exit_dev_debug
  35. # remove trap.
  36. trap - INT
  37. exit "${exitcode}"
  38. fi