-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinxi.sh
More file actions
executable file
·8652 lines (8165 loc) · 291 KB
/
inxi.sh
File metadata and controls
executable file
·8652 lines (8165 loc) · 291 KB
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
LANG=C
CMDL_MAX=''
COLOR_SCHEME=''
CPU_SLEEP='0.3'
DEV_DISK_ID=''
DEV_DISK_LABEL=''
DEV_DISK_MAPPER=''
DEV_DISK_UUID=''
DMIDECODE_DATA=''
FILTER_STRING='<filter>'
IRC_CLIENT=''
IRC_CLIENT_VERSION=''
LINE_MAX=''
LINE_MAX_CONSOLE='115'
LINE_MAX_IRC='105'
PS_COUNT=5
PS_THROTTLED=''
REPO_DATA=''
A_ALSA_DATA=''
A_AUDIO_DATA=''
A_CMDL=''
A_CPU_CORE_DATA=''
A_CPU_DATA=''
A_CPU_TYPE_PCNT_CCNT=''
A_DEBUG_BUFFER=''
A_GCC_VERSIONS=''
A_GFX_CARD_DATA=''
A_GLX_DATA=''
A_GRAPHIC_DRIVERS=''
A_HDD_DATA=''
A_INTERFACES_DATA=''
A_MACHINE_DATA=''
A_NETWORK_DATA=''
A_OPTICAL_DRIVE_DATA=''
A_PARTITION_DATA=''
A_PS_DATA=''
A_RAID_DATA=''
A_SENSORS_DATA=''
A_UNMOUNTED_PARTITION_DATA=''
A_X_DATA=''
B_ALLOW_UPDATE='true'
B_BSD='false'
B_COLOR_SCHEME_SET='false'
B_CONSOLE_IRC='false'
B_CPU_FLAGS_FULL='false'
B_DBUS_CLIENT='false'
B_DCOP='false'
B_DEBUG_FLOOD='false'
B_DMIDECODE_SET='false'
B_EXTRA_DATA='false'
B_EXTRA_EXTRA_DATA='false'
B_ID_SET='false'
B_HANDLE_CORRUPT_DATA='false'
B_LABEL_SET='false'
B_LOG_COLORS='false'
B_LOG_FULL_DATA='false'
B_MAPPER_SET='false'
B_OUTPUT_FILTER='false'
B_OVERRIDE_FILTER='false'
B_QDBUS='false'
B_PORTABLE='false'
B_ROOT='false'
B_RUN_COLOR_SELECTOR='false'
B_RUNNING_IN_SHELL='false'
if tty >/dev/null;then
B_RUNNING_IN_SHELL='true'
fi
B_SCRIPT_UP='false'
B_SHOW_ADVANCED_NETWORK='false'
B_SHOW_AUDIO='false'
B_SHOW_BASIC_RAID='false'
B_SHOW_BASIC_CPU='false'
B_SHOW_BASIC_DISK='false'
B_SHOW_BASIC_OPTICAL='false'
B_SHOW_CPU='false'
B_SHOW_DISK_TOTAL='false'
B_SHOW_DISK='false'
B_SHOW_FULL_HDD='false'
B_SHOW_FULL_OPTICAL='false'
B_SHOW_GRAPHICS='false'
B_SHOW_HOST='true'
B_SHOW_INFO='false'
B_SHOW_IP='false'
B_SHOW_LABELS='false'
B_SHOW_MACHINE='false'
B_SHOW_NETWORK='false'
B_SHOW_PARTITIONS='false'
B_SHOW_PARTITIONS_FULL='false'
B_SHOW_PS_CPU_DATA='false'
B_SHOW_PS_MEM_DATA='false'
B_SHOW_RAID='false'
B_SHOW_RAID_R='false'
B_SHOW_REPOS='false'
B_RUNNING_IN_X='false'
B_SHOW_SENSORS='false'
B_SHOW_SHORT_OUTPUT='false'
B_SHOW_SYSTEM='false'
B_SHOW_UNMOUNTED_PARTITIONS='false'
B_SHOW_UUIDS='false'
B_SHOW_X_DATA='false'
B_TESTING_1='false'
B_TESTING_2='false'
B_UPLOAD_DEBUG_DATA='false'
B_USB_NETWORKING='false'
# set to true here for debug logging from script start
B_USE_LOGGING='false'
B_UUID_SET='false'
B_XORG_LOG='false'
### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
B_ASOUND_DEVICE_FILE='false'
B_ASOUND_VERSION_FILE='false'
B_BASH_ARRAY='false'
B_CPUINFO_FILE='false'
B_LSB_FILE='false'
B_MDSTAT_FILE='false'
B_MEMINFO_FILE='false'
B_MODULES_FILE='false' #
B_MOUNTS_FILE='false'
B_OS_RELEASE_FILE='false' # new default distro id file? will this one work where lsb-release didn't?
B_PARTITIONS_FILE='false' #
B_PROC_DIR='false'
B_SCSI_FILE='false'
### File's used when present
FILE_ASOUND_DEVICE='/proc/asound/cards'
FILE_ASOUND_MODULES='/proc/asound/modules' # not used but maybe for -A?
FILE_ASOUND_VERSION='/proc/asound/version'
FILE_CPUINFO='/proc/cpuinfo'
FILE_LSB_RELEASE='/etc/lsb-release'
FILE_MDSTAT='/proc/mdstat'
FILE_MEMINFO='/proc/meminfo'
FILE_MODULES='/proc/modules'
FILE_MOUNTS='/proc/mounts'
FILE_OS_RELEASE='/etc/os-release'
FILE_PARTITIONS='/proc/partitions'
FILE_SCSI='/proc/scsi/scsi'
FILE_XORG_LOG='/var/log/Xorg.0.log' # if not found, search and replace with actual location
## app tested for and present, to avoid repeat tests
B_FILE_TESTED='false'
B_HDDTEMP_TESTED='false'
B_MODINFO_TESTED='false'
B_SUDO_TESTED='false'
FILE_PATH=''
HDDTEMP_PATH=''
MODINFO_PATH=''
SUDO_PATH=''
### Variable initializations: constants
DCOPOBJ="default"
DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
# Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up'
DEBUG_BUFFER_INDEX=0
## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function
## so -@[number] debug levels can be set if there is a failure, otherwise you can't even see the errors
# Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Use following variables in config
# files to change defaults for each type, or global
# Same as runtime parameter.
DEFAULT_COLOR_SCHEME=2
# Always leave these blank, these are only going to be set in inxi.conf files, that makes testing
# for user changes easier after sourcing the files
GLOBAL_COLOR_SCHEME=''
IRC_COLOR_SCHEME=''
IRC_CONS_COLOR_SCHEME=''
IRC_X_TERM_COLOR_SCHEME=''
CONSOLE_COLOR_SCHEME=''
VIRT_TERM_COLOR_SCHEME=''
# Default indentation level
INDENT=10
# logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level >= 8
LOGFS_STRING='log_function_data fs $FUNCNAME "$( echo $@ )"'
LOGFE_STRING='log_function_data fe $FUNCNAME'
LOGFS=''
LOGFE=''
# uncomment for debugging from script start
# LOGFS=$LOGFS_STRING
# LOGFE=$LOGFE_STRING
# default to false, no konversation found, 1 is native konvi (qt3/KDE3) script mode, 2 is /cmd inxi start,
## 3 is Konversation > 1.2 (qt4/KDE4)
KONVI=0
# NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
# This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
PARAMETER_LIMIT=30
SCHEME=0 # set default scheme - do not change this, it's set dynamically
# this is set in user prefs file, to override dynamic temp1/temp2 determination of sensors output in case
# cpu runs colder than mobo
SENSORS_CPU_NO=''
# SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
SHOW_IRC=2
# Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
VERBOSITY_LEVEL=0
# Supported number of verbosity levels, including 0
VERBOSITY_LEVELS=7
# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
# type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
# therefore results in nothing.
shopt -u nullglob
## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
# Backup the current Internal Field Separator
ORIGINAL_IFS="$IFS"
# These two determine separators in single line output, to force irc clients not to break off sections
SEP1='~'
SEP2=' '
# these will assign a separator to non irc states. Important! Using ':' can trigger stupid emoticon
# behaviors in output on IRC, so do not use those.
SEP3_IRC=''
SEP3_CONSOLE=':'
SEP3='' # do not set, will be set dynamically
### Script names/paths - must be non root writable
SCRIPT_DATA_DIR="$HOME/.inxi"
ALTERNATE_FTP='' # for data uploads
LOG_FILE="$SCRIPT_DATA_DIR/inxi.log"
LOG_FILE_1="$SCRIPT_DATA_DIR/inxi.1.log"
LOG_FILE_2="$SCRIPT_DATA_DIR/inxi.2.log"
MAN_FILE_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/inxi.1.gz'
MAN_FILE_LOCATION='/usr/share/man/man1'
SCRIPT_NAME='inxi'
SCRIPT_PATCH_NUMBER=''
SCRIPT_PATH='' #filled-in in Main
SCRIPT_VERSION_NUMBER="" #filled-in in Main
SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
SCRIPT_DOWNLOAD_BRANCH_3='http://inxi.googlecode.com/svn/branches/three/'
SCRIPT_DOWNLOAD_BRANCH_4='http://inxi.googlecode.com/svn/branches/four/'
SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/'
# note, you can use any ip url here as long as it's the only line on the output page.
# Also the ip address must be the last thing on that line.
WAN_IP_URL='http://smxi.org/opt/ip.php'
KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data)
### Script Localization
# Make sure every program speaks English.
LC_ALL="C"
export LC_ALL
### Output Colors
# A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
unset EMPTY
# DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW
ANSI_COLORS="[1;30m [0;30m [1;31m [0;31m [1;32m [0;32m [1;33m [0;33m"
IRC_COLORS=" \x0314 \x0301 \x0304 \x0305 \x0309 \x0303 \x0308 \x0307"
# BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
ANSI_COLORS="$ANSI_COLORS [1;34m [0;34m [1;35m [0;35m [1;36m [0;36m [1;37m [0;37m [0;37m"
IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03"
#ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
# See above for notes on EMPTY
## note: group 1: 0, 1 are null/normal
## Following: group 2: generic, light/dark or dark/light; group 3: dark on light; group 4 light on dark;
# this is the count of the first two groups, starting at zero
SAFE_COLOR_COUNT=12
A_COLOR_SCHEMES=(
EMPTY,EMPTY,EMPTY
NORMAL,NORMAL,NORMAL
BLUE,NORMAL,NORMAL
BLUE,RED,NORMAL
CYAN,BLUE,NORMAL
DCYAN,NORMAL,NORMAL
DCYAN,BLUE,NORMAL
DGREEN,NORMAL,NORMAL
DYELLOW,NORMAL,NORMAL
GREEN,DGREEN,NORMAL
GREEN,NORMAL,NORMAL
MAGENTA,NORMAL,NORMAL
RED,NORMAL,NORMAL
BLACK,DGREY,NORMAL
DBLUE,DGREY,NORMAL
DBLUE,DMAGENTA,NORMAL
DBLUE,DRED,NORMAL
DBLUE,BLACK,NORMAL
DGREEN,DYELLOW,NORMAL
DYELLOW,BLACK,NORMAL
DMAGENTA,BLACK,NORMAL
DCYAN,DBLUE,NORMAL
WHITE,GREY,NORMAL
GREY,WHITE,NORMAL
CYAN,GREY,NORMAL
GREEN,WHITE,NORMAL
GREEN,YELLOW,NORMAL
YELLOW,WHITE,NORMAL
MAGENTA,CYAN,NORMAL
MAGENTA,YELLOW,NORMAL
RED,CYAN,NORMAL
RED,WHITE,NORMAL
BLUE,WHITE,NORMAL
)
## Actual color variables
C1=''
C2=''
CN=''
### Distro Data
# In cases of derived distros where the version file of the base distro can also be found under /etc,
# the derived distro's version file should go first. (Such as with Sabayon / Gentoo)
DISTROS_DERIVED="antix-version aptosid-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release siduction-version sidux-version turbolinux-release zenwalk-version"
# debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
DISTROS_PRIMARY="arch-release gentoo-release redhat-release slackware-version SuSE-release"
DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
# this is being used both by core distros and derived distros now, eg, solusos uses it for solusos id, while
# debian, solusos base, uses it as well, so we have to know which it is.
DISTROS_OS_RELEASE_GOOD="arch-release SuSE-release"
## Distros with known problems
# DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
# Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
### Bans Data
# Note that \<ltd\> bans only words, not parts of strings; in \<corp\> you can't use punctuation characters like . or ,
# we're saving about 10+% of the total script exec time by hand building the ban lists here, using hard quotes.
BAN_LIST_NORMAL='computing|computer|corporation|communications|electronics|electrical|electric|gmbh|group|industrial|international|revision|software|technologies|technology|ltd\.|\<ltd\>|inc\.|\<inc\>|intl\.|co\.|\<co\>|corp\.|\<corp\>|\(tm\)|\(r\)|®|\(rev ..\)'
BAN_LIST_CPU='@|cpu deca|dual core|dual-core|tri core|tri-core|quad core|quad-core|ennea|genuine|hepta|hexa|multi|octa|penta|processor|single|triple|[0-9\.]+ *[MmGg][Hh][Zz]'
SENSORS_GPU_SEARCH='intel|radeon|nouveau'
### USB networking search string data, because some brands can have other products than
### wifi/nic cards, they need further identifiers, with wildcards.
### putting the most common and likely first, then the less common, then some specifics
USB_NETWORK_SEARCH="Wi-Fi.*Adapter|Wireless.*Adapter|WLAN.*Adapter|Network.*Adapter|802\.11|Atheros|Atmel|D-Link.*Adapter|D-Link.*Wireless|Linksys|Netgea|Ralink|Realtek.*Network|Realtek.*Wireless|Realtek.*WLAN|Belkin.*Wireless|Belkin.*WLAN|Belkin.*Network"
USB_NETWORK_SEARCH="$USB_NETWORK_SEARCH|Actiontec.*Wireless|Actiontec.*Network|AirLink.*Wireless|Asus.*Network|Asus.*Wireless|Buffalo.*Wireless|Davicom|DWA-.*RangeBooster|DWA-.*Wireless|ENUWI-.*Wireless|LG.*Wi-Fi|Rosewill.*Wireless|RNX-.*Wireless|Samsung.*LinkStick|Samsung.*Wireless|Sony.*Wireless|TEW-.*Wireless|TP-Link.*Wireless|WG[0-9][0-9][0-9].*Wireless|WNA[0-9][0-9][0-9]|WNDA[0-9][0-9][0-9]|Zonet.*ZEW.*Wireless|54 Mbps"
# then a few known hard to ID ones added
# belkin=050d; d-link=07d1; netgear=0846; ralink=148f; realtek=0bda;
USB_NETWORK_SEARCH="$USB_NETWORK_SEARCH|050d:935b|0bda:8189|0bda:8197"
# WARNING: In the main part below (search for 'KONVI')
# there's a check for Konversation-specific config files.
# Any one of these can override the above if inxi is run
# from Konversation!
########################################################################
#### MAIN: Where it all begins
########################################################################
main()
{
eval $LOGFS
local color_scheme=''
# This function just initializes variables
initialize_script_data
# Check for dependencies BEFORE running ANYTHING else except above functions
# Not all distro's have these depends installed by default. Don't want to run
# this if the user is requesting to see this information in the first place
if [[ $1 != '--recommends' ]];then
check_script_depends
check_script_suggested_apps
fi
### Only continue if depends ok
SCRIPT_PATH=$( dirname $0 )
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
SCRIPT_PATCH_NUMBER=$( grep -im 1 'Patch Number:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $4}' )
### Source global config overrides
if [[ -s /etc/$SCRIPT_NAME.conf ]];then
source /etc/$SCRIPT_NAME.conf
fi
# Source user config variables override /etc/inxi.conf variables
if [[ -s $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf ]];then
source $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf
fi
## this needs to run before the KONVI stuff is set below
## Konversation 1.2 apparently does not like the $PPID test in get_start_client
## So far there is no known way to detect if qt4_konvi is the parent process
## this method will infer qt4_konvi as parent
get_start_client
# note: this only works if it's run from inside konversation as a script builtin or something
# only do this if inxi has been started as a konversation script, otherwise bypass this
# KONVI=3 ## for testing puroses
if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then
if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3))
DCPORT="$1"
DCSERVER="$2"
DCTARGET="$3"
shift 3
elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
DCSERVER="$1" ##dbus testing
DCTARGET="$2" ##dbus testing
shift 2
fi
# The section below is on request of Argonel from the Konversation developer team:
# it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
IFS=":"
for kde_config in $( kde-config --path data )
do
if [[ -r ${kde_config}${KONVI_CFG} ]];then
source "${kde_config}${KONVI_CFG}"
break
fi
done
IFS="$ORIGINAL_IFS"
fi
## leave this for debugging dcop stuff if we get that working
# print_screen_output "DCPORT: $DCPORT"
# print_screen_output "DCSERVER: $DCSERVER"
# print_screen_output "DCTARGET: $DCTARGET"
# first init function must be set first for colors etc. Remember, no debugger
# stuff works on this function unless you set the debugging flag manually.
# Debugging flag -@ [number] will not work until get_parameters runs.
# "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
# must be here to allow debugger and other flags to be set.
get_parameters "$@"
# If no colorscheme was set in the parameter handling routine, then set the default scheme
if [[ $B_COLOR_SCHEME_SET != 'true' ]];then
# This let's user pick their color scheme. For IRC, only shows the color schemes, no interactive
# The override value only will be placed in user config files. /etc/inxi.conf can also override
if [[ $B_RUN_COLOR_SELECTOR == 'true' ]];then
select_default_color_scheme
else
# set the default, then override as required
color_scheme=$DEFAULT_COLOR_SCHEME
if [[ -n $GLOBAL_COLOR_SCHEME ]];then
color_scheme=$GLOBAL_COLOR_SCHEME
else
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
color_scheme=$CONSOLE_COLOR_SCHEME
elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
color_scheme=$VIRT_TERM_COLOR_SCHEME
fi
else
if [[ -n $IRC_X_TERM_COLOR_SCHEME && $B_CONSOLE_IRC == 'true' && -n $DISPLAY ]];then
color_scheme=$IRC_X_TERM_COLOR_SCHEME
elif [[ -n $IRC_CONS_COLOR_SCHEME && -z $DISPLAY ]];then
color_scheme=$IRC_CONS_COLOR_SCHEME
elif [[ -n $IRC_COLOR_SCHEME ]];then
color_scheme=$IRC_COLOR_SCHEME
fi
fi
fi
set_color_scheme $color_scheme
fi
fi
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
LINE_MAX=$LINE_MAX_CONSOLE
SEP3=$SEP3_CONSOLE
else
# too hard to read if no colors, so force that for users on irc
if [[ $SCHEME == 0 ]];then
SEP3=$SEP3_CONSOLE
else
SEP3=$SEP3_IRC
fi
LINE_MAX=$LINE_MAX_IRC
fi
# all the pre-start stuff is in place now
B_SCRIPT_UP='true'
script_debugger "Debugger: $SCRIPT_NAME is up and running..."
# then create the output
print_it_out
## last steps
if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
echo -n "[0m"
fi
eval $LOGFE
# weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
# from the last command is taken..
exit 0
}
#### -------------------------------------------------------------------
#### basic tests: set script data, booleans, PATH
#### -------------------------------------------------------------------
# Set PATH data so we can access all programs as user. Set BAN lists.
# initialize some boleans, these directories are used throughout the script
# some apps are used for extended functions any directory used, should be
# checked here first.
# No args taken.
initialize_script_data()
{
eval $LOGFS
# now set the script BOOLEANS for files required to run features
if [[ -d "/proc/" ]];then
B_PROC_DIR='true'
else
error_handler 6
fi
initialize_script_paths
# found a case of battery existing but having nothing in it on desktop mobo
# not all laptops show the first,
if [[ -n $( ls /proc/acpi/battery 2>/dev/null ) ]];then
B_PORTABLE='true'
fi
if [[ -e $FILE_CPUINFO ]]; then
B_CPUINFO_FILE='true'
fi
if [[ -e $FILE_MEMINFO ]];then
B_MEMINFO_FILE='true'
fi
if [[ -e $FILE_ASOUND_DEVICE ]];then
B_ASOUND_DEVICE_FILE='true'
fi
if [[ -e $FILE_ASOUND_VERSION ]];then
B_ASOUND_VERSION_FILE='true'
fi
if [[ -f $FILE_LSB_RELEASE ]];then
B_LSB_FILE='true'
fi
if [[ -f $FILE_OS_RELEASE ]];then
B_OS_RELEASE_FILE='true'
fi
if [[ -e $FILE_SCSI ]];then
B_SCSI_FILE='true'
fi
if [[ -n $DISPLAY ]];then
B_SHOW_X_DATA='true'
B_RUNNING_IN_X='true'
fi
if [[ -e $FILE_MDSTAT ]];then
B_MDSTAT_FILE='true'
fi
if [[ -e $FILE_MODULES ]];then
B_MODULES_FILE='true'
fi
if [[ -e $FILE_MOUNTS ]];then
B_MOUNTS_FILE='true'
fi
if [[ -e $FILE_PARTITIONS ]];then
B_PARTITIONS_FILE='true'
fi
# default to the normal location, then search for it
if [[ -e $FILE_XORG_LOG ]];then
B_XORG_LOG='true'
else
# Detect location of the Xorg log file
if [[ -n $( type -p xset ) ]]; then
FILE_XORG_LOG=$( xset q 2>/dev/null | grep -i 'Log file' | gawk '{print $3}')
if [[ -e $FILE_XORG_LOG ]];then
B_XORG_LOG='true'
fi
fi
fi
# gfx output will require this flag
if [[ $( whoami ) == 'root' ]];then
B_ROOT='true'
fi
eval $LOGFE
}
initialize_script_paths()
{
local path='' added_path='' b_path_found='' sys_path=''
# Extra path variable to make execute failures less likely, merged below
local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
# Fallback paths put into $extra_paths; This might, among others, help on gentoo.
# Now, create a difference of $PATH and $extra_paths and add that to $PATH:
IFS=":"
for path in $extra_paths
do
b_path_found='false'
for sys_path in $PATH
do
if [[ $path == $sys_path ]];then
b_path_found='true'
fi
done
if [[ $b_path_found == 'false' ]];then
added_path="$added_path:$path"
fi
done
IFS="$ORIGINAL_IFS"
PATH="${PATH}${added_path}"
##echo "PATH='$PATH'"
##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
}
# No args taken.
check_script_suggested_apps()
{
eval $LOGFS
local bash_array_test=( "one" "two" )
# check for array ability of bash, this is only good for the warning at this time
# the boolean could be used later
# bash version 2.05b is used in DSL
# bash version 3.0 is used in Puppy Linux; it has a known array bug <reference to be placed here>
# versions older than 3.1 don't handle arrays
# distro's using below 2.05b are unknown, released in 2002
if [[ ${bash_array_test[1]} -eq "two" ]];then
B_BASH_ARRAY='true'
else
script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
fi
# now setting qdbus/dcop for first run, some systems can have both by the way
if [[ -n $( type -p qdbus ) ]];then
B_QDBUS='true'
fi
if [[ -n $( type -p dcop ) ]];then
B_DCOP='true'
fi
eval $LOGFE
}
# Determine if any of the absolutely necessary tools are absent
# No args taken.
check_script_depends()
{
eval $LOGFS
local app_name='' app_path=''
# bc removed from deps for now
local depends="df free gawk grep lspci ps readlink tr uname uptime wc"
# no need to add xprop because it will just give N/A if not there, but if we expand use of xprop,
# should add that here as a test, then use the B_SHOW_X_DATA flag to trigger the tests in de function
local x_apps="xrandr xdpyinfo glxinfo"
if [[ $B_RUNNING_IN_X == 'true' ]];then
for app_name in $x_apps
do
app_path=$( type -p $app_name )
if [[ -z $app_path ]];then
script_debugger "Resuming in non X mode: $app_name not found. For package install advice run: $SCRIPT_NAME --recommends"
B_SHOW_X_DATA='false'
break
fi
done
fi
app_name=''
for app_name in $depends
do
app_path=$( type -p $app_name )
if [[ -z $app_path ]];then
error_handler 5 "$app_name"
fi
done
eval $LOGFE
}
## note: this is now running inside each gawk sequence directly to avoid exiting gawk
## looping in bash through arrays, then re-entering gawk to clean up, then writing back to array
## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
# Enforce boilerplate and buzzword filters
# args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
sanitize_characters()
{
eval $LOGFS
# Cannot use strong quotes to unquote a string with pipes in it!
# bash will interpret the |'s as usual and try to run a subshell!
# Using weak quotes instead, or use '"..."'
echo "$2" | gawk "
BEGIN {
IGNORECASE=1
}
{
gsub(/${!1}/,\"\")
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
print ## prints (returns) cleaned input
}"
eval $LOGFE
}
# Set the colorscheme
# args: $1 = <scheme number>|<"none">
set_color_scheme()
{
eval $LOGFS
local i='' a_script_colors='' a_color_codes=''
if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
set -- 1
fi
# Set a global variable to allow checking for chosen scheme later
SCHEME="$1"
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
a_color_codes=( $ANSI_COLORS )
else
a_color_codes=( $IRC_COLORS )
fi
for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
do
eval "${A_COLORS_AVAILABLE[i]}=\"${a_color_codes[i]}\""
done
IFS=","
a_script_colors=( ${A_COLOR_SCHEMES[$1]} )
IFS="$ORIGINAL_IFS"
# then assign the colors globally
C1="${!a_script_colors[0]}"
C2="${!a_script_colors[1]}"
CN="${!a_script_colors[2]}"
# ((COLOR_SCHEME++)) ## note: why is this? ##
eval $LOGFE
}
select_default_color_scheme()
{
eval $LOGFS
local spacer=' ' options='' user_selection='' config_variable=''
local config_file="$HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf"
local irc_clear="[0m"
local irc_gui='Unset' irc_console='Unset' irc_x_term='Unset'
local console='Unset' virt_term='Unset' global='Unset'
if [[ -n $IRC_COLOR_SCHEME ]];then
irc_gui="Set: $IRC_COLOR_SCHEME"
fi
if [[ -n $IRC_CONS_COLOR_SCHEME ]];then
irc_console="Set: $IRC_CONS_COLOR_SCHEME"
fi
if [[ -n $IRC_X_TERM_COLOR_SCHEME ]];then
irc_x_term="Set: $IRC_X_TERM_COLOR_SCHEME"
fi
if [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
virt_term="Set: $VIRT_TERM_COLOR_SCHEME"
fi
if [[ -n $CONSOLE_COLOR_SCHEME ]];then
console="Set: $CONSOLE_COLOR_SCHEME"
fi
if [[ -n $GLOBAL_COLOR_SCHEME ]];then
global="Set: $GLOBAL_COLOR_SCHEME"
fi
# don't want these printing in irc since they show literally
if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
irc_clear=''
fi
# first make output neutral so it's just plain default for console client
set_color_scheme "0"
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
print_screen_output "Welcome to $SCRIPT_NAME! Please select the default $COLOR_SELECTION color scheme."
# print_screen_output "You will see this message only one time per user account, unless you set preferences in: /etc/$SCRIPT_NAME.conf"
print_screen_output " "
fi
print_screen_output "Because there is no way to know your $COLOR_SELECTION foreground/background colors, you can"
print_screen_output "set your color preferences from color scheme option list below. 0 is no colors, 1 neutral."
print_screen_output "After these, there are 3 sets: 1-dark or light backgrounds; 2-light backgrounds; 3-dark backgrounds."
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
print_screen_output "Please note that this will set the $COLOR_SELECTION preferences only for user: $(whoami)"
fi
print_screen_output "------------------------------------------------------------------------------"
for (( i=0; i < ${#A_COLOR_SCHEMES[@]}; i++ ))
do
if [[ $i -gt 9 ]];then
spacer=' '
fi
# only offer the safe universal defaults
case $COLOR_SELECTION in
global|irc|irc-console|irc-virtual-terminal)
if [[ $i -gt $SAFE_COLOR_COUNT ]];then
break
fi
;;
esac
set_color_scheme $i
print_screen_output "$irc_clear $i)$spacer${C1}Card:${C2} nVidia G86 [GeForce 8400 GS] ${C1}X.Org${C2} 1.7.7"
done
set_color_scheme 0
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
echo -n "[0m"
print_screen_output "$irc_clear $i)${spacer}Remove all color settings. Restore $SCRIPT_NAME default."
print_screen_output "$irc_clear $(($i+1)))${spacer}Continue, no changes or config file setting."
print_screen_output "$irc_clear $(($i+2)))${spacer}Exit, use another terminal, or set manually."
print_screen_output "------------------------------------------------------------------------------"
print_screen_output "Simply type the number for the color scheme that looks best to your eyes for your $COLOR_SELECTION settings"
print_screen_output "and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c plus one of these numbers:"
print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);"
print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)"
print_screen_output "Your selection(s) will be stored here: $config_file"
print_screen_output "Global overrides all individual color schemes. Individual schemes remove the global setting."
print_screen_output "------------------------------------------------------------------------------"
read user_selection
if [[ -n $( grep -Es '^([0-9]+)$' <<< "$user_selection" ) && $user_selection -lt $i ]];then
case $COLOR_SELECTION in
irc)
config_variable='IRC_COLOR_SCHEME'
;;
irc-console)
config_variable='IRC_CONS_COLOR_SCHEME'
;;
irc-virtual-terminal)
config_variable='IRC_X_TERM_COLOR_SCHEME'
;;
console)
config_variable='CONSOLE_COLOR_SCHEME'
;;
virtual-terminal)
config_variable='VIRT_TERM_COLOR_SCHEME'
;;
global)
config_variable='GLOBAL_COLOR_SCHEME'
;;
esac
set_color_scheme $user_selection
# make file/directory first if missing
if [[ ! -f $config_file ]];then
if [[ ! -d $HOME/.$SCRIPT_NAME ]];then
mkdir $HOME/.$SCRIPT_NAME
fi
touch $config_file
fi
if [[ -z $( grep -s "$config_variable=" $config_file ) ]];then
print_screen_output "Creating and updating config file for $COLOR_SELECTION color scheme now..."
echo "$config_variable=$user_selection" >> $config_file
else
print_screen_output "Updating config file for $COLOR_SELECTION color scheme now..."
sed -i "s/$config_variable=.*/$config_variable=$user_selection/" $config_file
fi
# file exists now so we can go on to cleanup
case $COLOR_SELECTION in
irc|irc-console|irc-virtual-terminal|console|virtual-terminal)
sed -i '/GLOBAL_COLOR_SCHEME=/d' $config_file
;;
global)
sed -i -e '/VIRT_TERM_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' -e '/IRC_COLOR_SCHEME=/d' \
-e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file
;;
esac
elif [[ $user_selection == $i ]];then
print_screen_output "Removing all color settings from config file now..."
sed -i -e '/VIRT_TERM_COLOR_SCHEME=/d' -e '/GLOBAL_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' \
-e '/IRC_COLOR_SCHEME=/d' -e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file
set_color_scheme $DEFAULT_COLOR_SCHEME
elif [[ $user_selection == $(( $i+1 )) ]];then
print_screen_output "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 95 to 99"
if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
set_color_scheme $CONSOLE_COLOR_SCHEME
elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
set_color_scheme $VIRT_TERM_COLOR_SCHEME
else
set_color_scheme $DEFAULT_COLOR_SCHEME
fi
elif [[ $user_selection == $(( $i+2 )) ]];then
set_color_scheme $DEFAULT_COLOR_SCHEME
print_screen_output "Ok, exiting $SCRIPT_NAME now. You can set the colors later."
exit 0
else
print_screen_output "Error - Invalid Selection. You entered this: $user_selection"
print_screen_output " "
select_default_color_scheme
fi
else
print_screen_output "------------------------------------------------------------------------------"
print_screen_output "After finding the scheme number you like, simply run this again in a terminal to set the configuration"
print_screen_output "data file for your irc client. You can set color schemes for the following: start inxi with -c plus:"
print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);"
print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)"
exit 0
fi
eval $LOGFE
}
########################################################################
#### UTILITY FUNCTIONS
########################################################################
#### -------------------------------------------------------------------
#### error handler, debugger, script updater
#### -------------------------------------------------------------------
# Error handling
# args: $1 - error number; $2 - optional, extra information
error_handler()
{
eval $LOGFS
local error_message=''
# assemble the error message
case $1 in
2) error_message="large flood danger, debug buffer full!"
;;
3) error_message="unsupported color scheme number: $2"
;;
4) error_message="unsupported verbosity level: $2"
;;
5) error_message="dependency not met: $2 not found in path.\nFor distribution installation package names and missing apps information, run: $SCRIPT_NAME --recommends"
;;
6) error_message="/proc not found! Quitting..."
;;
7) error_message="One of the options you entered in your script parameters: $2\nis not supported.The option may require extra arguments to work.\nFor supported options (and their arguments), check the help menu: $SCRIPT_NAME -h"
;;
8) error_message="the self-updater failed, wget exited with error: $2.\nYou probably need to be root.\nHint, to make for easy updates without being root, do: chown <user name> $SCRIPT_PATH/$SCRIPT_NAME"
;;
9) error_message="unsupported debugging level: $2"
;;
10)
error_message="the alt download url you provided: $2\nappears to be wrong, download aborted. Please note, the url\nneeds to end in /, without $SCRIPT_NAME, like: http://yoursite.com/downloads/"
;;
11)
error_message="unsupported testing option argument: -! $2"
;;
12)
error_message="the svn branch download url: $2\nappears to be empty currently. Make sure there is an actual svn branch version\nactive before you try this again. Check http://code.google.com/p/inxi\nto verify the branch status."
;;
13)
error_message="The -t option requires the following extra arguments (no spaces between letters/numbers):\nc m cm [required], for example: -t cm8 OR -t cm OR -t c9\n(numbers: 1-20, > 5 throttled to 5 in irc clients) You entered: $2"
;;
14)
error_message="failed to write correctly downloaded $SCRIPT_NAME to location $SCRIPT_PATH.\nThis usually means you don't have permission to write to that location, maybe you need to be root?\nThe operation failed with error: $2"
;;
15)
error_message="failed set execute permissions on $SCRIPT_NAME at location $SCRIPT_PATH.\nThis usually means you don't have permission to set permissions on files there, maybe you need to be root?\nThe operation failed with error: $2"
;;
16)
error_message="$SCRIPT_NAME downloaded but the file data is corrupted. Purged data and using current version."
;;
20)
error_message="The option you selected has been deprecated. $2\nSee the -h (help) menu for currently supported options."
;;
*) error_message="error unknown: $@"
set -- 99
;;
esac
# then print it and exit
print_screen_output "Error $1: $error_message"
eval $LOGFE
exit $1
}
# prior to script up set, pack the data into an array
# then we'll print it out later.
# args: $1 - $@ debugging string text
script_debugger()
{
eval $LOGFS
if [[ $B_SCRIPT_UP == 'true' ]];then
# only return if debugger is off and no pre start up errors have occured
if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
return 0
# print out the stored debugging information if errors occured
elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
do
print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
done
DEBUG_BUFFER_INDEX=0
fi
# or print out normal debugger messages if debugger is on
if [[ $DEBUG -gt 0 ]];then
print_screen_output "$1"
fi
else
if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
error_handler 2
# this case stores the data for later printout, will print out only
# at B_SCRIPT_UP == 'true' if array index > 0
else
A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
# increment count for next pre script up debugging error
(( DEBUG_BUFFER_INDEX++ ))
fi
fi
eval $LOGFE
}
# NOTE: no logging available until get_parameters is run, since that's what sets logging
# in order to trigger earlier logging manually set B_USE_LOGGING to true in top variables.
# $1 alone: logs data; $2 with or without $3 logs func start/end.
# $1 type (fs/fe/cat/raw) or logged data; [$2 is $FUNCNAME; [$3 - function args]]
log_function_data()
{
if [ "$B_USE_LOGGING" == 'true' ];then
local logged_data='' spacer=' ' line='----------------------------------------'
case $1 in
fs)