lognconf-report.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/usr/bin/env bash
  2. set -o errexit #>Exit when a command fails (returns non-zero)
  3. set -o pipefail #>Exit when a command within a pipeline fail (returns non-zero)
  4. set -o nounset #>Forbid to use unse
  5. declare -A Paths
  6. Paths[sys]="$HOME"/lognconf_systeminfo.md
  7. Paths[log]="$HOME"/lognconf_logging.md
  8. Paths[plot]="$HOME"/lognconf_plot.svg
  9. Paths[url]="https://notabug.org/megavolt/random-scripts/raw/master/lognconf-report.sh"
  10. if [[ ! -t 0 ]] ; then
  11. echo "Pipe detected!"
  12. echo "Please don't pipe the script. Run it like that:"
  13. echo "* bash <(curl -s "${Paths[url]}")"
  14. echo "* curl -s ${Paths[url]} > /tmp/lncr.sh && bash /tmp/lncr.sh"
  15. echo "* bash lognconf-report.sh"
  16. echo "* chmod +x lognconf-report.sh && ./lognconf-report.sh"
  17. exit
  18. fi
  19. export LANG=C
  20. declare -A BootConfigs
  21. BootConfigs[grub]='/etc/default/grub'
  22. BootConfigs[mkinitcpio]='/etc/mkinitcpio.conf'
  23. BootConfigs[fstab]='/etc/fstab'
  24. BootConfigs[cryptab]='/etc/cryptab'
  25. BootConfigs[xorg]='/etc/X11/xorg.conf'
  26. BootConfigs[mkinitcpiod]='/etc/mkinitcpio.d/'
  27. BootConfigs[xorgconfd]='/etc/X11/xorg.conf.d/'
  28. BootConfigs[modeprobed]='/etc/modprobe.d/'
  29. BootConfigs[modulesloadd]='/etc/modules-load.d/'
  30. declare -A BootLogs
  31. BootLogs[xorgsys]='/var/log/'
  32. BootLogs[xorghme]="$HOME/.local/share/xorg/"
  33. OutPut=""
  34. function GetINXI ()
  35. {
  36. if [[ -x /usr/bin/inxi ]]; then
  37. inxi --full --admin --filter --width 80 --color=0
  38. fi
  39. }
  40. function MHWDGetGPU ()
  41. {
  42. local choice=$1
  43. local MHWD='/usr/bin/mhwd'
  44. local RMCOLOR='s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g'
  45. if [[ -x $MHWD ]]; then
  46. if [[ $choice == "list" ]]; then
  47. $MHWD --list | sed -r "${RMCOLOR}"
  48. elif [[ $choice == "installed" ]]; then
  49. $MHWD --listinstalled | sed -r "${RMCOLOR}"
  50. fi
  51. fi
  52. }
  53. function MHWDGetKernel ()
  54. {
  55. local choice=$1
  56. local KRNL='/usr/bin/mhwd-kernel'
  57. local RMCOLOR='s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g'
  58. if [[ -x $KRNL ]]; then
  59. if [[ $choice == "list" ]]; then
  60. $KRNL --list | sed -r "${RMCOLOR}"
  61. elif [[ $choice == "installed" ]]; then
  62. $KRNL --listinstalled | sed -r "${RMCOLOR}"
  63. fi
  64. fi
  65. }
  66. function GetXorgLogs ()
  67. {
  68. if [[ $DESKTOP_SESSION == "gnome" ]]; then
  69. echo -e "\n#### XORG Journal (Gnome)\n\n~~~\n$(journalctl --boot 0 --user --grep "\([A-Z][A-Z]\)" --no-hostname --no-pager)\n~~~\n\n"
  70. fi
  71. if [[ $DESKTOP_SESSION != "gnome" ]]; then
  72. for index in "${!BootLogs[@]}"; do
  73. for path in $(find "${BootLogs[$index]}" -name "Xorg.*" 2>/dev/null); do
  74. echo -e "\n#### ${path}\n\n~~~\n$(cat "${path}")\n~~~\n\n"
  75. done
  76. done
  77. fi
  78. }
  79. function GetBootConfigs ()
  80. {
  81. for index in "${!BootConfigs[@]}"; do
  82. # Search folders and get content
  83. if [[ ${index} == "xorgconfd" ]] \
  84. || [[ ${index} == "modeprobed" ]] \
  85. || [[ ${index} == "modulesloadd" ]] \
  86. || [[ ${index} == "mkinitcpiod" ]]; then
  87. for path in $(find "${BootConfigs[$index]}" \( -name "*.conf" -o -name "*.preset" \) 2>/dev/null); do
  88. echo -e "\n#### ${path}\n\n~~~\n$(cat "${path}")\n~~~\n\n"
  89. done
  90. continue
  91. fi
  92. if [[ -f "${BootConfigs[$index]}" ]]; then
  93. echo -e "\n#### ${BootConfigs[$index]}\n\n~~~\n$(cat "${BootConfigs[$index]}")\n~~~\n\n"
  94. fi
  95. done
  96. }
  97. function GetBlockDevices ()
  98. {
  99. if [[ -x "/usr/bin/lsblk" ]]; then
  100. lsblk --fs --all
  101. fi
  102. }
  103. function GetSystemJournals ()
  104. {
  105. local choice=$1
  106. if [[ -x "/usr/bin/journalctl" ]]; then
  107. if [[ $choice == "current" ]]; then
  108. journalctl --boot 0 --no-hostname --no-pager
  109. elif [[ $choice == "previous" ]]; then
  110. journalctl --boot -1 --no-hostname --no-pager
  111. fi
  112. fi
  113. }
  114. function GetSystemLoadTime ()
  115. {
  116. local choice=$1
  117. if [[ -x "/usr/bin/systemd-analyze" ]]; then
  118. if [[ $choice == "svg" ]]; then
  119. systemd-analyze plot
  120. elif [[ $choice == "blame" ]]; then
  121. systemd-analyze blame
  122. elif [[ $choice == "basic" ]]; then
  123. systemd-analyze
  124. fi
  125. fi
  126. }
  127. function upload ()
  128. {
  129. echo "Systeminfo: $(echo -e "${OutPut}" | curl -s -F'file=@-' https://0x0.st)"
  130. echo "Logs: $(echo -e "${Logs}" | curl -s -F'file=@-' https://0x0.st)"
  131. echo "Plot: $(echo -e "${Plot}" | curl -s -F'file=@-' https://0x0.st)"
  132. }
  133. function save ()
  134. {
  135. echo -e "${OutPut}" > "${Paths[sys]}"
  136. echo -e "${Logs}" > "${Paths[log]}"
  137. echo -e "${Plot}" > "${Paths[plot]}"
  138. #cp /tmp/plot.svg "${Paths[plot]"
  139. echo "The output was saved here:"
  140. echo -e "Systeminfo -> ${Paths[sys]}"
  141. echo -e "Logs -> ${Paths[log]}"
  142. echo -e "Plot -> ${Paths[plot]}"
  143. }
  144. echo "Collecting INXI output..."
  145. InPut="$(GetINXI)"
  146. [[ -n "${InPut}" ]] && OutPut+="\n### INXI\n\n~~~\n${InPut}\n~~~\n\n"
  147. echo "Collecting System Load Time output..."
  148. InPut="$(GetSystemLoadTime basic)"
  149. [[ -n "${InPut}" ]] && OutPut+="\n### System Load Time\n\n~~~\n${InPut}\n~~~\n\n"
  150. InPut="$(GetSystemLoadTime blame)"
  151. [[ -n "${InPut}" ]] && OutPut+="\n#### Blamed Services\n\n~~~\n${InPut}\n~~~\n\n"
  152. Plot=$(GetSystemLoadTime svg)
  153. echo "Collecting Manjaro Hardware Detection output..."
  154. # Graphics
  155. InPut="$(MHWDGetGPU list)"
  156. [[ -n "${InPut}" ]] && OutPut+="\n### Manjaro Hardware Detection\n\n~~~\n${InPut}\n~~~\n\n"
  157. InPut="$(MHWDGetGPU installed)"
  158. [[ -n "${InPut}" ]] && OutPut+="\n\n~~~\n${InPut}\n~~~\n\n"
  159. # Kernel
  160. InPut="$(MHWDGetKernel list)"
  161. [[ -n "${InPut}" ]] && OutPut+="\n\n~~~\n${InPut}\n~~~\n\n"
  162. InPut="$(MHWDGetKernel installed)"
  163. [[ -n "${InPut}" ]] && OutPut+="\n\n~~~\n${InPut}\n~~~\n\n"
  164. echo "Collecting Blockdevices..."
  165. InPut="$(GetBlockDevices)"
  166. [[ -n "${InPut}" ]] && OutPut+="\n\n### BLOCKDEVICES\n\n~~~\n${InPut}\n~~~\n\n"
  167. echo "Collecting Boot Configuration Files..."
  168. InPut="$(GetBootConfigs)"
  169. [[ -n "${InPut}" ]] && OutPut+="\n\n### Boot Configuration Files\n\n${InPut}\n\n"
  170. Logs=""
  171. echo "Collecting Xorg Logging Files..."
  172. InPut="$(GetXorgLogs)"
  173. [[ -n "${InPut}" ]] && Logs+="\n\n### Xorg Logging Files\n\n${InPut}\n\n"
  174. echo "Collecting System Journals..."
  175. InPut="$(GetSystemJournals current)"
  176. [[ -n "${InPut}" ]] && Logs+="\n\n### System Journals"
  177. [[ -n "${InPut}" ]] && Logs+="\n\n#### Current System Journals\n\n~~~\n${InPut}\n~~~\n\n"
  178. InPut="$(GetSystemJournals previous)"
  179. [[ -n "${InPut}" ]] && Logs+="\n\n#### Previous System Journals\n\n~~~\n${InPut}\n~~~\n\n"
  180. read -p "Would you like to view [v] the content? (View[V]/No[n]) " vn
  181. case $vn in
  182. [Vv]) less -f <(echo -e "${OutPut}${Logs}") ;;
  183. [Nn]) echo -n "" ;;
  184. *) less -f <(echo -e "${OutPut}${Logs}") ;;
  185. esac
  186. read -p "Would you like to upload [u] the content or write it to a file [s]? Save[s]/Upload[U]" us
  187. case $us in
  188. [Uu]) upload ;;
  189. [Ss]) save ;;
  190. *) upload ;;
  191. esac