core_exit.sh 2.0 KB

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