core_exit.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # LinuxGSM core_exit.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Handles exiting of LinuxGSM by running and reporting an exit code.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_exit_dev_debug() {
  9. if [ -f "${rootdir}/.dev-debug" ]; then
  10. echo -e ""
  11. echo -e "${moduleselfname} exiting with code: ${exitcode}"
  12. if [ -f "${rootdir}/dev-debug.log" ]; then
  13. grep -a "modulefile=" "${rootdir}/dev-debug.log" | sed 's/modulefile=//g' > "${rootdir}/dev-debug-module-order.log"
  14. elif [ -f "${logdir}/dev-debug.log" ]; then
  15. grep -a "modulefile=" "${logdir}/dev-debug.log" | sed 's/modulefile=//g' > "${logdir}/dev-debug-module-order.log"
  16. fi
  17. fi
  18. }
  19. fn_print_plain_flush
  20. # If running dependency check as root will remove any files that belong to root user.
  21. if [ "$(whoami)" == "root" ]; then
  22. find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  23. find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  24. fi
  25. if [ "${exitbypass}" ]; then
  26. unset exitbypass
  27. elif [ "${exitcode}" -ne 0 ]; then
  28. # List LinuxGSM version in logs
  29. fn_script_log_info "LinuxGSM version: ${version}"
  30. if [ "${exitcode}" -eq 1 ]; then
  31. fn_script_log_fail "${moduleselfname} exiting with code: ${exitcode}"
  32. elif [ "${exitcode}" -eq 2 ]; then
  33. fn_script_log_error "${moduleselfname} exiting with code: ${exitcode}"
  34. elif [ "${exitcode}" -eq 3 ]; then
  35. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  36. else
  37. # if exit code is not set assume error.
  38. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  39. exitcode=4
  40. fi
  41. fn_exit_dev_debug
  42. # remove trap.
  43. trap - INT
  44. exit "${exitcode}"
  45. elif [ "${exitcode}" ] && [ "${exitcode}" -eq 0 ]; then
  46. # List LinuxGSM version in logs
  47. fn_script_log_info "LinuxGSM version: ${version}"
  48. fn_script_log_pass "${moduleselfname} exiting with code: ${exitcode}"
  49. fn_exit_dev_debug
  50. # remove trap.
  51. trap - INT
  52. exit "${exitcode}"
  53. else
  54. # List LinuxGSM version in logs
  55. fn_script_log_info "LinuxGSM version: ${version}"
  56. fn_print_error "No exit code set"
  57. fn_script_log_pass "${moduleselfname} exiting with code: NOT SET"
  58. fn_exit_dev_debug
  59. # remove trap.
  60. trap - INT
  61. exit "${exitcode}"
  62. fi