core_exit.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # LinuxGSM core_exit.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://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 "${lgsmlogdir}/dev-debug.log" ]; then
  15. grep -a "modulefile=" "${lgsmlogdir}/dev-debug.log" | sed 's/modulefile=//g' > "${rootdir}/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 [ "${exitbypass}" ]; then
  25. unset exitbypass
  26. elif [ "${exitcode}" != "0" ]; then
  27. # List LinuxGSM version in logs
  28. fn_script_log_info "LinuxGSM version: ${version}"
  29. if [ "${exitcode}" == "1" ]; then
  30. fn_script_log_fail "${moduleselfname} exiting with code: ${exitcode}"
  31. elif [ "${exitcode}" == "2" ]; then
  32. fn_script_log_error "${moduleselfname} exiting with code: ${exitcode}"
  33. elif [ "${exitcode}" == "3" ]; then
  34. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  35. else
  36. # if exit code is not set assume error.
  37. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  38. exitcode=4
  39. fi
  40. fn_exit_dev_debug
  41. # remove trap.
  42. trap - INT
  43. exit "${exitcode}"
  44. elif [ "${exitcode}" ] && [ "${exitcode}" == "0" ]; then
  45. # List LinuxGSM version in logs
  46. fn_script_log_info "LinuxGSM version: ${version}"
  47. fn_script_log_pass "${moduleselfname} exiting with code: ${exitcode}"
  48. fn_exit_dev_debug
  49. # remove trap.
  50. trap - INT
  51. exit "${exitcode}"
  52. else
  53. # List LinuxGSM version in logs
  54. fn_script_log_info "LinuxGSM version: ${version}"
  55. fn_print_error "No exit code set"
  56. fn_script_log_pass "${moduleselfname} exiting with code: NOT SET"
  57. fn_exit_dev_debug
  58. # remove trap.
  59. trap - INT
  60. exit "${exitcode}"
  61. fi