/
system-info
executable file
·2700 lines (2522 loc) · 85.6 KB
/
system-info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
## MAFoElffen, <mafoelffen@ubuntu.com>, 2021.08.19
##
## Contributors:
## sudodus <nio.wiklund@gmail.com>, 2021.08.25
## Doug S, 2021.08.22
## oldfred, 2021.08.20
## Filename: support-info
## Description: Report Finds Machine System And Hardware Related Information.
## Purpose: For support use at "UbuntuForums.org".
#########################################################################
# Copyright (c) 2012, 2021
#
# GNU General Public License (GPL-3.0-or-later)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
#### Variables
########################################################################
# Versioning
version="Version: 02.00-09, Script Date: 2023.11.28"
exit_code=0
#md5_sum=$(md5sum $sname | sed 's/system.*//g' )
arg1=$1
arg2=$2
# Set Report filename and path to
sname="${0##*/}" # flexible, needs quoting everywhere if spaces
report="$HOME/${sname}.txt"
# Get present Locale settings
localectl_status=$(localectl status )
locale_state=$(locale )
LANG_Hx=$LANG
LC_CTYPE_Hx=$LC_CTYPE
# Set locale language settings
LANG=C
LC_CTYPE=C
# Set a pretty ANSI screen decoration for displaying the report onscreen
blueback="\0033[1;37;44m"
redback="\0033[1;37;41m"
faintvid="\0033[2m"
resetvid="\0033[0m"
# Check boot mode
boot_mode=$( [ -d /sys/firmware/efi ] && echo "UEFI Firmware mode" || echo "Legacy mode (alias CSM alias BIOS mode)" )
boot_status=$( [ -d /sys/firmware/efi ] ); # Use boot mode as boolean test
less_status="less"
up_status= "true"
debian_branch=0
# Report timestamp
startt="$(date '+%F %T %Z (%z)')"
# LST Name for package calc
LTS_PKG=""
# variables to keep track of missing programs...
missing_programs=""
check_paster=0
# Variable to track upload status as uploaded
check_paste=1
missing_paster_progs=""
# Variable to add more detail to Report
detail_level='-v'
bios_detail=1
zfs_detail=1
md_detail=1
lvm2_detail=1
btrfs_detail=1
# Logger settings
# Change verbosity to show level of warnings. Range: -1 through 5. -1 is show nothing.
verbosity=-1
silent_lvl=0
crt_lvl=1
err_lvl=2
wrn_lvl=3
inf_lvl=4
dbg_lvl=5
# Trap Control-C
stty -echoctl # hide ^C
trap 'other_commands' SIGINT
# 'Trap Section' to clean up Temporary Files on unexpected EXIT's
trap "rm -f $manually_installed" EXIT 2> /dev/null
trap "rm -f $default_installed" EXIT 2> /dev/null
trap "rm -f $user_installed" EXIT 2> /dev/null
trap "rm -f $ssh_data" EXIT 2> /dev/null
trap "ResetLocale" EXIT 2> /dev/null
########################################################################
#### Functions:
########################################################################
function other_commands()
{
tput setaf 1
printf "You can 'not' exit this script by pressing Control-C..."
tput sgr0
printf "Continue with last 'asked' input..."
}
function CheckRoot()
{
clear -x;
## Check if ran as root. Runs at startup. Called by Main()
if [[ "$EUID" == 0 ]] || [ $UID -eq 0 ]
then
echo -e "$redback Do not run this script with sudo or as root$resetvid"
echo -e "If your Linux ditribution installs with only a Root User as a default, "
echo -e "please create another User that has the ability to run elevated commands. "
PassPhrase
#exit_code=106
#exit $exit_code
echo -e "Running Script: ${sname} $version"
else
echo -e "This script needs some parts of it to run with elevated permissions."
nl
## Check if 'sudo' is installed...
if type sudo > /dev/null 2> /dev/null
then
echo -e "Please enter your password for that to happen."
sudo -k # revoke previously cached sudo password
if sudo true
then
echo -e "Running Script: ${sname} $version"
else
echo -e "$redback ----------- This script is made to use 'sudo' ----------- $resetvid"
echo -e "$redback ---- Password was incorrect for sudo elevated rights. --- $resetvid"
PassPhrase
echo -e "Continuing to run the script, but: Expect errors. "
fi
else
echo -e "$redback ----------- This script is made to use 'sudo' ----------- $resetvid"
echo -e "$redback This system does not have 'sudo' installed. $resetvid"
echo -e "$redback If you install 'sudo' you will get much more information. $resetvid"
Pause
echo -e "Running Script: ${sname} $version"
fi
fi
}
function CheckArgs()
{
# Version or Help Panel. Called by Main().
if [[ "$arg1" == "-v" ]]
then
# Versioning: At the commandline: [<ScriptName> -v] returns <VersionInfo>, then exits.
echo -e "$version";
ResetLocale
exit;
elif [[ "$arg1" == "-h" ]] || [[ "$arg1" == "--help" ]]
then
# Help Panel: At the commandline: [<ScriptName> -h or --help] returns this usage panel, then exits.
echo "Running Script: ${sname} $version"
echo -e "md5sum: "$(md5sum ${sname} | sed 's/system.*//g' )
nl
echo -e "Description: The Ubuntu Forums \"system-info\" script queries the users "
echo -e "computer and prepares a report, so that Ubuntu Forums Community Members "
echo -e "can see what they are recommending solutions for."
nl
echo -e "Usage: ./${sname} <option> "
nl
echo -e "Options: "
echo -e " -v Returns Version Information and exits."
echo -e " -h or --help Displays this Help Screen, then exits."
echo -e " -s # or --show # Changes Verbosity levels of the logger."
echo -e " # range 0 through 5"
echo -e " Example: system-info -s 5 turns on debugging messages"
echo -e " -d or --details Displays more details to Report"
echo -e " Adds more details to GPU,Storage Controller, Sound devices, "
echo -e " and ZFS (if installed)."
echo -e " -r or --refresh Update script to latest version."
nl
echo -e "Parts of the script need elevated permissions (sudo) to get the correct "
echo -e "information from your system, while other parts do not. We have "
echo -e "determined where that needs to be used and when not. While the script is "
echo -e "running, you will be asked to enter your userID's password."
nl
echo -e "It then asks the user 2 questions to describe the problem they are having, "
echo -e "then creates ${sname}.txt in their Home directory."
nl
echo -e "Will check programs used by this script, and give the user the option to "
echo -e "quit to install anything it finds missing. Will give the user the option "
echo -e "to upload the report to a pastebin and displays the URL of that to add "
echo -e "their post on Ubuntu Forums."
nl
echo -e "Or they can manually paste the report within code tags in a post or to a "
echo -e "pastebin. Or added as a text attachment to a post."
nl
echo -e "We have tried to keep this safe and simple to use."
ResetLocale
exit;
elif [[ "$arg1" == "-s" ]] || [[ "$arg1" == "--show" ]]
then
if [ $arg2 -ge -1 ] && [ $arg2 -le 5 ]
then
verbosity=$arg2
else
echo -e "Startup Option out of range."
ResetLocale
exit_code=1
exit $exit_code;
fi
elif [[ "$arg1" == "-d" ]] || [[ "$arg1" == "--details" ]]
then
detail_level='-vv'
zfs_detail=0
bios_detail=0
md_detail=0
lvm2_detail=0
btrfs_detail=0
elif [[ "$arg1" == "-r" ]] || [[ "$arg1" == "--refresh" ]]
then
RefreshScript
Pause
exit_code=0
exit $exit_code
fi
}
function ResetLocale() {
LANG=$LANG_Hx
LC_CTYPE=$LC_CTYPE_Hx
}
function CheckTypeError() {
type -a type > /dev/null 2>&1
TypeError=$?
if [[ "$TypeError" == "1" ]]
then
echo -e "The 'type' command is not found as an internal builtin command on this "
echo -e "system. Cannot check for prerequisite Linux utilities used in this script."
echo -e "This script will run, but may display some errors."
nl
fi
unset -v TypeError
}
function RefreshScript() {
# Upgrade script in-place
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]
# resolve $SOURCE until the file is no longer a symlink
do
DIR=$( cd -P "$( dirname "$SOURCE" )" > /dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
if [[ $SOURCE != /* ]]
then
SOURCE=$DIR/$SOURCE
fi
done
DIR=$( cd -P "$( dirname "$SOURCE" )" > /dev/null 2>&1 && pwd )
cd $DIR
sudo wget -N -t 5 -T 10 https://github.com/UbuntuForums/system-info/raw/main/system-info
sudo chmod +x system-info
echo -e "Script was refeshed."
nl
unset DIR SOURCE
}
function CheckDebianBranch()
{
# Check if OS is in Debian Branch
# var debian_branch is global
if [ -f /etc/debian_version ]
then
debian_branch=0
else
debian_branch=1
fi
debug "CheckDebianBranch(). Value: $debian_branch" 1
}
function CheckUbuntuFlavor()
{
# Check if OS is an Ubuntu Flavor
ubuntu_found=$(grep -m 1 -Ei 'untu' /etc/*release)
#echo -e "${#ubuntu_found[@]}"
if [[ "$ubuntu_found" == *"untu"* ]]
then
ubuntu_flavor=0
else
ubuntu_flavor=1
fi
debug "CheckUbuntuFlavor(). Value: $ubuntu_found" 1
# var ubuntu_flavor is global
unset -v ubuntu_found
}
function GetReleaseDescription()
{
# Retrieve 'Release Description' from a Linux Operating System
# As an alternative to: echo -e "The current release description is: ${setansi} $(lsb_release -sd) $ransi"
# Called from GetOtherDetails()
if [[ "$check_lsb_release" == "0" ]]
then
os_name=$(lsb_release -sd)
debug "Got release description from 'lsb_release'." 1
else
# Parse through the (possibly) many release file candidates to retrieve the answer...
os_name=$(grep -m 1 'PRETTY_NAME|DISTRIB_DESCRIPTION' /etc/*release | \
sed 's/\/etc\/.*release://g' | \
sed -e 's/[Pp][Rr][Ee][Tt][Tt][Yy]_[Nn][Aa][Mm][Ee]=//g' \
-e 's/[D,d][E,e][S.s][C,c][R,r][I,i][P,p][T,t][I,i][O,o][Nn]=//g' | \
sed 's/\"//g')
nl
debug "Got release description from 'release' file" 1
fi
echo -e " --- Operating System Release Description --- "
if [[ "$os_name" == "" ]]
then
echo -e "There was a problem determining the Release Description... "
echo -e "Here is the raw outout of the release file(s) to determine manually:"
grep --color=never '=' /etc/*release
debug "GetReleaseDescription(). Dumped release file info. Condition failed." 1
else
echo -e "The current release description is: ${setansi} $os_name $ransi"
fi
nl
unset -v os_name
}
function CheckPrerequisites()
{
## Check if all necessary programs are available. Called once by Main().
# Programs that are in /bin or /usr/bin.
Programs='
sudo
cat
grep
awk
free
gsettings
gzip
tar
md5sum
mokutil
curl
pastebinit
ubuntu-drivers
comm
dpkg
nc
wget
less
ls
lshw
lspci
lsb_release
stat
stdbuf
rm
sed
ping
id
hostname
hostnamectl
pstree
lsblk
lsusb
sleep
sort
mktemp
whoami
who'
# Programs that are in /usr/sbin or /sbin.
Programs_SBIN='
fdisk
ip'
# Programs that are in /usr/snap/bin.
Programs_SnapBin='
curl'
check_prog=1; # global scope
check_mokutil=1; # global scope
check_lshw=0; # global scope
check_lsb_release=0; # global scope
check_hostname=0; # global scope
CheckDebianBranch
CheckUbuntuFlavor
for Program in ${Programs} ${Programs_SBIN}
do
if [ $(type ${Program} > /dev/null 2>&1 ; echo $?) -ne 0 ]
then
## Added to check if a program is not in bin or sbin, but might be present in Snap
# I might have to replicate this for Flatpak(?)
# Renamed variable $Program in this stub here to ProgramSof (for "Program: Snap Or Flatpak".
for ProgramSoF in ${Programs_SnapBin}
do
snap_test=$(snap list $ProgramSof 2>&1 )
snap_exit=$?
flatpak_test=$(flatpak list $ProgramSof 2>&1 )
flatpak_exit=$?
## This first part is more generic code for future things moved to the Snap Store...
#if [[ "$snap_test" != *"no matching snaps installed"* ]] || [ $snap_exit -eq 0 ]
#then
# check_prog=0;
# debug "$ProgramSoF found in Snap" 1
#elif [[ "$flatpak_test 2>&1 )" != "no matching flatpaks installed" ]] || [ $flatpak_exit -eq 0 ]
#then
# check_prog=0
# debug "$ProgramSoF found in FlatPak" 1
#else
# debug "$ProgramSoF not found in an Alternative Package Store" 1
#fi
##
# This part is just for now, where 'curl' might be from Snap
if [[ "$ProgramSoF" == "curl" ]]
then
if [ -e /usr/bin/curl ] || [ -e /snap/bin/curl ]
then
check_prog=0
debug "'curl' was found in either /usr/bin or /snap/bin" 1
elif [ $snap_exit -eq 0 ]
then
check_prog=0
debug "'curl' found in Snap" 1
elif [ $flatpak_exit -eq 0 ]
then
check_prog=0
debug "'curl' found in Flatpak" 1
else
check_prog=1
debug "'curl' was not found in either /usr/bin or /snap/bin" 1
fi
fi
done
## Cleanup Local Variables
unset -v snap_test snap_exit flatpak_test flatpak_exit ProgramSoF Programs_SBIN
if [[ "$check_prog" == "1" ]]
then
echo -e " --- Some Programs This Script Uses Were Missing --- "
fi
if [[ "$Program" == "mokutil" ]]
then # If not 'Here' condition
# 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
# a useful option to see if there "is" a SecureBoot option in the BIOS, besides just what it is set at. This, during
# tests, is safe to install on Legacy Only BIOS systems and can be used to tell if the BIOS is such.
echo -e "$faintvid \"${Program}\" Could not be found. This program is suggested.$resetvid"
echo -e "$faintvid If this is older hardware that is 'Legacy Only BIOS', then this can be $resetvid"
echo -e "$faintvid ignored. The report will still run without it. It will just not be able $resetvid"
echo -e "$faintvid to answer one question. $resetvid"
check_mokutil=0; # Set Flag to false and recheck in GetSb()
check_prog=0;
missing_programs="$missing_programs\n$Program"
debug "'$Program' is not installed" 1
elif [[ "$Program" == "pastebinit" ]] || [[ "$Program" == "wget" ]] || [[ "$Program" == "curl" ]] || [[ "$Program" == "nc" ]]
then
check_prog=0;
check_paster=$((check_paster+1));
missing_paster_progs="$missing_paster_progs$Program, "
missing_programs="$missing_programs\n$Program"
# To take care of a permissions check issue on Debian, 2022.06.15
elif [[ "$Program" == "fdisk" ]]
then
#LSB_ID=$(lsb_release -si)
if [[ "$debian_branch" == "0" ]]
then
# Set Debian as an exception
check_prog=0;
debug "System is Debian, 'fdisk'" 1
fi
if [ -e /sbin/fdisk ]
then
check_prog=0
debug "'fdisk' is in /sbin" 1
fi
elif [[ "$Program" == "ip" ]]
then
# For Slackware
if [ -e /sbin/ip ]
then
check_prog=0
debug "'ip' is in /sbin" 1
fi
elif [[ "$Program" == "lspci" ]]
then
# For Slackware. lspci is in /sbin, instead of /bin
if [ -e /bin/lspci ]
then
#lspci_cmd="/bin/lspci"
check_prog=0
debug "'lspci' is in /bin" 1
elif [ -e /sbin/lspci ]
then
#lspci_cmd="/sbin/lspci"
check_prog=0
debug "'lspci' is in /sbin" 1
else
#lspci_cmd="lspci"
debug "'lspci' was not found." 1
fi
elif [[ "$Program" == "lsb_release" ]]
then
# CHANGE - Do not assume all Debian Branch uses 'lsb_release'...
# If 'lsb_release' does not exist, then set flag for it.
# Set/call alternate methods to retrieve System Description information
## GetReleaseDescription() Modified for this
#check_prog=0;
check_lsb_release=1
debug "Utility 'lsb_release' is not here" 1
elif [[ "$Program" == "hostname" ]]
then
if [ -e /usr/bin/hostnamectl ]
then
check_prog=0
check_hostname=1
else
check_hostname=2
debug "Both 'hostname' and 'hostnamectl' where not found." 1
fi
elif [[ "$Program" == "ubuntu-drivers" ]]
then
# Check if it is Ubuntu Flavor, else not needed
if [[ "$ubuntu_flavor" == "1" ]]
then
check_prog=0;
echo -e "'ubuntu-drivers' is not installed, but is not an Ubuntu Flavor, so ignore."
fi
elif [[ "$Program" == "dpkg" ]]
then
# Check if Debian Branch, else not needed
if [[ "$debian_branch" == "1" ]]
then
check_prog=0;
echo -e "'dpkg' is not installed, but ignore, as this is not a Debian Branch."
fi
elif [[ "$Program" == "lshw" ]]
then
check_lshw=1
check_prog=0;
echo -e "'lshw' is not installed, but will run with less details."
else
echo -e "'$Program' is not installed."
check_prog=0;
missing_programs="$missing_programs\n$Program"
fi
fi
done
if [ "$check_prog" == 0 ]
then
echo -e " -------------------------------- "
nl
echo -e "The Script 'system-info' uses some very basic Linux utilities. "
echo -e "Some of these utilities were not found."
nl
echo -e "The report will still run without them. It will just not answer related "
echo -e "questions. Some of that information may be related to the diagnosis of "
echo -e "your installed system. If missing utilities may have answered your "
echo -e "specified problem, you may be asked by a 'Ubuntu Forums Member' supporting "
echo -e "you if a program was missing, and if you could install it to answer that "
echo -e "related question."
nl
CheckPaster
echo -e "Some of these utilities are not default installed utilities to all Editions, "
echo -e "versions, and flavors of Ubuntu... So may be considered as optional. "
nl
ans=
while [ "$ans" != "e" ] && [ "$ans" != "E" ] && [ "$ans" != "c" ] && [ "$ans" != "C" ]
do
read -erp "<E>xit and install the program(s) or <C>ontinue anyway? <E/C> " ans
ans="${ans,}"
debug "User answered $ans" 1
if [[ $ans =~ ^[Ee]$ ]]
then
echo -e "Please install the missing programs listed above before rerunning script."
debug "User choose to exit after missing programs." 1
ResetLocale
exit_code=0
exit $exit_code
elif [[ ${ans,} =~ ^[Cc]$ ]]
then
echo -e "Some task(s) will not work, but I'll do the best possible, continuing ..."
debug "User choose to continue while missing some programs." 1
sleep 1
fi
done
else
echo -e "All required programs installed..."
sleep 1
fi
}
function CheckPaster() {
if [ $check_paster -eq 4 ]
then
echo -e "Programs 'pastebinit', 'curl', 'wget', and 'nc' are missing. "
echo -e "All 4 utilities used to upload this report to a PasteBin are missing."
echo -e "The report will still run. If not installed, you would just need to "
echo -e "paste the report into a post, contained within 'CODE' Tags."
nl
fi
if [ $check_paster -le 3 -a $check_paster -ge 1 ]
then
echo -e "Program(s) $missing_paster_progs is/are missing, "
echo -e "but can be ignored as there still are installed utilities present to "
echo -e "to be able to upload the report to an online PasteBin."
nl
fi
}
function ProcessMissingPrograms() {
echo -e "---- Required Programs For Report."
if [[ "$missing_programs" == "" ]]
then
echo -e " All required programs installed for report. "
nl
else
echo -e " --- Some Programs This Script Uses Were Missing --- "
echo -e "$missing_programs" | awk 'NF && !/^(start|#)/ {print " " $0}'
nl
fi
}
function RmOldReport()
{
# Removes the old report. Called once by Main().
/bin/rm -f "$report"
exit_code=$?
debug "Remove old report. Exit code: $exit_code" 1
}
function UserInput()
{
# Gather User Information on the problem. Called once by Main()
# User Input for Problem and Description
# Format input
width=$(tput cols)
str=
for ((i=1; i<=$width; i++))
do
str="${str}_"
done
#echo -e "$str"
nl
echo -e "Please provide some \"Basic Information\"..."
read -erp "What is the Main Complaint (summarized)? " main_complaint
read -erp "Describe the Problem: " problem_description
clear -x
unset -v i cols width str
}
function GetMachineInfo()
{
# Gets Computer Information. Called once by Writer().
GetCPU
GetDmi
GetMem
GetSwap
GetNetworkingInfo
GetHostname
nl
}
function GetCPU()
{
# Gets CPU Information. Called once by GetMachineInfo().
echo -e "${setansi}---------- General Computer Specifications:$ransi"
nl
# Do not call $lshw_cmd if 'lshw' is not installed...
if [[ "$check_lshw" == "0" ]]
then
echo -e " --- Computer/CPU Information from 'lshw -C cpu' --- "
$lshw_cmd -C cpu \
| sed -r '/^ *([a-z])/ s/([a-zA-Z])/\u&/' \
| sed -e 's/^ *\*-cpu/\*-Cpu/g' \
| sed '/Capabilities/ s/ *Capabilities/ Capabilities/' \
| fold -sw 71 \
|sed -e 's/^[^ ]/ &/' \
-e 's/ *\*-Cpu/\*-Cpu/g' \
-e 's/ Capabilities/ Capabilities/' \
-e 's/ / /' \
-e '/Capabilities/ s/^[^ ]/ &/'
nl
$lshw_cmd \
| sed '/*-core/,$ d' \
| sed -r '/^ *([a-z])/ s/([a-zA-Z])/\u&/' \
| sed -e 's/ *Configuration/ Configuration/' \
-e '/Configuration/ s/ [^ ]*=[^ ]*/\n&/g' \
-e 's/Configuration/ Configuration/' \
| sed 's/^ [^ ]/ &/'
nl
else
echo -e " --- Computer/CPU Information from '/proc/cpuinfo' --- "
grep -m 1 -Ei 'model name' /proc/cpuinfo | sed 's/model name.*:.//g'
nl
fi
}
function FixNonAsciiVar() {
# Call format to this function is: FixNonAsciiVar <var_name> <var_content>
VarName=$1 # Local Var
VarContent=$2 # Global Var
# Check if field contains non ascii characters
# Remember to set whatever the original passed varaible equal to $VarContent after the call
# to catch the fixed return value.
if [[ "$VarContent" == "*[!:ascii:]*" ]]
then
debug "$VarName contains Non-ASCII characters." 1
debug "Content= $VarContent" 1
# Remove non-ascii chars from string
VarContent=$(sed 's/[\d0-\d8,\d11-\d31,\d127-\d255]//g' <<< $VarContent )
debug "Fixed Content: $VarContent" 1
fi
unset $VarName
}
function GetDmi()
{
# Checks for SMBIOS compliance and values for. Called once by GetMachineInfo().
# Dynamically checks the dmi_var's and removes them from the array if not present
# to adjust for SMBIOS Standard Version variations.
smbios_compliant="/sys/class/dmi/id/" # local var
dmi_vars='bios_vendor
bios_version
bios_release
board_vendor
board_name
board_version
board_serial
board_asset_tag' # local var
echo -e "------------------ SMBIOS Information from '/sys/class/dmi/id/' "
debug "SMBIOS Information" 1
if [ -d $smbios_compliant ]
then
# Loop through once to verify all the vdi_var files exist first. If not,
# then modify list by removing the file name from the declared array.
dmi_idx=0 # local var for counter
for dmi_var in ${dmi_vars}
do
if [ ! -f $smbios_compliant$dmi_var ]
then
debug "Deleting $dmi_var from array..." 1
dmi_vars=( "${dmi_vars[@]/$dmi_var}" )
fi
dmi_idx+=1
done
# Then spin through the modified array to list them
for dmi_var in ${dmi_vars}
do
dmi_content=$(sudo head -n 1 $smbios_compliant$dmi_var | \
sed 's/[\d0-\d8,\d11-\d31,\d127-\d255]//g' )
dmi_title=$(echo $dmi_var | sed -e 's/_/ /g' | sed -e 's/\b\(.\)/\u\1/g' )
if [ $dmi_var == "board_version" ]
then
if [[ "$dmi_content" == "1234567890" ]]
then
dmi_content=""
fi
elif [[ "$dmi_content" == *"default "* ]]
then
dmi_content="Value Not Set"
fi
printf "%-20s %s\n" "$dmi_title:" "$dmi_content";
done
else
echo -e "No SMBIOS information found"
fi
nl
printf "%-20s %s\n" "Current boot mode:" "$boot_mode"
GetSb
nl
GetDmiDetails
unset -v dmi_idx dmi_var dmi_vars dmi_content dmi_title
}
function GetDmiDetails()
{
if [ $bios_detail -eq 0 ]
then
echo -e "Further details from BIOS:"
sudo dmidecode -t 0,1,4
nl
fi
}
function GetSb()
{
# Gets SafeBoot Info from UEFI BIOS or if not UEFI capable. Called once by GetDMI().
# Warns user if mokutil was not present.
echo -e " --- SecureBoot Status from 'mokutil':"
## Bug found on some machines concerning the '--sb-state' option switch on 2022.06.01.
# Shortened to '--sb' (undocumented option switch)
# 'mokuitl' Bug was resolved within days...
# 2022.06.02, Added fallack error handling for fallback to alternate option flag...
# using the documented option flag as the primary method.
if [ $check_mokutil -eq 0 ]
then
echo -e "\tThis would check / have checked if SecureBoot was enabled or not, "
echo -e "\tand checks if the system BIOS was UEFI or Lagacy only BIOS, "
echo -e "\tbut package mokutil was not installed. If you would like to check"
echo -e "\tthis information, please install 'mokutil' and rerun script."
else
# Added this error handling because of a bug on a 'mokutil', that was resolved
# but showed that an error was possible from a faulty update of this utility.
error_mokutil=$(mokutil --sb-state 2>&1 )
if [[ "$error_mokutil" == *"mokutil: unrecognized option '--sb-state'"* ]]
then
mokutil_cmd=$(mokutil --sb 2>&1 )
error_mokutil=$mokutil_cmd
else
mokutil_cmd=$(mokutil --sb-state 2>&1 )
fi
# For Legacy only BIOS, returns error: "EFI variables are not supported on this system"
if [[ "$error_mokutil" == *"EFI variables"* ]]
then
echo -e "$error_mokutil"
elif [[ "$error_mokutil" == *"Command 'mokutil' not found"* ]] #
then
echo -e "\tThis would check / have checked if SecureBoot was enabled or not, "
echo -e "\t and checks if the system BIOS was UEFI or Lagacy only BIOS, "
echo -e "\tbut package mokutil was not installed. If you would like to check"
echo -e "\tthis information, please install 'mokutil' and rerun script."
else
sb_state=$mokutil_cmd
debug "sb_state: $sb_state" 1
if [[ $sb_state == "Failed to read SecureBoot" ]]
then
sb_disabled="SecureBoot: Disabled"
#printf "%-20s %s\n" ${sb_disabled/ /: }
echo -e "$sb_disabled"
else
# These are the known messages returned from mokutil
# This system doesn't support Secure Boot
# Secure Boot is enabled
# Failed to read SecureBoot
# Platform is in Setup Mode
# mokutil: unrecognized option '--sb-state'
#
#printf "%-20s %s\n" ${sb_state/ /: }
echo -e "$sb_state"
fi
fi
nl
fi
unset -v error_mokutil mokutil_cmd sb_state sb_disabled
}
function GetMem()
{
# Gets memory information (pysical and swap). Called once by GetMachineInfo().
echo -e "${setansi}---------- Memory Information:$ransi"
mem_stats=$(free -m)
echo -e "$mem_stats"
nl
unset -v mem_stats
}
function GetSwap () {
# Gets more swap information. Called once by GetMachineInfo().
fstab_info=$(grep 'swap' /etc/fstab )
swaps_info=$(awk '{print $0}' /proc/swaps )
sw_proc=$(awk '{print $0}' /proc/sys/vm/swappiness )
sw_sysctl=$(grep 'vm.swappiness' /etc/sysctl.conf )
valid_settings="10 - 60"
if [ "$sw_sysctl" == "" ]
then
sw_stsctl="If setting 'vm.swappiness' is not declared in '/etc/systctl', then the system inherits the default setting of '60'."
fi
echo -e "${setansi}---------- Swap Information:$ransi"
echo -e " --- Info from 'fstab'"
echo -e "$fstab_info"
nl
echo -e " --- Info from '/proc/swaps'"
echo -e "$swaps_info"
nl
echo -e " --- System Swapiness Settings"
echo -e "Valid swappiness settings are from $valid_settings . "
echo -e "Current setting in '/proc/sys/vm/swappiness': $sw_proc "
echo -e "Current configuration setting in '/etc/sysctl.conf file: "
echo -e "$sw_sysctl"
nl
unset -v fstab_info swaps_info sw_proc sw_sysctl valid_settings
}
function GetUsb()
{
# Gets USB information. Called once by Writer().
# Check condition added for IBM System 390.
if [ -d /sys/bus/usb/devices ]
then
echo -e "${setansi}---------- USB Information from 'lsusb -t -v':$ransi"
usb_info=$(lsusb -t $detail_level)
echo -e "$usb_info"
else
echo "System does not have USB devices."
fi
nl
unset -v usb_info
}
function GetNetworkingInfo()
{
# Gets Networking related Information. Called once by GetMachineInfo().
GetIP
CheckIpUp silent
if [ "$up_status" == "true" ]
then
GetInternetStatus
else
echo -e " --- Internet Connection Status from 'ip addr' --- "
echo -e "Skipped getting Internet Status. Connection: $up_status"
nl
fi
CheckIpUp show
GetMoreWirelessInformation
}
function GetInternetStatus()
{
# Verifies ping status and relsolv. Called once by GetNetworkingInfo().
ping -c 1 www.google.com &> /dev/null
pingStatus=$? # Global var
echo -e " --- Internet Connection Status from 'ping [various addresses]' --- "
if [ $pingStatus == 0 ]
then
echo -e "Connected to Internet with DNS"
else
echo -e "Cannot reach internet by DNS"
ping -c 1 8.8.8.8 &> /dev/null
pingStatus=$?
if [ $pingStatus == 0 ]
then
echo -e "Can reach the internet without DNS"
else
echo -e "Cannot reach internet by IP..."
fi
fi
nl
}
function GetPingStatus()
{
# Takes arg as IP or URL. Returns pseudo boolean $return_status. Called twice (by Paster() and GetInternetStatus()).
ping -c 1 $1 &> /dev/null
pingStatus=$? # Global Var
if [ $pingStatus == 0 ]
then
return_status="true" # Global Var
else
return_status="false" # Global Var
fi
debug "GetPingStatus(): Value: $return_status" 1
}
function GetIP()
{
# Get IP related information. Called once by GetNetworkingInfo().
echo -e "${setansi}---------- IP Address Information:$ransi"
echo -e " --- IP Address Information from 'ip addr' --- "
# Grab IP address information
if [ "$less_status" == "less" ]
then
ip_addr=$(/sbin/ip addr | grep -e '^[[:space:][1-9]:' -e 'inet.') # Local Var
echo -e "$ip_addr"
else
ip_addr=$(/sbin/ip addr | grep -e '^[[:space:][1-9]:' -e 'inet.' \
| sed '/inet\s/ s/inet\s.*/inet [REMOVED]/g' \
| sed '/inet6\s.*/ s/inet6\s.*/inet6 [REMOVED]/g') # Local Var
echo -e "$ip_addr"
fi
unset -v ip_addr