core_exit.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 [ -z "${exitbypass}" ] && [ "${updatelocklevel}" == "${BASH_SUBSHELL}" ] && [ "$(cat "${lockdir}/updating.lock" 2> /dev/null)" == "$$" ]; then
  26. rm -f "${lockdir:?}/updating.lock"
  27. fi
  28. if [ "${exitbypass}" ]; then
  29. unset exitbypass
  30. elif [ "${exitcode}" -ne 0 ]; then
  31. # List LinuxGSM version in logs
  32. fn_script_log_info "LinuxGSM version: ${version}"
  33. if [ "${exitcode}" -eq 1 ]; then
  34. fn_script_log_fail "${moduleselfname} exiting with code: ${exitcode}"
  35. elif [ "${exitcode}" -eq 2 ]; then
  36. fn_script_log_error "${moduleselfname} exiting with code: ${exitcode}"
  37. elif [ "${exitcode}" -eq 3 ]; then
  38. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  39. else
  40. # if exit code is not set assume error.
  41. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  42. exitcode=4
  43. fi
  44. fn_exit_dev_debug
  45. # remove trap.
  46. trap - INT
  47. exit "${exitcode}"
  48. elif [ "${exitcode}" ] && [ "${exitcode}" -eq 0 ]; then
  49. # List LinuxGSM version in logs
  50. fn_script_log_info "LinuxGSM version: ${version}"
  51. fn_script_log_pass "${moduleselfname} exiting with code: ${exitcode}"
  52. fn_exit_dev_debug
  53. # remove trap.
  54. trap - INT
  55. exit "${exitcode}"
  56. else
  57. # List LinuxGSM version in logs
  58. fn_script_log_info "LinuxGSM version: ${version}"
  59. fn_print_error "No exit code set"
  60. fn_script_log_pass "${moduleselfname} exiting with code: NOT SET"
  61. fn_exit_dev_debug
  62. # remove trap.
  63. trap - INT
  64. exit "${exitcode}"
  65. fi