v-generate-debug-report 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Includes
  3. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  4. source $HESTIA/conf/hestia.conf
  5. # Variables and arguments
  6. HESTIA="/usr/local/hestia"
  7. script=$1
  8. log=$2
  9. mode=${3-$2}
  10. if [ "$DEBUG_MODE" = "no" ] || [ -z "$DEBUG_MODE" ]; then
  11. echo "ERROR: Developer mode is disabled."
  12. echo "Enable with v-change-sys-config-value DEBUG_MODE yes"
  13. exit 1
  14. fi
  15. if [ -z "$script" ]; then
  16. echo "ERROR: No script specified."
  17. echo "Usage: v-generate-debug-report v-script-name LOG_OUTPUT"
  18. echo ""
  19. echo "Example: v-generate-debug-report v-add-user yes"
  20. echo " Log output to file located in ~/hst-debug/"
  21. echo ""
  22. echo "Example: v-generate-debug-report v-list-web-domains"
  23. echo " Show output in console."
  24. echo ""
  25. exit 1
  26. fi
  27. # Install shellcheck
  28. package_check=$(dpkg -l | grep shellcheck)
  29. if [ -z "$package_check" ]; then
  30. echo "[ * ] Updating APT package cache..."
  31. apt-get -qq update > /dev/null 2>&1
  32. echo "[ * ] Installing shellcheck code linter..."
  33. apt-get -qq install -y shellcheck > /dev/null 2>&1
  34. fi
  35. # Set debug path and ensure it exists
  36. DEBUG_PATH="$HOME/hst-debug/"
  37. if [ ! -d "$DEBUG_PATH" ]; then
  38. mkdir "$DEBUG_PATH"
  39. fi
  40. # Generate timestamp
  41. time_n_date=$(date +'%F %T')
  42. time_n_date=$(echo $time_n_date | sed "s|:||g" | sed "s| |_|g")
  43. # If logging specified, export shellcheck output to log
  44. if [ "$log" = "yes" ]; then
  45. if [ "$mode" = "all" ]; then
  46. shellcheck -x "$HESTIA/bin/$script" > "$DEBUG_PATH/${script}_$date-$time.log"
  47. fi
  48. if [ "$mode" = "warn" ]; then
  49. shellcheck -x -e "SC2086,SC1090,SC2154,SC2153" "$HESTIA/bin/$script" > "$DEBUG_PATH/${script}_$date-$time.log"
  50. else
  51. shellcheck -x -e "SC2086,SC2016,SC2153,SC2154,SC1090,SC2034,SC2119" "$HESTIA/bin/$script" > "$DEBUG_PATH/${script}_$date-$time.log"
  52. fi
  53. else
  54. # Prompt user to scroll output from shellcheck
  55. clear
  56. if [ "$mode" = "all" ]; then
  57. shellcheck -x "$HESTIA/bin/$script"
  58. fi
  59. if [ "$mode" = "warn" ]; then
  60. shellcheck -x -e "SC2086,SC1090,SC2154,SC2153" "$HESTIA/bin/$script"
  61. else
  62. shellcheck -x -e "SC2086,SC2016,SC2153,SC2154,SC1090,SC2034,SC2119" "$HESTIA/bin/$script"
  63. fi
  64. fi