core_exit.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. fi
  15. fi
  16. }
  17. # If running dependency check as root will remove any files that belong to root user.
  18. if [ "$(whoami)" == "root" ]; 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_fail "${moduleselfname} exiting with code: ${exitcode}"
  29. elif [ "${exitcode}" == "2" ]; then
  30. fn_script_log_error "${moduleselfname} exiting with code: ${exitcode}"
  31. elif [ "${exitcode}" == "3" ]; then
  32. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  33. else
  34. # if exit code is not set assume error.
  35. fn_script_log_warn "${moduleselfname} exiting with code: ${exitcode}"
  36. exitcode=4
  37. fi
  38. fn_exit_dev_debug
  39. # remove trap.
  40. trap - INT
  41. exit "${exitcode}"
  42. elif [ "${exitcode}" ] && [ "${exitcode}" == "0" ]; then
  43. # List LinuxGSM version in logs
  44. fn_script_log_info "LinuxGSM version: ${version}"
  45. fn_script_log_pass "${moduleselfname} exiting with code: ${exitcode}"
  46. fn_exit_dev_debug
  47. # remove trap.
  48. trap - INT
  49. exit "${exitcode}"
  50. else
  51. # List LinuxGSM version in logs
  52. fn_script_log_info "LinuxGSM version: ${version}"
  53. fn_print_error "No exit code set"
  54. fn_script_log_pass "${moduleselfname} exiting with code: NOT SET"
  55. fn_exit_dev_debug
  56. # remove trap.
  57. trap - INT
  58. exit "${exitcode}"
  59. fi