core_exit.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 -e ""
  9. echo -e "${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 [ "${exitbypass}" ]; then
  21. unset exitbypass
  22. elif [ "${exitcode}" ]&&[ "${exitcode}" != "0" ]; then
  23. # List LinuxGSM version in logs
  24. fn_script_log_info "LinuxGSM version: ${version}"
  25. if [ "${exitcode}" == "1" ]; then
  26. fn_script_log_fatal "${function_selfname} exiting with code: ${exitcode}"
  27. elif [ "${exitcode}" == "2" ]; then
  28. fn_script_log_error "${function_selfname} exiting with code: ${exitcode}"
  29. elif [ "${exitcode}" == "3" ]; then
  30. fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
  31. else
  32. fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
  33. fi
  34. fn_exit_dev_debug
  35. # remove trap.
  36. trap - INT
  37. exit "${exitcode}"
  38. elif [ "${exitcode}" ]&&[ "${exitcode}" == "0" ]; then
  39. # List LinuxGSM version in logs
  40. fn_script_log_info "LinuxGSM version: ${version}"
  41. fn_script_log_pass "${function_selfname} exiting with code: ${exitcode}"
  42. fn_exit_dev_debug
  43. # remove trap.
  44. trap - INT
  45. exit "${exitcode}"
  46. else
  47. # List LinuxGSM version in logs
  48. fn_script_log_info "LinuxGSM version: ${version}"
  49. fn_print_error "No exit code set"
  50. fn_script_log_pass "${function_selfname} exiting with code: NOT SET"
  51. fn_exit_dev_debug
  52. # remove trap.
  53. trap - INT
  54. exit "${exitcode}"
  55. fi