core_exit.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. # If running dependency check as root will remove any files that belong to root user.
  20. if [ "$(whoami)" == "root" ]; then
  21. find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  22. find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  23. fi
  24. if [ -z "${exitbypass}" ] && [ "${updatelocklevel}" == "${BASH_SUBSHELL}" ] && [ "$(cat "${lockdir}/updating.lock" 2> /dev/null)" == "$$" ]; then
  25. rm -f "${lockdir:?}/updating.lock"
  26. fi
  27. if [ "${exitbypass}" ]; then
  28. unset exitbypass
  29. elif [ "${exitcode}" -ne 0 ]; then
  30. # List LinuxGSM version in logs
  31. fn_script_log_info "LinuxGSM version: ${version}"
  32. if [ "${exitcode}" -eq 1 ]; then
  33. fn_script_log_fail "${moduleselfname} exiting with code: ${exitcode}"
  34. elif [ "${exitcode}" -eq 2 ]; then
  35. fn_script_log_error "${moduleselfname} exiting with code: ${exitcode}"
  36. elif [ "${exitcode}" -eq 3 ]; then
  37. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  38. else
  39. # if exit code is not set assume error.
  40. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  41. exitcode=4
  42. fi
  43. fn_exit_dev_debug
  44. # remove trap.
  45. trap - INT
  46. exit "${exitcode}"
  47. elif [ "${exitcode}" ] && [ "${exitcode}" -eq 0 ]; then
  48. # List LinuxGSM version in logs
  49. fn_script_log_info "LinuxGSM version: ${version}"
  50. fn_script_log_pass "${moduleselfname} exiting with code: ${exitcode}"
  51. fn_exit_dev_debug
  52. # remove trap.
  53. trap - INT
  54. exit "${exitcode}"
  55. else
  56. # List LinuxGSM version in logs
  57. fn_script_log_info "LinuxGSM version: ${version}"
  58. fn_print_error "No exit code set"
  59. fn_script_log_pass "${moduleselfname} exiting with code: NOT SET"
  60. fn_exit_dev_debug
  61. # remove trap.
  62. trap - INT
  63. exit "${exitcode}"
  64. fi