core_exit.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_exit_dev_debug() {
  9. if [ -f "${rootdir}/.dev-debug" ]; then
  10. echo -e ""
  11. echo -e "${functionselfname} exiting with code: ${exitcode}"
  12. if [ -f "${rootdir}/dev-debug.log" ]; then
  13. grep "functionfile=" "${rootdir}/dev-debug.log" | sed 's/functionfile=//g' > "${rootdir}/dev-debug-function-order.log"
  14. fi
  15. fi
  16. }
  17. # If running dependency check as root will remove any files that belong to root user.
  18. if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then
  19. find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  20. find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1
  21. fi
  22. if [ "${exitbypass}" ]; then
  23. unset exitbypass
  24. elif [ "${exitcode}" != "0" ]; then
  25. # List LinuxGSM version in logs
  26. fn_script_log_info "LinuxGSM version: ${version}"
  27. if [ "${exitcode}" == "1" ]; then
  28. fn_script_log_fatal "${functionselfname} exiting with code: ${exitcode}"
  29. elif [ "${exitcode}" == "2" ]; then
  30. fn_script_log_error "${functionselfname} exiting with code: ${exitcode}"
  31. elif [ "${exitcode}" == "3" ]; then
  32. fn_script_log_warn "${functionselfname} exiting with code: ${exitcode}"
  33. else
  34. fn_script_log_warn "${functionselfname} exiting with code: ${exitcode}"
  35. fi
  36. fn_exit_dev_debug
  37. # remove trap.
  38. trap - INT
  39. exit "${exitcode}"
  40. elif [ "${exitcode}" ] && [ "${exitcode}" == "0" ]; then
  41. # List LinuxGSM version in logs
  42. fn_script_log_info "LinuxGSM version: ${version}"
  43. fn_script_log_pass "${functionselfname} exiting with code: ${exitcode}"
  44. fn_exit_dev_debug
  45. # remove trap.
  46. trap - INT
  47. exit "${exitcode}"
  48. else
  49. # List LinuxGSM version in logs
  50. fn_script_log_info "LinuxGSM version: ${version}"
  51. fn_print_error "No exit code set"
  52. fn_script_log_pass "${functionselfname} exiting with code: NOT SET"
  53. fn_exit_dev_debug
  54. # remove trap.
  55. trap - INT
  56. exit "${exitcode}"
  57. fi