Advertisement
phillip1882

sysdetails

Oct 31st, 2022
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 81.38 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## MAFoElffen, <mafoelffen@ubuntu.com>, 2021.08.19
  4. ##
  5. ## Contributors:
  6. ## sudodus <nio.wiklund@gmail.com>, 2021.08.25
  7. ## Doug S, 2021.08.22
  8. ## oldfred, 2021.08.20
  9. ## Filename: support-info
  10. ## Description: Report Finds Machine System And Hardware Related Information.
  11. ## Purpose: For support use at "UbuntuForums.org".
  12. #########################################################################
  13. # Copyright (c) 2012, 2021
  14. #
  15. # GNU General Public License (GPL-3.0-or-later)
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. #
  30.  
  31.  
  32. ########################################################################
  33. #### Variables
  34. ########################################################################
  35. # Versioning
  36. version="Version: 02.00-03, Script Date: 2022.10.29"
  37. exit_code=0
  38. #md5_sum=$(md5sum $sname | sed 's/system.*//g' )
  39. arg1=$1
  40. arg2=$2
  41. # Set Report filename and path to
  42. sname="${0##*/}" # flexible, needs quoting everywhere if spaces
  43. report="$HOME/${sname}.txt"
  44. # Get present Locale settings
  45. localectl_status=$(localectl status )
  46. locale_state=$(locale )
  47. LANG_Hx=$LANG
  48. LC_CTYPE_Hx=$LC_CTYPE
  49. # Set locale language settings
  50. LANG=C
  51. LC_CTYPE=C
  52. # Set a pretty ANSI screen decoration for displaying the report onscreen
  53. blueback="\0033[1;37;44m"
  54. redback="\0033[1;37;41m"
  55. faintvid="\0033[2m"
  56. resetvid="\0033[0m"
  57. # Check boot mode
  58. boot_mode=$( [ -d /sys/firmware/efi ] && echo "UEFI Firmware mode" || echo "Legacy mode (alias CSM alias BIOS mode)" )
  59. boot_status=$( [ -d /sys/firmware/efi ] ); # Use boot mode as boolean test
  60. less_status="less"
  61. up_status= "true"
  62. debian_branch=0
  63. # Report timestamp
  64. startt="$(date '+%F %T %Z (%z)')"
  65. # LST Name for package calc
  66. LTS_PKG=""
  67. # variables to keep track of missing programs...
  68. missing_programs=""
  69. check_paster=0
  70. # Variable to track upload status as uploaded
  71. check_paste=1
  72. missing_paster_progs=""
  73. # Variable to add more detail to Report
  74. detail_level='-v'
  75. zfs_detail=1
  76. # Logger settings
  77. # Change verbosity to show level of warnings. Range: -1 through 5. -1 is show nothing.
  78. verbosity=-1
  79. silent_lvl=0
  80. crt_lvl=1
  81. err_lvl=2
  82. wrn_lvl=3
  83. inf_lvl=4
  84. dbg_lvl=5
  85.  
  86. # Trap Control-C
  87. stty -echoctl # hide ^C
  88. trap 'other_commands' SIGINT
  89.  
  90. # 'Trap Section' to clean up Temporary Files on unexpected EXIT's
  91. trap "rm -f $manually_installed" EXIT 2> /dev/null
  92. trap "rm -f $default_installed" EXIT 2> /dev/null
  93. trap "rm -f $user_installed" EXIT 2> /dev/null
  94. trap "rm -f $ssh_data" EXIT 2> /dev/null
  95. trap "ResetLocale" EXIT 2> /dev/null
  96.  
  97. ########################################################################
  98. #### Functions:
  99. ########################################################################
  100. function other_commands()
  101. {
  102. tput setaf 1
  103. printf "You can 'not' exit this script by pressing Control-C..."
  104. tput sgr0
  105. printf "Continue with last 'asked' input..."
  106. }
  107.  
  108. function CheckRoot()
  109. {
  110. clear -x;
  111. ## Check if ran as root. Runs at startup. Called by Main()
  112. if [[ "$EUID" == 0 ]] || [ $UID -eq 0 ]
  113. then
  114. echo -e "$redback Do not run this script with sudo or as root$resetvid"
  115. echo -e "If your Linux ditribution installs with only a Root User as a default, "
  116. echo -e "please create another User that has the ability to run elevated commands. "
  117. PassPhrase
  118. #exit_code=106
  119. #exit $exit_code
  120. echo -e "Running Script: ${sname} $version"
  121. else
  122. echo -e "This script needs some parts of it to run with elevated permissions."
  123. nl
  124. ## Check if 'sudo' is installed...
  125. if type sudo > /dev/null 2> /dev/null
  126. then
  127. echo -e "Please enter your password for that to happen."
  128. sudo -k # revoke previously cached sudo password
  129. if sudo true
  130. then
  131. echo -e "Running Script: ${sname} $version"
  132. else
  133. echo -e "$redback ----------- This script is made to use 'sudo' ----------- $resetvid"
  134. echo -e "$redback ---- Password was incorrect for sudo elevated rights. --- $resetvid"
  135. PassPhrase
  136. echo -e "Continuing to run the script, but: Expect errors. "
  137. fi
  138. else
  139. echo -e "$redback ----------- This script is made to use 'sudo' ----------- $resetvid"
  140. echo -e "$redback This system does not have 'sudo' installed. $resetvid"
  141. echo -e "$redback If you install 'sudo' you will get much more information. $resetvid"
  142. Pause
  143. echo -e "Running Script: ${sname} $version"
  144. fi
  145. fi
  146. }
  147.  
  148. function CheckArgs()
  149. {
  150. # Version or Help Panel. Called by Main().
  151. if [[ "$arg1" == "-v" ]]
  152. then
  153. # Versioning: At the commandline: [<ScriptName> -v] returns <VersionInfo>, then exits.
  154. echo -e "$version";
  155. ResetLocale
  156. exit;
  157. elif [[ "$arg1" == "-h" ]] || [[ "$arg1" == "--help" ]]
  158. then
  159. # Help Panel: At the commandline: [<ScriptName> -h or --help] returns this usage panel, then exits.
  160. echo "Running Script: ${sname} $version"
  161. echo -e "md5sum: "$(md5sum ${sname} | sed 's/system.*//g' )
  162. nl
  163. echo -e "Description: The Ubuntu Forums \"system-info\" script queries the users "
  164. echo -e "computer and prepares a report, so that Ubuntu Forums Community Members "
  165. echo -e "can see what they are recommending solutions for."
  166. nl
  167. echo -e "Usage: ./${sname} <option> "
  168. nl
  169. echo -e "Options: "
  170. echo -e " -v Returns Version Information and exits."
  171. echo -e " -h or --help Displays this Help Screen, then exits."
  172. echo -e " -s # or --show # Changes Verbosity levels of the logger."
  173. echo -e " # range 0 through 5"
  174. echo -e " Example: system-info -s 5 turns on debugging messages"
  175. echo -e " -d or --details Displays more details to Report"
  176. echo -e " Adds more details to GPU,Storage Controller, Sound devices, "
  177. echo -e " and ZFS (if installed)."
  178. nl
  179. echo -e "Parts of the script need elevated permissions (sudo) to get the correct "
  180. echo -e "information from your system, while other parts do not. We have "
  181. echo -e "determined where that needs to be used and when not. While the script is "
  182. echo -e "running, you will be asked to enter your userID's password."
  183. nl
  184. echo -e "It then asks the user 2 questions to describe the problem they are having, "
  185. echo -e "then creates ${sname}.txt in their Home directory."
  186. nl
  187. echo -e "Will check programs used by this script, and give the user the option to "
  188. echo -e "quit to install anything it finds missing. Will give the user the option "
  189. echo -e "to upload the report to a pastebin and displays the URL of that to add "
  190. echo -e "their post on Ubuntu Forums."
  191. nl
  192. echo -e "Or they can manually paste the report within code tags in a post or to a "
  193. echo -e "pastebin. Or added as a text attachment to a post."
  194. nl
  195. echo -e "We have tried to keep this safe and simple to use."
  196. ResetLocale
  197. exit;
  198. elif [[ "$arg1" == "-s" ]] || [[ "$arg1" == "--show" ]]
  199. then
  200. if [ $arg2 -ge -1 ] && [ $arg2 -le 5 ]
  201. then
  202. verbosity=$arg2
  203. else
  204. echo -e "Startup Option out of range."
  205. ResetLocale
  206. exit_code=1
  207. exit $exit_code;
  208. fi
  209. elif [[ "$arg1" == "-d" ]] || [[ "$arg1" == "--details" ]]
  210. then
  211. detail_level='-vv'
  212. zfs_detail=0
  213. fi
  214. }
  215.  
  216. function ResetLocale() {
  217. LANG=$LANG_Hx
  218. LC_CTYPE=$LC_CTYPE_Hx
  219. }
  220.  
  221. function CheckTypeError() {
  222. type -a type > /dev/null 2>&1
  223. TypeError=$?
  224. if [[ "$TypeError" == "1" ]]
  225. then
  226. echo -e "The 'type' command is not found as an internal builtin command on this "
  227. echo -e "system. Cannot check for prerequisite Linux utilities used in this script."
  228. echo -e "This script will run, but may display some errors."
  229. nl
  230. fi
  231. unset -v TypeError
  232. }
  233.  
  234. function CheckDebianBranch()
  235. {
  236. # Check if OS is in Debian Branch
  237. # var debian_branch is global
  238. if [ -f /etc/debian_version ]
  239. then
  240. debian_branch=0
  241. else
  242. debian_branch=1
  243. fi
  244. debug "CheckDebianBranch(). Value: $debian_branch" 1
  245. }
  246.  
  247. function CheckUbuntuFlavor()
  248. {
  249. # Check if OS is an Ubuntu Flavor
  250. ubuntu_found=$(grep -m 1 -Ei 'untu' /etc/*release)
  251. #echo -e "${#ubuntu_found[@]}"
  252.  
  253. if [[ "$ubuntu_found" == *"untu"* ]]
  254. then
  255. ubuntu_flavor=0
  256. else
  257. ubuntu_flavor=1
  258. fi
  259. debug "CheckUbuntuFlavor(). Value: $ubuntu_found" 1
  260. # var ubuntu_flavor is global
  261. unset -v ubuntu_found
  262. }
  263.  
  264. function GetReleaseDescription()
  265. {
  266. # Retrieve 'Release Description' from a Linux Operating System
  267. # As an alternative to: echo -e "The current release description is: ${setansi} $(lsb_release -sd) $ransi"
  268. # Called from GetOtherDetails()
  269.  
  270. if [[ "$check_lsb_release" == "0" ]]
  271. then
  272. os_name=$(lsb_release -sd)
  273. debug "Got release description from 'lsb_release'." 1
  274. else
  275. # Parse through the (possibly) many release file candidates to retrieve the answer...
  276. os_name=$(grep -m 1 'PRETTY_NAME|DISTRIB_DESCRIPTION' /etc/*release | \
  277. sed 's/\/etc\/.*release://g' | \
  278. sed -e 's/[Pp][Rr][Ee][Tt][Tt][Yy]_[Nn][Aa][Mm][Ee]=//g' \
  279. -e 's/[D,d][E,e][S.s][C,c][R,r][I,i][P,p][T,t][I,i][O,o][Nn]=//g' | \
  280. sed 's/\"//g')
  281. nl
  282. debug "Got release description from 'release' file" 1
  283. fi
  284.  
  285. echo -e " --- Operating System Release Description --- "
  286.  
  287. if [[ "$os_name" == "" ]]
  288. then
  289. echo -e "There was a problem determining the Release Description... "
  290. echo -e "Here is the raw outout of the release file(s) to determine manually:"
  291. grep --color=never '=' /etc/*release
  292. debug "GetReleaseDescription(). Dumped release file info. Condition failed." 1
  293. else
  294. echo -e "The current release description is: ${setansi} $os_name $ransi"
  295. fi
  296.  
  297. nl
  298. unset -v os_name
  299. }
  300.  
  301. function CheckPrerequisites()
  302. {
  303. ## Check if all necessary programs are available. Called once by Main().
  304. # Programs that are in /bin or /usr/bin.
  305. Programs='
  306. sudo
  307. cat
  308. grep
  309. awk
  310. free
  311. gsettings
  312. gzip
  313. tar
  314. md5sum
  315. mokutil
  316. curl
  317. pastebinit
  318. ubuntu-drivers
  319. comm
  320. dpkg
  321. nc
  322. wget
  323. ls
  324. lshw
  325. lspci
  326. lsb_release
  327. stat
  328. stdbuf
  329. rm
  330. sed
  331. ping
  332. id
  333. hostname
  334. hostnamectl
  335. pstree
  336. lsblk
  337. lsusb
  338. sleep
  339. sort
  340. mktemp
  341. whoami
  342. who'
  343.  
  344. # Programs that are in /usr/sbin or /sbin.
  345. Programs_SBIN='
  346. fdisk
  347. ip'
  348.  
  349. # Programs that are in /usr/snap/bin.
  350. Programs_SnapBin='
  351. curl'
  352.  
  353. check_prog=1; # global scope
  354. check_mokutil=1; # global scope
  355. check_lshw=0; # global scope
  356. check_lsb_release=0; # global scope
  357. check_hostname=0; # global scope
  358.  
  359. CheckDebianBranch
  360. CheckUbuntuFlavor
  361.  
  362. for Program in ${Programs} ${Programs_SBIN}
  363. do
  364. if [ $(type ${Program} > /dev/null 2>&1 ; echo $?) -ne 0 ]
  365. then
  366. ## Added to check if a program is not in bin or sbin, but might be present in Snap
  367. # I might have to replicate this for Flatpak(?)
  368. # Renamed variable $Program in this stub here to ProgramSof (for "Program: Snap Or Flatpak".
  369. for ProgramSoF in ${Programs_SnapBin}
  370. do
  371. snap_test=$(snap list $ProgramSof 2>&1 )
  372. snap_exit=$?
  373. flatpak_test=$(flatpak list $ProgramSof 2>&1 )
  374. flatpak_exit=$?
  375.  
  376. ## This first part is more generic code for future things moved to the Snap Store...
  377. #if [[ "$snap_test" != *"no matching snaps installed"* ]] || [ $snap_exit -eq 0 ]
  378. #then
  379. # check_prog=0;
  380. # debug "$ProgramSoF found in Snap" 1
  381. #elif [[ "$flatpak_test 2>&1 )" != "no matching flatpaks installed" ]] || [ $flatpak_exit -eq 0 ]
  382. #then
  383. # check_prog=0
  384. # debug "$ProgramSoF found in FlatPak" 1
  385. #else
  386. # debug "$ProgramSoF not found in an Alternative Package Store" 1
  387. #fi
  388. ##
  389.  
  390. # This part is just for now, where 'curl' might be from Snap
  391. if [[ "$ProgramSoF" == "curl" ]]
  392. then
  393. if [ -e /usr/bin/curl ] || [ -e /snap/bin/curl ]
  394. then
  395. check_prog=0
  396. debug "'curl' was found in either /usr/bin or /snap/bin" 1
  397. elif [ $snap_exit -eq 0 ]
  398. then
  399. check_prog=0
  400. debug "'curl' found in Snap" 1
  401. elif [ $flatpak_exit -eq 0 ]
  402. then
  403. check_prog=0
  404. debug "'curl' found in Flatpak" 1
  405. else
  406. check_prog=1
  407. debug "'curl' was not found in either /usr/bin or /snap/bin" 1
  408. fi
  409. fi
  410. done
  411. ## Cleanup Local Variables
  412. unset -v snap_test snap_exit flatpak_test flatpak_exit ProgramSoF Programs_SBIN
  413.  
  414. if [[ "$check_prog" == "1" ]]
  415. then
  416. echo -e " --- Some Programs This Script Uses Were Missing --- "
  417. fi
  418. if [[ "$Program" == "mokutil" ]]
  419. then # If not 'Here' condition
  420. # If this missing, it is a variant for UEFI systems only. It does work on 18.04 where it was not default yet, and is
  421. # a useful option to see if there "is" a SecureBoot option in the BIOS, besides just what it is set at. This, during
  422. # tests, is safe to install on Legacy Only BIOS systems and can be used to tell if the BIOS is such.
  423. echo -e "$faintvid \"${Program}\" Could not be found. This program is suggested.$resetvid"
  424. echo -e "$faintvid If this is older hardware that is 'Legacy Only BIOS', then this can be $resetvid"
  425. echo -e "$faintvid ignored. The report will still run without it. It will just not be able $resetvid"
  426. echo -e "$faintvid to answer one question. $resetvid"
  427. check_mokutil=0; # Set Flag to false and recheck in GetSb()
  428. check_prog=0;
  429. missing_programs="$missing_programs\n$Program"
  430. debug "'$Program' is not installed" 1
  431. elif [[ "$Program" == "pastebinit" ]] || [[ "$Program" == "wget" ]] || [[ "$Program" == "curl" ]] || [[ "$Program" == "nc" ]]
  432. then
  433. check_prog=0;
  434. check_paster=$((check_paster+1));
  435. missing_paster_progs="$missing_paster_progs$Program, "
  436. missing_programs="$missing_programs\n$Program"
  437. # To take care of a permissions check issue on Debian, 2022.06.15
  438. elif [[ "$Program" == "fdisk" ]]
  439. then
  440. #LSB_ID=$(lsb_release -si)
  441. if [[ "$debian_branch" == "0" ]]
  442. then
  443. # Set Debian as an exception
  444. check_prog=0;
  445. debug "System is Debian, 'fdisk'" 1
  446. fi
  447. if [ -e /sbin/fdisk ]
  448. then
  449. check_prog=0
  450. debug "'fdisk' is in /sbin" 1
  451. fi
  452. elif [[ "$Program" == "ip" ]]
  453. then
  454. # For Slackware
  455. if [ -e /sbin/ip ]
  456. then
  457. check_prog=0
  458. debug "'ip' is in /sbin" 1
  459. fi
  460. elif [[ "$Program" == "lspci" ]]
  461. then
  462. # For Slackware. lspci is in /sbin, instead of /bin
  463. if [ -e /bin/lspci ]
  464. then
  465. #lspci_cmd="/bin/lspci"
  466. check_prog=0
  467. debug "'lspci' is in /bin" 1
  468. elif [ -e /sbin/lspci ]
  469. then
  470. #lspci_cmd="/sbin/lspci"
  471. check_prog=0
  472. debug "'lspci' is in /sbin" 1
  473. else
  474. #lspci_cmd="lspci"
  475. debug "'lspci' was not found." 1
  476. fi
  477. elif [[ "$Program" == "lsb_release" ]]
  478. then
  479. # CHANGE - Do not assume all Debian Branch uses 'lsb_release'...
  480. # If 'lsb_release' does not exist, then set flag for it.
  481. # Set/call alternate methods to retrieve System Description information
  482. ## GetReleaseDescription() Modified for this
  483. #check_prog=0;
  484. check_lsb_release=1
  485. debug "Utility 'lsb_release' is not here" 1
  486. elif [[ "$Program" == "hostname" ]]
  487. then
  488. if [ -e /usr/bin/hostnamectl ]
  489. then
  490. check_prog=0
  491. check_hostname=1
  492. else
  493. check_hostname=2
  494. debug "Both 'hostname' and 'hostnamectl' where not found." 1
  495. fi
  496. elif [[ "$Program" == "ubuntu-drivers" ]]
  497. then
  498. # Check if it is Ubuntu Flavor, else not needed
  499. if [[ "$ubuntu_flavor" == "1" ]]
  500. then
  501. check_prog=0;
  502. echo -e "'ubuntu-drivers' is not installed, but is not an Ubuntu Flavor, so ignore."
  503. fi
  504. elif [[ "$Program" == "dpkg" ]]
  505. then
  506. # Check if Debian Branch, else not needed
  507. if [[ "$debian_branch" == "1" ]]
  508. then
  509. check_prog=0;
  510. echo -e "'dpkg' is not installed, but ignore, as this is not a Debian Branch."
  511. fi
  512. elif [[ "$Program" == "lshw" ]]
  513. then
  514. check_lshw=1
  515. check_prog=0;
  516. echo -e "'lshw' is not installed, but will run with less details."
  517. else
  518. echo -e "'$Program' is not installed."
  519. check_prog=0;
  520. missing_programs="$missing_programs\n$Program"
  521. fi
  522. fi
  523. done
  524.  
  525. if [ "$check_prog" == 0 ]
  526. then
  527. echo -e " -------------------------------- "
  528. nl
  529. echo -e "The Script 'system-info' uses some very basic Linux utilities. "
  530. echo -e "Some of these utilities were not found."
  531. nl
  532. echo -e "The report will still run without them. It will just not answer related "
  533. echo -e "questions. Some of that information may be related to the diagnosis of "
  534. echo -e "your installed system. If missing utilities may have answered your "
  535. echo -e "specified problem, you may be asked by a 'Ubuntu Forums Member' supporting "
  536. echo -e "you if a program was missing, and if you could install it to answer that "
  537. echo -e "related question."
  538. nl
  539. CheckPaster
  540. echo -e "Some of these utilities are not default installed utilities to all Editions, "
  541. echo -e "versions, and flavors of Ubuntu... So may be considered as optional. "
  542. nl
  543.  
  544. ans=
  545. while [ "$ans" != "e" ] && [ "$ans" != "E" ] && [ "$ans" != "c" ] && [ "$ans" != "C" ]
  546. do
  547. read -erp "<E>xit and install the program(s) or <C>ontinue anyway? <E/C> " ans
  548. ans="${ans,}"
  549. debug "User answered $ans" 1
  550. if [[ $ans =~ ^[Ee]$ ]]
  551. then
  552. echo -e "Please install the missing programs listed above before rerunning script."
  553. debug "User choose to exit after missing programs." 1
  554. ResetLocale
  555. exit_code=0
  556. exit $exit_code
  557. elif [[ ${ans,} =~ ^[Cc]$ ]]
  558. then
  559. echo -e "Some task(s) will not work, but I'll do the best possible, continuing ..."
  560. debug "User choose to continue while missing some programs." 1
  561. sleep 1
  562. fi
  563. done
  564. else
  565. echo -e "All required programs installed..."
  566. sleep 1
  567. fi
  568. }
  569.  
  570. function CheckPaster() {
  571. if [ $check_paster -eq 4 ]
  572. then
  573. echo -e "Programs 'pastebinit', 'curl', 'wget', and 'nc' are missing. "
  574. echo -e "All 4 utilities used to upload this report to a PasteBin are missing."
  575. echo -e "The report will still run. If not installed, you would just need to "
  576. echo -e "paste the report into a post, contained within 'CODE' Tags."
  577. nl
  578. fi
  579. if [ $check_paster -le 3 -a $check_paster -ge 1 ]
  580. then
  581. echo -e "Program(s) $missing_paster_progs is/are missing, "
  582. echo -e "but can be ignored as there still are installed utilities present to "
  583. echo -e "to be able to upload the report to an online PasteBin."
  584. nl
  585. fi
  586. }
  587.  
  588. function ProcessMissingPrograms() {
  589. echo -e "---- Required Programs For Report."
  590. if [[ "$missing_programs" == "" ]]
  591. then
  592. echo -e " All required programs installed for report. "
  593. nl
  594. else
  595. echo -e " --- Some Programs This Script Uses Were Missing --- "
  596. echo -e "$missing_programs" | awk 'NF && !/^(start|#)/ {print " " $0}'
  597. nl
  598. fi
  599. }
  600.  
  601. function RmOldReport()
  602. {
  603. # Removes the old report. Called once by Main().
  604. /bin/rm -f "$report"
  605. exit_code=$?
  606. debug "Remove old report. Exit code: $exit_code" 1
  607. }
  608.  
  609. function UserInput()
  610. {
  611. # Gather User Information on the problem. Called once by Main()
  612. # User Input for Problem and Description
  613. # Format input
  614. width=$(tput cols)
  615. str=
  616. for ((i=1; i<=$width; i++))
  617. do
  618. str="${str}_"
  619. done
  620. #echo -e "$str"
  621. nl
  622. echo -e "Please provide some \"Basic Information\"..."
  623. read -erp "What is the Main Complaint (summarized)? " main_complaint
  624. read -erp "Describe the Problem: " problem_description
  625. clear -x
  626. unset -v i cols width str
  627. }
  628.  
  629. function GetMachineInfo()
  630. {
  631. # Gets Computer Information. Called once by Writer().
  632. GetCPU
  633. GetDmi
  634. GetMem
  635. GetSwap
  636. GetNetworkingInfo
  637. GetHostname
  638. nl
  639. }
  640.  
  641. function GetCPU()
  642. {
  643. # Gets CPU Information. Called once by GetMachineInfo().
  644. echo -e "${setansi}---------- General Computer Specifications:$ransi"
  645. nl
  646. # Do not call $lshw_cmd if 'lshw' is not installed...
  647. if [[ "$check_lshw" == "0" ]]
  648. then
  649. echo -e " --- Computer/CPU Information from 'lshw -C cpu' --- "
  650. $lshw_cmd -C cpu \
  651. | sed -r '/^ *([a-z])/ s/([a-zA-Z])/\u&/' \
  652. | sed -e 's/^ *\*-cpu/\*-Cpu/g' \
  653. | sed '/Capabilities/ s/ *Capabilities/ Capabilities/' \
  654. | fold -sw 71 \
  655. |sed -e 's/^[^ ]/ &/' \
  656. -e 's/ *\*-Cpu/\*-Cpu/g' \
  657. -e 's/ Capabilities/ Capabilities/' \
  658. -e 's/ / /' \
  659. -e '/Capabilities/ s/^[^ ]/ &/'
  660. nl
  661. $lshw_cmd \
  662. | sed '/*-core/,$ d' \
  663. | sed -r '/^ *([a-z])/ s/([a-zA-Z])/\u&/' \
  664. | sed -e 's/ *Configuration/ Configuration/' \
  665. -e '/Configuration/ s/ [^ ]*=[^ ]*/\n&/g' \
  666. -e 's/Configuration/ Configuration/' \
  667. | sed 's/^ [^ ]/ &/'
  668. nl
  669. else
  670. echo -e " --- Computer/CPU Information from '/proc/cpuinfo' --- "
  671. grep -m 1 -Ei 'model name' /proc/cpuinfo | sed 's/model name.*:.//g'
  672. nl
  673. fi
  674. }
  675.  
  676. function FixNonAsciiVar() {
  677. # Call format to this function is: FixNonAsciiVar <var_name> <var_content>
  678. VarName=$1 # Local Var
  679. VarContent=$2 # Global Var
  680.  
  681. # Check if field contains non ascii characters
  682. # Remember to set whatever the original passed varaible equal to $VarContent after the call
  683. # to catch the fixed return value.
  684. if [[ "$VarContent" == "*[!:ascii:]*" ]]
  685. then
  686. debug "$VarName contains Non-ASCII characters." 1
  687. debug "Content= $VarContent" 1
  688. # Remove non-ascii chars from string
  689. VarContent=$(sed 's/[\d0-\d8,\d11-\d31,\d127-\d255]//g' <<< $VarContent )
  690. debug "Fixed Content: $VarContent" 1
  691. fi
  692. unset $VarName
  693. }
  694.  
  695. function GetDmi()
  696. {
  697. # Checks for SMBIOS compliance and values for. Called once by GetMachineInfo().
  698. # Dynamically checks the dmi_var's and removes them from the array if not present
  699. # to adjust for SMBIOS Standard Version variations.
  700. smbios_compliant="/sys/class/dmi/id/" # local var
  701.  
  702. dmi_vars='bios_vendor
  703. bios_version
  704. bios_release
  705. board_vendor
  706. board_name
  707. board_version
  708. board_serial
  709. board_asset_tag' # local var
  710.  
  711. echo -e "------------------ SMBIOS Information from '/sys/class/dmi/id/' "
  712. debug "SMBIOS Information" 1
  713.  
  714. if [ -d $smbios_compliant ]
  715. then
  716. # Loop through once to verify all the vdi_var files exist first. If not,
  717. # then modify list by removing the file name from the declared array.
  718. dmi_idx=0 # local var for counter
  719. for dmi_var in ${dmi_vars}
  720. do
  721. if [ ! -f $smbios_compliant$dmi_var ]
  722. then
  723. debug "Deleting $dmi_var from array..." 1
  724. dmi_vars=( "${dmi_vars[@]/$dmi_var}" )
  725. fi
  726. dmi_idx+=1
  727. done
  728.  
  729. # Then spin through the modified array to list them
  730. for dmi_var in ${dmi_vars}
  731. do
  732. dmi_content=$(sudo head -n 1 $smbios_compliant$dmi_var | \
  733. sed 's/[\d0-\d8,\d11-\d31,\d127-\d255]//g' )
  734. dmi_title=$(echo $dmi_var | sed -e 's/_/ /g' | sed -e 's/\b\(.\)/\u\1/g' )
  735.  
  736. if [ $dmi_var == "board_version" ]
  737. then
  738. if [[ "$dmi_content" == "1234567890" ]]
  739. then
  740. dmi_content=""
  741. fi
  742. elif [[ "$dmi_content" == *"default "* ]]
  743. then
  744. dmi_content="Value Not Set"
  745. fi
  746. printf "%-20s %s\n" "$dmi_title:" "$dmi_content";
  747. done
  748. else
  749. echo -e "No SMBIOS information found"
  750. fi
  751. nl
  752. printf "%-20s %s\n" "Current boot mode:" "$boot_mode"
  753. GetSb
  754. nl
  755. unset -v dmi_idx dmi_var dmi_vars dmi_content dmi_title
  756. }
  757.  
  758. function GetSb()
  759. {
  760. # Gets SafeBoot Info from UEFI BIOS or if not UEFI capable. Called once by GetDMI().
  761. # Warns user if mokutil was not present.
  762. echo -e " --- SecureBoot Status from 'mokutil':"
  763.  
  764. ## Bug found on some machines concerning the '--sb-state' option switch on 2022.06.01.
  765. # Shortened to '--sb' (undocumented option switch)
  766. # 'mokuitl' Bug was resolved within days...
  767. # 2022.06.02, Added fallack error handling for fallback to alternate option flag...
  768. # using the documented option flag as the primary method.
  769. if [ $check_mokutil -eq 0 ]
  770. then
  771. echo -e "\tThis would check / have checked if SecureBoot was enabled or not, "
  772. echo -e "\tand checks if the system BIOS was UEFI or Lagacy only BIOS, "
  773. echo -e "\tbut package mokutil was not installed. If you would like to check"
  774. echo -e "\tthis information, please install 'mokutil' and rerun script."
  775. else
  776. # Added this error handling because of a bug on a 'mokutil', that was resolved
  777. # but showed that an error was possible from a faulty update of this utility.
  778. error_mokutil=$(mokutil --sb-state 2>&1 )
  779. if [[ "$error_mokutil" == *"mokutil: unrecognized option '--sb-state​'"* ]]
  780. then
  781. mokutil_cmd=$(mokutil --sb 2>&1 )
  782. error_mokutil=$mokutil_cmd
  783. else
  784. mokutil_cmd=$(mokutil --sb-state 2>&1 )
  785. fi
  786. # For Legacy only BIOS, returns error: "EFI variables are not supported on this system"
  787. if [[ "$error_mokutil" == *"EFI variables"* ]]
  788. then
  789. echo -e "$error_mokutil"
  790. elif [[ "$error_mokutil" == *"Command 'mokutil' not found"* ]] #
  791. then
  792. echo -e "\tThis would check / have checked if SecureBoot was enabled or not, "
  793. echo -e "\t and checks if the system BIOS was UEFI or Lagacy only BIOS, "
  794. echo -e "\tbut package mokutil was not installed. If you would like to check"
  795. echo -e "\tthis information, please install 'mokutil' and rerun script."
  796. else
  797. sb_state=$mokutil_cmd
  798. debug "sb_state: $sb_state" 1
  799. if [[ $sb_state == "Failed to read SecureBoot" ]]
  800. then
  801. sb_disabled="SecureBoot: Disabled"
  802. #printf "%-20s %s\n" ${sb_disabled/ /: }
  803. echo -e "$sb_disabled"
  804. else
  805. # These are the known messages returned from mokutil
  806. # This system doesn't support Secure Boot
  807. # Secure Boot is enabled
  808. # Failed to read SecureBoot
  809. # Platform is in Setup Mode
  810. # mokutil: unrecognized option '--sb-state​'
  811. #
  812. #printf "%-20s %s\n" ${sb_state/ /: }
  813. echo -e "$sb_state"
  814. fi
  815. fi
  816. nl
  817. fi
  818. unset -v error_mokutil mokutil_cmd sb_state sb_disabled
  819. }
  820.  
  821. function GetMem()
  822. {
  823. # Gets memory information (pysical and swap). Called once by GetMachineInfo().
  824. echo -e "${setansi}---------- Memory Information:$ransi"
  825. mem_stats=$(free -m)
  826. echo -e "$mem_stats"
  827. nl
  828. unset -v mem_stats
  829. }
  830.  
  831. function GetSwap () {
  832. # Gets more swap information. Called once by GetMachineInfo().
  833. fstab_info=$(grep 'swap' /etc/fstab )
  834. swaps_info=$(awk '{print $0}' /proc/swaps )
  835. sw_proc=$(awk '{print $0}' /proc/sys/vm/swappiness )
  836. sw_sysctl=$(grep 'vm.swappiness' /etc/sysctl.conf )
  837. valid_settings="10 - 60"
  838.  
  839. if [ "$sw_sysctl" == "" ]
  840. then
  841. sw_stsctl="If setting 'vm.swappiness' is not declared in '/etc/systctl', then the system inherits the default setting of '60'."
  842. fi
  843.  
  844. echo -e "${setansi}---------- Swap Information:$ransi"
  845. echo -e " --- Info from 'fstab'"
  846. echo -e "$fstab_info"
  847. nl
  848. echo -e " --- Info from '/proc/swaps'"
  849. echo -e "$swaps_info"
  850. nl
  851. echo -e " --- System Swapiness Settings"
  852. echo -e "Valid swappiness settings are from $valid_settings . "
  853. echo -e "Current setting in '/proc/sys/vm/swappiness': $sw_proc "
  854. echo -e "Current configuration setting in '/etc/sysctl.conf file: "
  855. echo -e "$sw_sysctl"
  856. nl
  857. unset -v fstab_info swaps_info sw_proc sw_sysctl valid_settings
  858. }
  859.  
  860. function GetUsb()
  861. {
  862. # Gets USB information. Called once by Writer().
  863. echo -e "${setansi}---------- USB Information from 'lsusb -t -v':$ransi"
  864. usb_info=$(lsusb -t $detail_level)
  865. echo -e "$usb_info"
  866. nl
  867. unset -v usb_info
  868. }
  869.  
  870. function GetNetworkingInfo()
  871. {
  872. # Gets Networking related Information. Called once by GetMachineInfo().
  873. GetIP
  874. CheckIpUp silent
  875. if [ "$up_status" == "true" ]
  876. then
  877. GetInternetStatus
  878. else
  879. echo -e " --- Internet Connection Status from 'ip addr' --- "
  880. echo -e "Skipped getting Internet Status. Connection: $up_status"
  881. nl
  882. fi
  883. CheckIpUp show
  884. GetMoreWirelessInformation
  885. }
  886.  
  887. function GetInternetStatus()
  888. {
  889. # Verifies ping status and relsolv. Called once by GetNetworkingInfo().
  890. ping -c 1 www.google.com &> /dev/null
  891. pingStatus=$? # Global var
  892. echo -e " --- Internet Connection Status from 'ping [various addresses]' --- "
  893. if [ $pingStatus == 0 ]
  894. then
  895. echo -e "Connected to Internet with DNS"
  896. else
  897. echo -e "Cannot reach internet by DNS"
  898. ping -c 1 8.8.8.8 &> /dev/null
  899. pingStatus=$?
  900. if [ $pingStatus == 0 ]
  901. then
  902. echo -e "Can reach the internet without DNS"
  903. else
  904. echo -e "Cannot reach internet by IP..."
  905. fi
  906. fi
  907. nl
  908. }
  909.  
  910. function GetPingStatus()
  911. {
  912. # Takes arg as IP or URL. Returns pseudo boolean $return_status. Called twice (by Paster() and GetInternetStatus()).
  913. ping -c 1 $1 &> /dev/null
  914. pingStatus=$? # Global Var
  915. if [ $pingStatus == 0 ]
  916. then
  917. return_status="true" # Global Var
  918. else
  919. return_status="false" # Global Var
  920. fi
  921. debug "GetPingStatus(): Value: $return_status" 1
  922. }
  923.  
  924. function GetIP()
  925. {
  926. # Get IP related information. Called once by GetNetworkingInfo().
  927. echo -e "${setansi}---------- IP Address Information:$ransi"
  928. echo -e " --- IP Address Information from 'ip addr' --- "
  929. # Grab IP address information
  930. if [ "$less_status" == "less" ]
  931. then
  932. ip_addr=$(/sbin/ip addr | grep -e '^[[:space:][1-9]:' -e 'inet.') # Local Var
  933. echo -e "$ip_addr"
  934. else
  935. ip_addr=$(/sbin/ip addr | grep -e '^[[:space:][1-9]:' -e 'inet.' \
  936. | sed '/inet\s/ s/inet\s.*/inet [REMOVED]/g' \
  937. | sed '/inet6\s.*/ s/inet6\s.*/inet6 [REMOVED]/g') # Local Var
  938. echo -e "$ip_addr"
  939. fi
  940. unset -v ip_addr
  941. nl
  942. }
  943.  
  944. function CheckIpUp()
  945. {
  946. # Check to see if an exposed network device is up before going out to LAN. Called twice by GetNetworkingInfo()
  947. show_silent=$1 # show or silent. Eval is on: "show" # Global Var
  948. ip_devices_up=$(/sbin/ip addr | \
  949. grep -e '^[[:space:][1-9]:.*UP,LOWER_UP' | \
  950. sed 's/.*virb.*:.*\|.*lo:.*LOOPBACK.*//g' | \
  951. sed -e /^$/d) # Local Var
  952. if [ "$show_silent" == "show" ]
  953. then
  954. echo -e " --- Network Device Status Summary from 'ip addr' --- "
  955. if [ "$ip_devices_up" == "" ]
  956. then
  957. echo -e "No Network Devices up..."
  958. nl
  959. up_status="false"
  960. else
  961. echo -e "These Network Devices are up:"
  962. echo -e "$ip_devices_up"
  963. nl
  964. up_status="true"
  965. fi
  966. elif [ "$show_silent" == "silent" ]
  967. then
  968. if [ "$ip_devices_up" == "" ]
  969. then
  970. up_status="false"
  971. else
  972. up_status="true"
  973. fi
  974. else
  975. debug "'show_silent' call out of range $show_silent" 1
  976. fi
  977. debug "show_silent: $show_silent 'up_status': $up_status" 1
  978. unset -v ip_devices_up
  979. }
  980.  
  981. function GetHostname()
  982. {
  983. # Gets Hostname information. Called once by GetMachineInfo().
  984. # Values for $check_hostname:
  985. # 0 = Use 'hostname'
  986. # 1 = Use 'hostnamectl'
  987. # 2 = 'hostname' and 'hostnamectl' were not found.
  988. # Print alternate message.
  989. if [ $check_hostname -eq 0 ]
  990. then
  991. hostname_long=$(hostname --fqdn) # Local Var
  992. hostname_short=$(hostname | \
  993. sed 's/\..*//g') # Local Var
  994. hostname_title="'hostname --fqdn'" # Local Var
  995. elif [ $check_hostname -eq 1 ]
  996. then
  997. hostname_long=$(hostnamectl --static )
  998. hostname_short=$(hostnamectl --static | \
  999. sed 's/\..*//g')
  1000. hostname_title="'hostnamectl --static'"
  1001. else
  1002. hostname_long="<Could not be determined>"
  1003. hostname_short="<Could not be determined>"
  1004. hostname_title="'hostname'"
  1005. fi
  1006.  
  1007. echo -e " --- Hostname from $hostname_title --- "
  1008. if [ "$less_status" == "less" ]
  1009. then
  1010. host_name=$hostname_long
  1011. else
  1012. host_name=$hostname_short
  1013. fi
  1014. echo -e "The 'Hostname' of the computer system is: $host_name"
  1015. nl
  1016. unset -v hostname_long hostname_short hostname_title host_name
  1017. }
  1018.  
  1019. function GetDiskInfo()
  1020. {
  1021. # Gets filesystem, disk, fstab and mount information. Called once by Writer().
  1022. GetStorageControllers
  1023. echo -e "${setansi}---------- File system specs from 'df -h':$ransi"
  1024. df -hT -x tmpfs -x devtmpfs | grep -v '/snap/'
  1025. nl
  1026. echo -e "${setansi}---------- Disk/Partition Information From 'fdisk':$ransi"
  1027. sudo fdisk -l 2>&1 | sed '/\/dev\/loop/,+3 d' 2> /dev/null | uniq
  1028. nl
  1029. echo -e "${setansi}---------- Disk/Partition Information From 'lsblk':$ransi"
  1030. # Note: sed replacement added to switch out non-ascii charaters of 'lsblk'.
  1031. # 'paste.ubuntu.com' does not accept non-ascii characters
  1032. lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT,MODEL | grep -v '/snap/' | sed 's/^[\|,`]-/\|_/g'
  1033. echo -e " ------- 'lsblk' information continued ..."
  1034. lsblk -o NAME,HOTPLUG,PARTUUID,UUID | grep -v 'loop' | sed 's/^[\|,`]-/\|_/g'
  1035. nl
  1036. GetZfsInfo
  1037. GetLuksInfo
  1038. echo -e "${setansi}---------- Mount Details of '/etc/fstab':$ransi"
  1039. grep -E -v '#' /etc/fstab
  1040. nl
  1041. GetMountInfo
  1042. GetMoreDiskInfo
  1043. }
  1044.  
  1045. function GetMoreDiskInfo() {
  1046. echo -e "For more detailed disk Information, please run the 'boot-info' script "
  1047. echo -e "from: (STABLE) https://launchpad.net/~yannubuntu/+archive/ubuntu/boot-repair "
  1048. nl
  1049. }
  1050.  
  1051. function GetMoreAlsaInformation() {
  1052. echo -e "For more detailed audio information, get and run the script at: http://www.alsa-project.org/alsa-info.sh "
  1053. nl
  1054. }
  1055.  
  1056. function GetMoreWirelessInformation() {
  1057. echo -e "For more detailed wireless information, get and run the script at https://github.com/UbuntuForums/wireless-info "
  1058. nl
  1059. }
  1060.  
  1061. GetMountInfo()
  1062. {
  1063. mount_info=$(mount | grep '^/dev' | sort) # local var
  1064.  
  1065. if [ "$mount_info" == "" ]
  1066. then
  1067. mount_info=$(mount)
  1068. fi
  1069. echo -e "${setansi}---------- Current Mount Details of 'mount':$ransi"
  1070. echo -e "$mount_info"
  1071. nl
  1072. unset -v mount_info
  1073. }
  1074.  
  1075. function GetZfsInfo()
  1076. {
  1077. zfs_part_type=$(sudo fdisk -l 2>&1 | \
  1078. sed '/\/dev\/loop/,+3 d' 2> /dev/null | \
  1079. uniq | grep -m 1 'Solaris root\|Solaris boot' ) # Local Var
  1080. zfs_fs_type=$(df -hT -x tmpfs -x devtmpfs | \
  1081. grep -v '/snap/' | \
  1082. grep -m 1 'rpool') # Local Var
  1083.  
  1084. if [[ "$zfs_part_type" != "" ]]
  1085. then
  1086. echo -e "${setansi}---------- ZFS Information:$ransi"
  1087. echo -e "System has at least one ZFS type partition."
  1088. nl
  1089. if [[ "$zfs_fs_type" != "" ]]
  1090. then
  1091. echo -e "System has ZFS rpools activated."
  1092. nl
  1093. if [ $zfs_detail -eq 0 ]
  1094. then
  1095. # Shown only if --details or -d option is used
  1096. zfs list
  1097. nl
  1098. zpool list
  1099. nl
  1100. else
  1101. echo -e "If you restart the script adding a '-d' startup option, it will show more details."
  1102. nl
  1103. fi
  1104. else
  1105. echo -e "System has no ZFS rpools activated."
  1106. fi
  1107. nl
  1108. fi
  1109. unset -v zfs_part_type zfs_fs_type
  1110. }
  1111.  
  1112. function GetLuksInfo()
  1113. {
  1114. luks_fs_type=$(lsblk -o NAME,FSTYPE | \
  1115. grep -m 1 'crypto_LUKS' )
  1116. if [[ "$luks_fs_type" != "" ]]
  1117. then
  1118. echo -e "${setansi}---------- LUKS Information:$ransi"
  1119. echo -e "System has a LUKS encrypted filesystem."
  1120. nl
  1121. fi
  1122. unset -v luks_fs_type
  1123. }
  1124.  
  1125.  
  1126. function GetStorageControllers() {
  1127. # Based on this information:
  1128. # lspci | grep --color=never -i -e 'IDE controller' -e 'SATA controller' -e 'SCSI controller' -e 'Non-Volatile memory controller' -e 'RAID Controller'
  1129. echo -e "${setansi}---------- Storage Controller Information From 'lspci':$ransi"
  1130. cntrllr_busid_list=$(sudo -i lspci | \
  1131. grep --color=never -i -e 'IDE ' \
  1132. -e 'SATA ' \
  1133. -e 'SCSI ' \
  1134. -e 'Non-Volatile memory ' \
  1135. -e 'RAID ' | \
  1136. awk '{print $1}') # Local Var
  1137. # Modified for devices which have no formal storage controllers besides USB or SD
  1138. if [ ! -z "$cntrllr_busid_list" ]
  1139. then
  1140. # Parse through list (array) and show detailed information on each
  1141. for controller in ${cntrllr_busid_list}
  1142. do
  1143. sudo -i lspci -s $controller $detail_level
  1144. nl
  1145. done
  1146. else
  1147. echo -e "No storage controller found. Check in 'lsusb' section."
  1148. echo -e "May be USB or SD storage."
  1149. nl
  1150. fi
  1151. unset -v controller cntrllr_busid_list
  1152. }
  1153.  
  1154. function GetGraphicsEnv()
  1155. {
  1156. # Gets Graphics Layer Information. Called once by Writer().
  1157. # Do not call $lshw_cmd if lshw is not installed...
  1158. if [[ "$check_lshw" == "0" ]] && [[ "$detail_level" == "-v" ]]
  1159. then
  1160.  
  1161. echo -e "${setansi}---------- Video Details from 'lshw':$ransi"
  1162. nl
  1163. #lshw_data=$(sudo lshw -C video )
  1164. lshw_data=$(sudo lshw -C video \
  1165. | sed -e 's/ *resources/resources/' \
  1166. -e '/resources/ s/ [^ ]*:[^ ]*/ \n&/g' \
  1167. -e 's/resources:/ resources:/g' \
  1168. | sed 's/^ [^ ]/ &/' )
  1169.  
  1170. if [ "$lshw_data" == "" ]
  1171. then
  1172. echo -e "No conventional GPU detected. May be using a Frame Buffer."
  1173. else
  1174. echo -e "$lshw_data"
  1175. fi
  1176. nl
  1177. else
  1178. # Use alternate method to display GPU info
  1179. echo -e "${setansi}---------- Video Details from 'lspci':$ransi"
  1180. #lspci | grep -i vga | sed 's/[0-9][0-9]:[0-9][0-9]\.[0-9] //g'
  1181. gpu_list=$(sudo -i lspci | \
  1182. grep --color=never -i -e 'VGA' | \
  1183. awk '{print $1}')
  1184. # Modified for devices which have no formal GPU's
  1185. if [ ! -z "$gpu_list" ]
  1186. then
  1187. # Parse through list )array) and show detailed information on each
  1188. for gpu in ${gpu_list}
  1189. do
  1190. sudo -i lspci -s $gpu $detail_level
  1191. nl
  1192. done
  1193. else
  1194. echo -e "No formal GPU found. Check in other places for a framebuffer."
  1195. nl
  1196. fi
  1197. unset -v gpu_list
  1198. fi
  1199. echo -e " --- Graphics Environment Continued from 'various graphics ENVs' ----"
  1200. if [ "$XDG_CURRENT_DESKTOP" != "" ]
  1201. then
  1202. echo -e "The Current Configured Destop is: $XDG_CURRENT_DESKTOP "
  1203. else
  1204. echo -e "The Current Configured Desktop is: <Not Populated> "
  1205. fi
  1206. if [ "$DESKTOP_SESSION" != "" ]
  1207. then
  1208. echo -e "The Current Desktop Session is: $DESKTOP_SESSION "
  1209. if [[ "$detail_level" == "-v" ]]
  1210. then
  1211. xmode=$(xrandr -q 2> /dev/null | \
  1212. grep -E --color=never -e 'Screen' -e 'connected ')
  1213. else
  1214. xmode=$(xrandr -q 2> /dev/null )
  1215. fi
  1216. echo -e "The Current X Desktop Information Details from 'xrandr' are: "
  1217. echo -e "$xmode"
  1218. else
  1219. echo -e "The Current Desktop Session is: <Not Populated> "
  1220. fi
  1221. unset -v xmode
  1222.  
  1223. if [ "$XDG_SESSION_TYPE" != "" ]
  1224. then
  1225. echo -e "The Current Session Type is: $XDG_SESSION_TYPE "
  1226. else
  1227. session_type=$(ps -e | \
  1228. grep -E -e 'tty' | \
  1229. grep -E -e 'x11|Xorg|wayland' | \
  1230. awk '{print $4}')
  1231. if [ "$session_type" != "" ]
  1232. then
  1233. echo -e "The Current Session Type is: $session_type "
  1234. else
  1235. echo -e "The Current Session Type is: <No Graphics Session Type Loaded> "
  1236. fi
  1237. fi
  1238. unset -v session_type
  1239.  
  1240. if [ -f /etc/X11/default-display-manager ]
  1241. then
  1242. display_manager=$(grep -E -e '/usr/sbin/' /etc/X11/default-display-manager | \
  1243. sed 's/\/usr\/sbin\///g')
  1244. echo "The Current Display Manager is: $display_manager"
  1245. else
  1246. echo "The Current Display Manager is: <Not Configured>"
  1247. fi
  1248. unset -v display_manager
  1249.  
  1250. # This change is to adapt to Server Edition, which for some reason, can have a gsettings setting.
  1251. get_console_desktop=$([ -d /usr/share/xsessions/ ] && \
  1252. echo "Desktop" || \
  1253. echo "Console") # Local Var
  1254. if [ "$get_console_desktop" == "Desktop" ]
  1255. then
  1256. desktop_theme=$(gsettings get org.gnome.desktop.interface gtk-theme) # Local Var
  1257. if [ "$desktop_theme" != "" ]
  1258. then
  1259. echo -e "The Current Desktop Theme: $desktop_theme"
  1260. else
  1261. echo -e "The Current Desktop Theme: <None Configured>"
  1262. fi
  1263. else
  1264. echo -e "The Current Desktop Theme: Is not set, this is Console Based."
  1265. fi
  1266. unset -v get_console_desktop desktop_theme
  1267.  
  1268. virt_ttys=$(ps -e | \
  1269. awk '$2 ~ /^tty/ || $2 ~ /^ttyS/ || $2 ~ /^pts/ {print "\t" $2 "\t" $4}') # Local Var
  1270. echo -e "The Current Virtual TTY's being used are:"
  1271. echo -e "\tTTY#\tUsed By"
  1272. echo -e "$virt_ttys"
  1273. unset -v virt_ttys
  1274. nl
  1275. }
  1276.  
  1277. function GetSoundDevices() {
  1278. # Retreive Sound device ID's
  1279. echo -e "${setansi}---------- Sound Device Information From 'lspci':$ransi"
  1280. sound_device_list=$(sudo -i lspci | \
  1281. grep --color=never -i -e 'audio ' | \
  1282. awk '{print $1}') # Local Var
  1283. # Make sure not NULL
  1284. if [ ! -z "$sound_device_list" ]
  1285. then
  1286. # Parse through list (array) and show detailed information on each
  1287. for sound_device in ${sound_device_list}
  1288. do
  1289. sudo -i lspci -s $sound_device $detail_level
  1290. nl
  1291. done
  1292. else
  1293. echo -e "No sound devices found. Also check in 'lsusb' section."
  1294. nl
  1295. fi
  1296. if [[ "$detail_level" == "-vv" ]]
  1297. then
  1298. # Only displays in detailed mode
  1299. echo -e " --- More Sound Device info from 'aplay' ----"
  1300. aplay --list-devices --list-pcms
  1301. nl
  1302. fi
  1303. GetMoreAlsaInformation
  1304.  
  1305. unset -v sound_device sound_device_list
  1306. }
  1307.  
  1308. function GetKeyMap() {
  1309. echo -e "${setansi}---------- KeyMap and Locale Information from from various sources:$ransi"
  1310.  
  1311. # setxkbmap & xset are part of package 'x11-xserver-utils', not installed if no xserver present.
  1312. # In Ubuntu: /etc/default/... cfg are keyboard and locale files
  1313. get_console_desktop=$([ -d /usr/share/xsessions/ ] && \
  1314. echo "Desktop" || \
  1315. echo "Console") # Local Var
  1316. if [ "$get_console_desktop" == "Desktop" ]
  1317. then
  1318. echo -e " --- Keymap Info from 'setxkbmap' ----"
  1319. setxkbmap -query 2> /dev/null
  1320. nl
  1321. if [[ "$detail_level" == "-vv" ]]
  1322. then
  1323. echo -e " --- More Keymap Info from 'xset' ----"
  1324. xset -q 2> /dev/null
  1325. nl
  1326. echo -e " --- More Keymap Info from 'gsettings' ----"
  1327. input_sources=$(gsettings get org.gnome.desktop.input-sources sources 2> /dev/null )
  1328. echo -e "gsettings input-sources: $input_sources "
  1329. nl
  1330. fi
  1331. else
  1332. echo -e " --- Keymap Info from 'setxkbmap' ----"
  1333. if [ -f /etc/default/keyboard ]
  1334. then
  1335. awk '{print $0}' /etc/default/keyboard
  1336. nl
  1337. else
  1338. echo -e "This is console-only and not Debian Branch."
  1339. nl
  1340. fi
  1341. fi
  1342.  
  1343. echo -e " --- Locale Info from 'localectl' ----"
  1344. echo -e "$localectl_status"
  1345. nl
  1346. if [[ "$detail_level" == "-vv" ]]
  1347. then
  1348. echo -e " --- More Locale Info from 'locale' ----"
  1349. echo -e "$locale_state"
  1350. nl
  1351. fi
  1352. unset -v get_console_desktop input_sources
  1353. }
  1354.  
  1355. function GetRepositories()
  1356. {
  1357. # Gets Repository Information. Called once by Writer().
  1358. # Method only works in Debian Branch. Check for Debian Branch first...
  1359. debug "debian_branch: $debian_branch" 1
  1360. if [[ "$debian_branch" == "0" ]]
  1361. then
  1362. echo -e "${setansi}---------- Repository Information from '/etc/apt/sources.list and etc/apt/sources.list.d/':$ransi"
  1363. nl
  1364. sources=$(grep -v '#' /etc/apt/sources.list | sed -e /^$/d ) # Local Var
  1365. # sourcesd=$(grep -v '#' /etc/apt/sources.list.d/* | sed -e /^$/d)
  1366. echo -e "Sources List:"
  1367. echo -e "$sources"
  1368. nl
  1369. sourcesd_file_path="/etc/apt/sources.list.d/" # Local Var
  1370. if [ $(find $file_path -type f 2> /dev/null | wc -l) -ne 0 ]
  1371. then
  1372. echo -e "Sources List from SourcesD:"
  1373. sourcesd_files=$(find $sourcesd_file_path -type f 2> /dev/null ) # Local Var
  1374. for list_file in $sourcesd_files
  1375. do
  1376. lines=$(grep -v '#' $list_file | \
  1377. sed -e /^$/d )
  1378. #line_count=$( wc -l <<< "$lines" )
  1379. if [ "$lines" != "" ]
  1380. then
  1381. echo -e "$list_file:"
  1382. echo -e "$lines"
  1383. else
  1384. echo -e "$list_file:"
  1385. echo -e "File had no entries."
  1386. fi
  1387. done
  1388. nl
  1389. fi
  1390. else
  1391. echo -e "${setansi}---------- Repository Information"
  1392. echo -e "The repository method written in this script is only for Debian Branch."
  1393. echo -e "This system is not derived from a Debian Branch"
  1394. nl
  1395. fi
  1396. unset -v sources sourcesd_file_path sourcesd_files list_file lines
  1397. }
  1398.  
  1399. function GetOtherDetails()
  1400. {
  1401. # Gets Other General Details. Gets called once by Writer().
  1402. echo -e "${setansi}---------- Other Details from 'Various':$ransi"
  1403. echo -e "The current kernel version is: ${setansi} $(uname -r) $ransi"
  1404. GetReleaseDescription
  1405. GetOriginalInstallDate
  1406. GetInstallMedia
  1407. GetDistUpgradeDate
  1408. GetHweInfo
  1409. GetUserInstalled
  1410. GetSnapInstalled
  1411. GetFlatpakInstalled
  1412. GetUser
  1413. GetLive
  1414. GetWhere
  1415. GetCmdLine
  1416. }
  1417.  
  1418. function GetOriginalInstallDate()
  1419. {
  1420. # Gets the original installation date. Called once by GetOtherDetails().
  1421. # Makes best logical efforts.
  1422. if [ $(sudo find /var/log/installer/ -type f 2> /dev/null | wc -l) -ne 0 ]
  1423. then
  1424. installer_date=$(sudo find /var/log/installer/ -type f -printf "%T+\n" 2> /dev/null | \
  1425. sort| \
  1426. head -1 2> /dev/null ) # Local Var
  1427. installer_date="Original Installation Date: ${setansi} ${installer_date%.*} $ransi"
  1428. else
  1429. debug "Installer date: $(sudo find / -maxdepth 1 -type d -printf "%T+ %p\n" > /dev/null | sort| head -1 )" 1
  1430. #installer_date=$(sudo find / -maxdepth 1 -type d -printf "%T+ %p\n" 2> /dev/null | sort | head -1)
  1431. installer_date=$( \
  1432. for i in /*; \
  1433. do \
  1434. if ! mountpoint -q "$i"; \
  1435. then \
  1436. stat --format='%y %n' "$i"; \
  1437. else \
  1438. echo -e 'Could not accurately determine original Installation Date.'
  1439. fi; \
  1440. done \
  1441. | sort \
  1442. | head -1 \
  1443. | sed 's/ .*//' )
  1444. #installer_date=$(sudo find / -maxdepth 1 -type d -printf "%T+ %p\n" 2> /dev/null | sort | head -1)
  1445. installer_date="Estimated Installation Date: ${setansi} ${installer_date%.*} $ransi"
  1446. fi
  1447. echo -e "$installer_date"
  1448. unset -v installer_date
  1449. }
  1450.  
  1451. function GetInstallMedia()
  1452. {
  1453. # Gets the original install media data. Called once by GetOtherDetails().
  1454. # Only displays if it was installed traditionally
  1455. if [ -d /var/log/installer/ ]
  1456. then
  1457. # Check to See if the media-info file was created before trying to read it...
  1458. # On some pre-created Ubuntu Image Files now available, the /var/log/installer directory exists
  1459. # but the files within that directory have been removed before release for distribution.
  1460. if [ -f /var/log/installer/media-info ]
  1461. then
  1462. installer_media=$(sudo head -n 1 /var/log/installer/media-info | \
  1463. awk '{print "Original Installation Media: "$0}' ) # Local Var
  1464. echo -e "$installer_media"
  1465. elif [ -f /var/anaconda/journal.log ]
  1466. then
  1467. # RHEL Branch
  1468. installer_media=$(grep -i 'CDLABEL' | head -n 1 | awk '{print $10}' | sed 's/root=live:CDLABEL=//g' )
  1469. echo -e "$installer_media"
  1470. elif [ -f /var/anaconda/journal.log ]
  1471. then
  1472. # SUSE Branch
  1473. installer_media=$(sudo grep 'alias' /var/log/zypper.log | grep 'SUSE' | head -n 1 | awk '{print $10}' )
  1474. echo -e "$installer_media"
  1475. else
  1476. echo -e "The Installer log directory exists, but the Installer log files have been removed."
  1477. echo -e "This system may have been installed from a distribution image file."
  1478. fi
  1479. else
  1480. echo -e "Original Installation Media: Cannot determine which ISO this was installed from (yet). "
  1481. echo -e "The Installer Log Directory does not exist. "
  1482. fi
  1483. unset -v installer_media
  1484. }
  1485.  
  1486. function GetDistUpgradeDate()
  1487. {
  1488. # Gets Do_Release_Update date. Called once by GetOtherDetails().
  1489. # Displays if it ever had a do-release-upgrade process done
  1490. if [ -f /var/log/dist-upgrade/apt.log ]
  1491. then
  1492. drg_date=$(sudo grep -E -m 1 -e 'Log Time' /var/log/dist-upgrade/apt.log | \
  1493. awk '{"Do-Release-Upgrade Date: "$3 }' ) # Local Var
  1494. echo -e "$drg_date"
  1495. else
  1496. echo -e "Do-Release-Upgrade Date: This system may have not had a 'Release Upgrade' through 'do-release-upgrade'"
  1497. fi
  1498. nl
  1499. unset -v drg_date
  1500. }
  1501.  
  1502. function GetHweInfo()
  1503. {
  1504. # Get HWE information safely. Only call if it is a flavor of Ubuntu
  1505. # Check if in Debian Branch
  1506. echo -e " --- Hardware Enablement Stack (HWE) Informationt:"
  1507. if [[ "$debian_branch" == "0" ]]
  1508. then
  1509. # Make sure it is a flavor of Ubuntu
  1510. if [[ "$ubuntu_flavor" == "0" ]]
  1511. then
  1512. GetHweRange
  1513. if [ ! -z $LTS_PKG ]
  1514. then
  1515. GetHweKernels
  1516. CheckHwe
  1517. CheckIfCertifiedHardwarePlatform
  1518. fi
  1519. else
  1520. echo -e "System tested is Debian Branch, but is not an Ubuntu or an Ubuntu flavor."
  1521. echo -e "HWE is Ubuntu specific."
  1522. nl
  1523. fi
  1524. else
  1525. echo -e "System tested is either not Ubuntu or is an Ubuntu EOS release version."
  1526. echo -e "HWE is Ubuntu specific."
  1527. nl
  1528. fi
  1529.  
  1530. }
  1531.  
  1532. function GetHweRange() {
  1533. # Valid current choices for Release numbers LTS are: 14.04 through current DEV versions...
  1534. LSB_Rel=$(lsb_release -sr | \
  1535. cut -c 1-5) # Local Var
  1536. case "$LSB_Rel" in
  1537. ("14.04")
  1538. LTS_PKG="14.04"
  1539. ;;
  1540. ("14.10")
  1541. LTS_PKG="14.04"
  1542. ;;
  1543. ("15.04")
  1544. LTS_PKG="14.04"
  1545. ;;
  1546. ("15.10")
  1547. LTS_PKG="14.04"
  1548. ;;
  1549. ("16.04")
  1550. LTS_PKG="16.04"
  1551. ;;
  1552. ("16.10")
  1553. LTS_PKG="16.04"
  1554. ;;
  1555. ("17.04")
  1556. LTS_PKG="16.04"
  1557. ;;
  1558. ("17.10")
  1559. LTS_PKG="16.04"
  1560. ;;
  1561. ("18.04")
  1562. LTS_PKG="18.04"
  1563. ;;
  1564. ("18.10")
  1565. LTS_PKG="18.04"
  1566. ;;
  1567. ("19.04")
  1568. LTS_PKG="18.04"
  1569. ;;
  1570. ("19.10")
  1571. LTS_PKG="18.04"
  1572. ;;
  1573. ("20.04")
  1574. LTS_PKG="20.04"
  1575. ;;
  1576. ("20.10")
  1577. LTS_PKG="20.04"
  1578. ;;
  1579. ("21.04")
  1580. LTS_PKG="20.04"
  1581. ;;
  1582. ("21.10")
  1583. LTS_PKG="20.04"
  1584. ;;
  1585. ("22.04")
  1586. LTS_PKG="22.04"
  1587. ;;
  1588. ("22.10")
  1589. LTS_PKG="22.04"
  1590. ;;
  1591. (*)
  1592. echo -e "Something went wrong. LTS Edition out of HWE support range."
  1593. esac
  1594. # LTS_PKG is Global Var
  1595. debug "HWE LTS_PKG: $LTS_PKG" 1
  1596. unset -v LSB_Rel
  1597. }
  1598.  
  1599. function GetHweKernels()
  1600. {
  1601. echo -e "These are the current kernel ranges for HWE kernels for this release."
  1602.  
  1603. show_kernels=$(apt-cache show linux-generic-hwe-$LTS_PKG 2> /dev/null \
  1604. | awk '/Depends:/ {print "For HWE Package: " $2 ", Kernel Version: " $4}' \
  1605. | sed -e 's/..$//' -e 's/~.*//') 2> /dev/null # Local Var
  1606. echo -e " --- HWE Kernel Reference from 'apt-cache show':"
  1607. echo -e "$show_kernels"
  1608. nl
  1609. unset -v show_kernels
  1610. }
  1611.  
  1612. function CheckHwe()
  1613. {
  1614. return_status=$(dpkg -s linux-generic-hwe-$LTS_PKG 2>&1 \
  1615. | grep 'Status\|dpkg-query' ) # Local Var
  1616. echo -e " --- HWE Package Status from 'dpkg':"
  1617. if [[ "$return_status" == *"Status:"* ]]
  1618. then
  1619. echo -e "Package linux-generic-hwe-$LTS_PKG is installed."
  1620. elif [[ "$return_status" == *"is not installed"* ]]
  1621. then
  1622. echo -e "HWE package linux-generic-hwe-$LTS_PKG was not detected. Please check "
  1623. echo -e "kernel version to verify range"
  1624. fi
  1625. nl
  1626. unset -v return_status
  1627. }
  1628.  
  1629. function CheckIfCertifiedHardwarePlatform()
  1630. {
  1631. platform_check=$(ubuntu-drivers list-oem 2> /dev/null ) # Local Var
  1632. echo -e " --- Certified Hardware Platform Status: (By the Ubuntu Wiki Standards)"
  1633. if [ -z $platform_check ]
  1634. then
  1635. echo -e "Ubuntu Certified Hardware Platform. Safe to install "
  1636. echo -e "the Hardware Enablement Stack (HWE)."
  1637. else
  1638. echo -e "Hardware meta packages were listed. Please refrain from manually changing "
  1639. echo -e "the kernel flavors. The Hardware Enablement Stack (HWE) should not be "
  1640. echo -e "installed on this platform. "
  1641. fi
  1642. nl
  1643. unset -v platform_check
  1644. }
  1645.  
  1646. function GetUserInstalled()
  1647. {
  1648. ## Get a list of User Installed Packages
  1649. # This only works for Debian Branch...
  1650.  
  1651. echo -e " --- User Installed Package List:"
  1652. # check if Debian Branch. Otherwise 'apt-mark' will not be found...
  1653. if [[ "$debian_branch" == "0" ]]
  1654. then
  1655. manually_installed=$(mktemp /tmp/ManuallyInstalled-XXXXX)
  1656. default_installed=$(mktemp /tmp/DefaultInstalled-XXXXX)
  1657. user_installed=$(mktemp /tmp/UserInstalled-XXXXX)
  1658. # Use apt-mark to list all packages marked as manually installed.
  1659. apt-mark showmanual | sort -u > $manually_installed
  1660. # Check to see if defualt installed list exists
  1661. # for prebuilt system images, it does not exist
  1662. if [ -f /var/log/installer/initial-status.gz ]
  1663. then
  1664. # Get the list of default installed packages at initial installation.
  1665. gzip -dc /var/log/installer/initial-status.gz 2> /dev/null | \
  1666. sed -n 's/^Package: //p' | \
  1667. sort -u > $default_installed
  1668. else
  1669. touch $default_installed
  1670. fi
  1671. # Use compare, to exclude those defaults that are unique, AND exclude defaults
  1672. # that are presently marked as manually installed. (Those 'may' have been changed.)
  1673. comm -23 $manually_installed $default_installed > $user_installed
  1674. # Print the list in two columns
  1675. awk 'NF' $user_installed #\ Removed 2022.03.10 to turn to one column
  1676. #| pr -2T # You can remove the pr filter on this to keep output in a single column...
  1677. nl # Add newline in report
  1678. # Remove the temporary files
  1679. rm -f $manually_installed
  1680. rm -f $default_installed
  1681. rm -f $user_installed
  1682. else
  1683. echo -e "The system tested is not in the Debian Branch. "
  1684. echo -e "The method written in this script is for Debian Branch conventions."
  1685. nl
  1686. fi
  1687. unset -v manually_installed default_installed user_installed
  1688. }
  1689.  
  1690. function GetSnapInstalled()
  1691. {
  1692. ## Get a list of Installed Snap Packages
  1693. echo -e " --- Installed Snap Package List:"
  1694. snap_list="" # Local Var
  1695. snap_list=$(snap list 2>&1)
  1696. snap_exit=$? # Local Var
  1697. if [[ "$snap_exit" == "0" ]]
  1698. then
  1699. snap_list=$(snap list | \
  1700. awk '{print $1}' | \
  1701. grep -v 'Name')
  1702. snap_count=0 # Local Var
  1703.  
  1704. if [ "$snap_list" == "" ]
  1705. then
  1706. echo -e "No Snap Packages Installed"
  1707. else
  1708. for snap_package in "${snap_list[@]}"
  1709. do
  1710. echo "$snap_package"
  1711. ((snap_count++))
  1712. done
  1713. debug "Snaplist count: $snap_count" 1
  1714. fi
  1715. else
  1716. echo -e "Snap is not installed"
  1717. fi
  1718. unset -v snap_list snap_exit snap_count snap_package
  1719. nl
  1720. }
  1721.  
  1722. function GetFlatpakInstalled()
  1723. {
  1724. ## Get a list of Installed Flatpak Packages
  1725. echo -e " --- Installed Flatpak Package List:"
  1726. flatpak_list="" # Local Var
  1727. flatpak_list=$(flatpak list 2>&1)
  1728. flatpak_exit=$? # Local Var
  1729. if [[ "$flatpak_exit" == "0" ]]
  1730. then
  1731. flatpak_list=$(flatpak list | \
  1732. awk '{print $1}' | \
  1733. grep -v 'Name') # Local Var
  1734. debug "Flatpak list count:${#flatpak_list[@]}" 1
  1735.  
  1736. if [ "$flatpak_list" == "" ]
  1737. then
  1738. echo -e "No Flatpak Packages Installed"
  1739. else
  1740. for flatpak_package in "${flatpak_list}"
  1741. do
  1742. echo "$flatpak_package"
  1743. done
  1744. fi
  1745. else
  1746. echo -e "Flatpak is not installed"
  1747. fi
  1748. unset -v flatpak_list flatpak_exit flatpak_package
  1749. nl
  1750. }
  1751.  
  1752. function GetLive
  1753. {
  1754. debug "GetLive: (Debug)" 1
  1755. live=false # Local Var
  1756. live_test1=$(mount | \
  1757. grep ' / ' | \
  1758. grep -o -e squashfs \
  1759. -e tmpfs \
  1760. -e aufs ) # Local Var
  1761. live_test2=$(df | \
  1762. grep ' /$'| \
  1763. grep -o -e overlay \
  1764. -e cow \
  1765. -e aufs \
  1766. -e rootfs \
  1767. -e /dev/mapper/live-rw \
  1768. -e union ) # Local Var
  1769.  
  1770. if [ "$live_test1" != "" ]
  1771. then
  1772. live=true
  1773. elif [ "$live_test2" != "" ]
  1774. then
  1775. live=true
  1776. fi
  1777.  
  1778. if $live
  1779. then
  1780. live_installed="a Live Image Environment (LIE)." # Local Var
  1781. else
  1782. live_installed="an installed system"
  1783. fi
  1784. echo -e "The 'system-info' script was booted from $live_installed"
  1785. debug "Live Installed: $live_installed" 1
  1786. unset -v live live_test1 live_test2
  1787. nl
  1788. }
  1789.  
  1790. function GetWhere()
  1791. {
  1792. if [ -e /usr/bin/pstree ]
  1793. then
  1794. if pstree -A -p -l -s &> /dev/null
  1795. then
  1796. LocalOrSsh
  1797. else
  1798. GetLocal
  1799. fi
  1800. else
  1801. GetLocal
  1802. fi
  1803. }
  1804.  
  1805. function LocalOrSsh()
  1806. {
  1807. debug "LocalOrSsh:" 1
  1808. message_tmpstr="locally"
  1809. pidsi="$$"
  1810. debug "pidsi=$pidsi" 1
  1811. treestr=$(pstree -A -p -l -s $pidsi)
  1812. debug "$treestr" 1
  1813. debug "" 1
  1814. debug "-------- ^ whole treestr ^ -------- v trimmed treestr v --------" 1
  1815. treetrm=$(echo $treestr | \
  1816. sed -e "s/.*sshd/sshd/" | \
  1817. sed -e "s/($pidsi).*/($pidsi)/")
  1818. debug "$treetrm" 1
  1819. treestr_test=$(echo "$treestr" | \
  1820. grep 'sshd')
  1821. debug "$treestr_test" 1
  1822. if [[ "$treestr_test" != "" ]]
  1823. then
  1824. message_tmpstr="via ssh"
  1825. fi
  1826.  
  1827. debug "$message_tmpstr" 1
  1828. echo "The 'system-info' script seems to be running $message_tmpstr"
  1829. nl
  1830. unset -v message_tmpstr pidsi treestr treetrm treestr_test
  1831. }
  1832.  
  1833. function GetLocal
  1834. {
  1835. debug "GetLocal: (Debug)" 1
  1836.  
  1837. local_status="locally." # Local Var
  1838. # Get pts session of where the script was run
  1839. pts=$(echo $(ps -C "${0##*/}") | \
  1840. awk '{print $6}') # Local Var
  1841.  
  1842. if [ "$pts" != "" ]
  1843. then
  1844. # Get pts session of the current user if they are
  1845. # using a sshd session
  1846. ssh_test=$(ps -ef | \
  1847. grep "@$pts" | \
  1848. grep "sshd" | \
  1849. awk '{print$9}' | \
  1850. sed 's/.*@//g' \
  1851. 2> /dev/null) # Local Var
  1852. ssh_user=$(ps -ef | \
  1853. grep "$USER@$pts" | \
  1854. grep "sshd" | \
  1855. awk '{print$9}' | \
  1856. sed 's/@,*//g' \
  1857. 2> /dev/null) # Local Var
  1858. # Compare the pts sessions
  1859. if [ "$pts" == "$ssh_test" ]
  1860. then
  1861. local_status="via ssh."
  1862. fi
  1863. fi
  1864. debug "PTS: $pts" 1
  1865. debug "ssh_test: $ssh_test" 1
  1866. debug "ssh_user: $ssh_user" 1
  1867. debug "Current User: $USER" 1
  1868. echo "The 'sysetm-info' script seems to be running $local_status "
  1869. unset -v local_status pts ssh_test ssh_user
  1870. nl
  1871. }
  1872.  
  1873. function GetUser() {
  1874. echo -e "Currently logged in User(s):"
  1875. who -H
  1876. nl
  1877. echo -en "The User running this script was: "
  1878. id -un
  1879. id | \
  1880. tr ' ' '\n'| \
  1881. sed 's/,/, /g'| \
  1882. fold -sw 80 | \
  1883. sed 's/ //g'
  1884. nl
  1885. }
  1886.  
  1887. function GetCmdLine() {
  1888. cmd_line=$(awk '{print $0}' /proc/cmdline)
  1889. echo -e "The Linux Kernel Command Line use to boot was: "
  1890. echo -e "$cmd_line"
  1891. nl
  1892. }
  1893.  
  1894. function AdjustForLessStatus()
  1895. {
  1896. # Sets Env Vars for less viewer or not (written report). Called once by Writer()
  1897. if [ "$less_status" == "less" ]
  1898. then
  1899. setansi="$blueback" # Global Var
  1900. ransi="$resetvid" # Global Var
  1901. lshw_cmd='sudo lshw' # Global Var
  1902. MessageView
  1903. MessageLess
  1904. else
  1905. setansi=""
  1906. ransi=""
  1907. lshw_cmd='sudo lshw -sanitize'
  1908. fi
  1909. }
  1910.  
  1911. function ReportHeader()
  1912. {
  1913. # Start of report (Header). Called once by Writer()
  1914. echo -e "Starting the Ubuntu Forums 'system-info' Report: $startt"
  1915. echo -e '\tPart of the Ama-gi Project'
  1916. echo -e '\t'$version
  1917. nl
  1918. echo -e "---------------------------------------------------------------"
  1919. echo -e "Main Complaint: $main_complaint"
  1920. echo -e "Problem Description: $problem_description"
  1921.  
  1922. unset -v main_complaint problem_description
  1923. }
  1924.  
  1925. function MessageView()
  1926. {
  1927. # Provides message at start of report. Called once by AdjustForLessStatus().
  1928. echo -e "This output should first be ${setansi}viewed by less${ransi}, then sent to a file"
  1929. nl
  1930. }
  1931.  
  1932. function MessageLess()
  1933. {
  1934. # User Instructions for the 'less' utility. Called once by AdjustForLessStatus() and once by Writer() at end of report.
  1935. echo -e "$redback ---------- INSTRUCTIONS FOR THE VIEWER 'LESS' ---------- $resetvid "
  1936. echo -e "You are using the viewer 'less'."
  1937. echo -e "Advance to a next page with the $blueback<SpaceBar>$resetvid key."
  1938. echo -e "Navigate what has been displayed with the"
  1939. echo -e "Left/Right/Up/Down Arrow, PageUp, PageDown, Home, or End keys."
  1940. echo -e "If you are running within a graphical terminal session,"
  1941. nl
  1942. echo -e "you can also navigate with the mouse or touchpad."
  1943. echo -e "Get more built-in help within 'less' with the <H> key."
  1944. echo -e "At any point while in 'less' or if you see this '(END)' prompt"
  1945. echo -e "at the lower left of your screen,"
  1946. echo -e "$blueback quit from 'less' to continue the script with the <q> key. $resetvid"
  1947. nl
  1948. SensitiveDataWarning
  1949. }
  1950.  
  1951. function SensitiveDataWarning()
  1952. {
  1953. echo -e "$redback --- SENSITIVE DATA WARNING --- $resetvid "
  1954. nl
  1955. echo -e "This Report is prepared in two versions- "
  1956. nl
  1957. echo -e "The 'Your Eyes Only' version, only exists temporarily in memory, and is "
  1958. echo -e "viewed onscreen by 'less'. The report that is viewed by 'less' onscreen "
  1959. echo -e "contains 'sensitive data' that should NOT be posted publicly. "
  1960. nl
  1961. echo -e "The Final Report 'file' is saved to disk as a file. The Final Report is "
  1962. echo -e "sanitized, filtered, with the sensitive data removed. It is safe to post "
  1963. echo -e "online publicly. "
  1964. nl
  1965. }
  1966.  
  1967. function ReportFooter()
  1968. {
  1969. # End of report (the footer). Called once by Writer().
  1970. echo -e "${setansi}*** End Of Report ***$ransi"
  1971. if [ "$less_status" == "less" ]
  1972. then
  1973. MessageLess
  1974. fi
  1975. }
  1976.  
  1977. function nl()
  1978. {
  1979. echo -e ""
  1980. }
  1981.  
  1982. function Pause()
  1983. {
  1984. read -n 1 -s -r -p "Press any key to continue"
  1985. nl
  1986. }
  1987.  
  1988. function PassPhrase() {
  1989. read -erp "Press any key to continue: " ans
  1990. ans=$ans
  1991. if [[ "$ans" == "I am Groot" ]]
  1992. then
  1993. echo -e "Running Script: ${sname} $version"
  1994. sleep 0.2
  1995. else
  1996. echo -e "Exiting script"
  1997. ResetLocale
  1998. exit_code=106
  1999. exit $exit_code
  2000. fi
  2001. }
  2002.  
  2003. function ArchiveReport() {
  2004. #Check if uploaded (successfully)...
  2005. # $check-paste is 1 at start (not uploaed), 0 if upload was successful.
  2006. uploaded=$check_paste # Global Var
  2007. report_size=$(wc -c $report | \
  2008. awk '{print $1}') # Local Var
  2009. debug "Report size: $report_size" 1
  2010.  
  2011. if [ $uploaded -eq 1 ]
  2012. then
  2013. # Check size of report file, must be less than 19.5kB
  2014. report_size=$(wc -c $report | \
  2015. awk '{print $1}') # Local Var
  2016. debug "Report size: $report_size" 1
  2017. if [ $report_size -ge 19500 ]
  2018. then
  2019. echo -e "'${sname}.txt' is larger than 19.5kB. ($report_size bytes)"
  2020. nl
  2021. echo -e "If you want to attach to a post on Ubuntu Forums as an attachment, "
  2022. echo -e "you will need to compress the report."
  2023. nl
  2024. # Prompt User
  2025. ans=
  2026. while [ "$ans" != "y" ] && [ "$ans" != "Y" ] && [ "$ans" != "n" ] && [ "$ans" != "N" ]
  2027. do
  2028. read -erp "Would you like to archive the report? <y/N> " ans
  2029. ans="${ans,}"
  2030. debug "User answered $ans" 1
  2031. if [[ $ans =~ ^[Yy]$ ]]
  2032. then
  2033. echo -e "Compressing '${sname}.txt' to archive file '$HOME/${sname}.tar.gz'."
  2034. nl
  2035. # Remove old archive file, if present
  2036. if [ -f $HOME/${sname}.tar.gz ]
  2037. then
  2038. rm -f $HOME/${sname}.tar.gz
  2039. fi
  2040. cwd=$(pwd) # Save current directory
  2041. cd $HOME
  2042. # Create Archive without any parent direcetories
  2043. tar -czvf ${sname}.tar.gz ${sname}.txt
  2044. exit_code=$?
  2045. # Check if archive was created successfully (catch exit code)
  2046. if [ $exit_code -eq 0 ]
  2047. then
  2048. echo -e "Archive file can be found at '$HOME/$sname.tar.gz'."
  2049. nl
  2050. Pause
  2051. else
  2052. echo -e "$sname.txt was not compressed. Archive file not created."
  2053. nl
  2054. Pause
  2055. ResetLocale
  2056. exit 1
  2057. fi
  2058. cd $cwd
  2059. elif [[ ${ans,} =~ ^[Nn]$ ]]
  2060. then
  2061. if [ $verbosity -eq 5 ]
  2062. then
  2063. debug "Continuing without creating archive file..." 1
  2064. sleep 1
  2065. fi
  2066. fi
  2067.  
  2068. done
  2069. else
  2070. echo "Report 'size' check complete. ($report_size bytes)"
  2071. nl
  2072. sleep 1
  2073. fi
  2074. fi
  2075. }
  2076.  
  2077. function Writer
  2078. {
  2079. # Report template. Called twice by Main().
  2080. less_status="$1"
  2081. debug "less_status: $less_status" 1
  2082. AdjustForLessStatus
  2083. ReportHeader
  2084. GetMachineInfo
  2085. GetDiskInfo
  2086. GetUsb
  2087. GetGraphicsEnv
  2088. GetSoundDevices
  2089. GetRepositories
  2090. GetKeyMap
  2091. GetOtherDetails
  2092. if [[ "$less_status" != "less" ]]
  2093. then
  2094. ProcessMissingPrograms
  2095. fi
  2096. ReportFooter
  2097. }
  2098.  
  2099. function PasteCurl()
  2100. {
  2101. target="ix.io"
  2102. return_url=$(printf "%s" "$(<$report)" | curl -F 'f:1=<-' $target )
  2103.  
  2104. check_paste=$?
  2105. debug "From PasteCurl()" 1
  2106. debug "Response: $return_url Exit Code: $check_paste" 1;
  2107. }
  2108.  
  2109. function PastePastebinit()
  2110. {
  2111. target="https://paste.ubuntu.com"
  2112. return_url=$(pastebinit \
  2113. -a "$USER" \
  2114. -i "$report" \
  2115. -b "$target" \
  2116. -t "$sname.txt")
  2117. check_paste=$?
  2118. debug "From PastePasebinit()" 1
  2119. debug "Response: $return_url Exit Code: $check_paste" 1;
  2120. }
  2121.  
  2122. function PasteWget()
  2123. {
  2124. target="termbin.com:9999"
  2125. return_url=$(wget --quiet -O- --post-data="$(cat $report)" $target | tr '\0' '\n' )
  2126. check_paste=$?
  2127. debug "From PasteWget()" 1
  2128. debug "Response: $return_url Exit Code: $check_paste" 1;
  2129. }
  2130.  
  2131. function PasteNc()
  2132. {
  2133. echo -e "This uses a program which sometimes conflicts with "
  2134. echo -e "Anti-Virus Programs. You should turn that off if you "
  2135. echo -e "have installed."
  2136. read -erp "Would you like to proceed or skip? (y/N) " ans
  2137. if [[ ${ans,} =~ ^[Yy]$ ]]
  2138. then
  2139. target="termbin.com 9999"
  2140. return_url=$(cat $report | nc $target | tr '\0' '\n')
  2141. check_paste=$?
  2142. debug "From PasteNc()" 1
  2143. debug "Response: $return_url Exit Code: $check_paste" 1;
  2144. else
  2145. echo -e "You skipped uploading to Pastebin."
  2146. check_paste=1
  2147. fi
  2148. }
  2149.  
  2150. function CheckPasterProgs()
  2151. {
  2152. # The order set here will set preference order.
  2153. # If you change the order here, reset the order in DoPaste() to match.
  2154. if [ -e /usr/bin/pastebinit ]
  2155. then
  2156. paste_prog=1;
  2157. elif [ -e /usr/bin/wget ]
  2158. then
  2159. paste_prog=2;
  2160. elif [ -e /usr/bin/nc ] || [ -e /bin/nc ]
  2161. then
  2162. paste_prog=3;
  2163. elif [ -e /usr/bin/curl ] || [ -e /snap/bin/curl ]
  2164. then
  2165. paste_prog=4;
  2166. else
  2167. paste_prog=0;
  2168. echo -e "Many utilities were not found. Something is wrong.";
  2169. debug "All progs used for paste where not found" 1
  2170. fi
  2171. }
  2172.  
  2173. function DoPaste()
  2174. {
  2175. prog_here=$1
  2176. debug "Passed $prog_here" 1
  2177. case "$prog_here" in
  2178. 1)
  2179. PastePastebinit
  2180. ;;
  2181. 2)
  2182. PasteWget
  2183. ;;
  2184. 3)
  2185. PasteNc
  2186. ;;
  2187. 4)
  2188. PasteCurl
  2189. ;;
  2190. *)
  2191. echo -e "Something went wrong. Error out of range."
  2192. ResetLocale
  2193. exit_code=105
  2194. exit $exit_code
  2195. esac
  2196. }
  2197.  
  2198. function ProgressActive()
  2199. {
  2200. # Provides a spinner to show progress. Called once by Paster.
  2201. declare -a spinner=("\b|" "\b/" "\b-" "\b\\" "\b-")
  2202.  
  2203. echo -ne ' '
  2204. while test -f "$1"
  2205. do
  2206. for spin in "${spinner[@]}"
  2207. do
  2208. stdbuf -oL echo -ne $spin 2> /dev/null
  2209. sleep 0.2
  2210. done
  2211. done
  2212. stdbuf -oL echo -en '\b '
  2213. }
  2214.  
  2215. function Paster()
  2216. {
  2217. # Provides an upload of report with a progress bar. Called once by Main().
  2218. target="a pastebin (URL depends on the method used)." # Var could be unset at end of this function...
  2219. linklog="$HOME/${sname}-link.log"
  2220.  
  2221. echo -e "$blueback Sensitive data is [REMOVED] from the report file $resetvid"
  2222. CheckPasterProgs
  2223. ## Eval $paste_prog
  2224. if [ $paste_prog -ne 0 ]
  2225. then
  2226. read -erp "Do you want to upload the report file to a pastebin? (y/N) " ans
  2227. if [[ ${ans,} =~ ^[Yy]$ ]]
  2228. then
  2229. GetPingStatus "www.ubuntu.com"
  2230. if [ "$return_status" == "true" ]
  2231. then
  2232. echo "Uploading '$report' to '$target'"
  2233. echo -e "This may take 1-2 minutes..."
  2234. nl
  2235. tput civis
  2236. keep_spinning=$(mktemp /tmp/keep_spinning-XXXXX)
  2237. ProgressActive "$keep_spinning" & pid_progressactive=$!
  2238. DoPaste $paste_prog
  2239. if [ $check_paste -eq 0 ]
  2240. then
  2241. paste_done=true
  2242. else
  2243. paste_done=false
  2244. fi
  2245. rm "$keep_spinning"
  2246. sleep 0.5
  2247. tput cnorm
  2248. debug "From Paster()" 1
  2249. debug "Paste_done: $paste_done" 1
  2250. if $paste_done
  2251. then
  2252. # Check $return_url for NULLL
  2253. if [ "$return_url" != "" ]
  2254. then
  2255. echo -e "Uploaded Report: ${startt}:" >> "$linklog"
  2256. echo -e "$blueback Upload successful $resetvid"
  2257. nl
  2258. echo -e "The link to the pastebin is saved in: '$linklog'"
  2259. nl
  2260. echo -e "View at: $return_url" | tee -a "$linklog"
  2261. nl
  2262. else
  2263. echo -e "$redback Upload process failed $resetvid"
  2264. echo -e "The upload utility reported that the upload was susccessful, "
  2265. echo -e "but the host did not return a link to view it."
  2266. nl
  2267. echo -e "Upload the file manually: 'copy & paste' to"
  2268. echo -e "https://paste.ubuntu.com/"
  2269. nl
  2270. exit_code=101
  2271. fi
  2272. else
  2273. echo -e "$redback Upload failed $resetvid"
  2274. echo -e "Upload the file manually: 'copy & paste' to"
  2275. echo -e "https://paste.ubuntu.com/"
  2276. nl
  2277. exit_code=102
  2278. fi
  2279. else
  2280. echo -e "No connection to an outside URL. " | tee -a "$linklog"
  2281. echo -e "Please copy the file $report to a USB and post "
  2282. echo -e "from a computer that does have a working connection."
  2283. echo -e "Upload the file manually: 'copy & paste' to"
  2284. nl
  2285. echo -e "https://paste.ubuntu.com/"
  2286. exit_code=103
  2287. fi
  2288. fi
  2289. else
  2290. echo -e "$redback The required package was not installed. $resetvid"
  2291. nl
  2292. echo -e "Either rerun the script after installing curl, or"
  2293. echo -e "Upload the file manually: 'copy & paste' to"
  2294. nl
  2295. echo -e "https://paste.ubuntu.com/"
  2296. nl
  2297. exit_code=104
  2298. fi
  2299. unset -v target linklog keep_spinning
  2300. }
  2301.  
  2302. function ReportCleaner()
  2303. {
  2304. # Clean the report from non-ascii characters. Called once by Main.
  2305. report_original=$(mktemp /tmp/report_uncleaned-XXXXX)
  2306. mv "$report" "$report_original"
  2307. tr -cd '\11\12\40-\176' < "$report_original" > "$report"
  2308. sleep 1
  2309. # For debug purposes, comment out this next line
  2310. rm "$report_original"
  2311. #unset -v report_cleaned
  2312. }
  2313.  
  2314. # The following Basic Logger was based on public domain code
  2315. # from https://gist.github.com/goodmami/6556701
  2316. # Rewritten by MAFoElffen, 2021.09.15
  2317. function notify()
  2318. {
  2319. logger $silent_lvl "NOTE: $1" $2;
  2320. }
  2321.  
  2322. function critical()
  2323. {
  2324. logger $crt_lvl "CRITICAL: $1" $2;
  2325. }
  2326.  
  2327. error()
  2328. {
  2329. logger $err_lvl "ERROR: $1" $2;
  2330. }
  2331.  
  2332. warn()
  2333. {
  2334. logger $wrn_lvl "WARNING: $1" $2;
  2335. }
  2336.  
  2337. inf()
  2338. {
  2339. logger $inf_lvl "INFO: $1" $2;
  2340. }
  2341.  
  2342. debug()
  2343. {
  2344. logger $dbg_lvl "DEBUG: $1" $2;
  2345. }
  2346.  
  2347. logger()
  2348. {
  2349. logfile=$HOME/$sname.log
  2350. case "$3" in
  2351. 1)
  2352. exec 3>&2 # logging stream (file descriptor 3) defaults to STDERR
  2353. ;;
  2354. 2)
  2355. exec 3>> $logfile # send to log file
  2356. ;;
  2357. 3)
  2358. exec 3>&2 | tee $logfile # send to both logfile and screen
  2359. ;;
  2360. *)
  2361. echo -e "Something went wrong. Log option out of range."
  2362. ResetLocale
  2363. exit 1
  2364. ;;
  2365. esac
  2366.  
  2367.  
  2368. if [ $verbosity -ge $1 ]; then
  2369. # Expand escaped characters, wrap at 70 chars, indent wrapped lines
  2370. echo -e "$startt $2" | \
  2371. fold -w70 -s | \
  2372. sed '2~1s/^/ /' >&3
  2373. fi
  2374. }
  2375.  
  2376.  
  2377. ########################################################################
  2378. #### MAIN
  2379. ########################################################################
  2380. ## PreProcessing
  2381. CheckArgs # Check external arguments: [<ScriptName> arg1]
  2382. CheckRoot # Check if ran as root
  2383. CheckTypeError
  2384. #CheckPath ## <-- This currently breaks CheckPrerequisites()
  2385. CheckPrerequisites
  2386. ## Report
  2387. UserInput
  2388. Writer less | \
  2389. less -R # writing to less
  2390. ## Post processing
  2391. RmOldReport
  2392. #RestorePath ## This needed if we ever get CheckPath() working
  2393. Writer | \
  2394. sed 's/<filter>/[REMOVED]/g' > \
  2395. "$report" # Writing to file
  2396. ## Epitaph
  2397. echo "The result is stored in '$report'"
  2398. # Remove any Non-ASCII characters before Paster()
  2399. ReportCleaner
  2400. ## Optional upload to various PasteBins
  2401. Paster
  2402. ## Optional - Archive Report if size larger than 19.5k
  2403. ArchiveReport
  2404. ResetLocale
  2405. exit $exit_code
  2406.  
  2407.  
  2408.  
  2409. ########################################################################
  2410. ## TODO LIST ##
  2411. ########################################################################
  2412. # Continue to improve script, Report layout and UI
  2413. #
  2414. # Recheck all messages and prompts for spelling errors
  2415. #
  2416. # Add comments as script documentation:
  2417. # - Document logic flow
  2418. #
  2419. # Add DEBUG statements:
  2420. # - To be able to step through logic flow for maintence.
  2421. #
  2422. # Possibly add more for LVM, ZFS, mdadm, and LUKS information(?)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement