Merge ~sylvain-pineau/plainbox-provider-checkbox:inxi_2021_07_21 into plainbox-provider-checkbox:master
- Git
- lp:~sylvain-pineau/plainbox-provider-checkbox
- inxi_2021_07_21
- Merge into master
Proposed by
Sylvain Pineau
Status: | Merged |
---|---|
Approved by: | Sylvain Pineau |
Approved revision: | 24af188e19afb22898301d5a30e498b0daf980c3 |
Merged at revision: | 5d9b74b71d0e883bce1b1300e580f79ada78a7e7 |
Proposed branch: | ~sylvain-pineau/plainbox-provider-checkbox:inxi_2021_07_21 |
Merge into: | plainbox-provider-checkbox:master |
Diff against target: |
45453 lines (+26072/-18358) 1 file modified
bin/inxi_snapshot (+26072/-18358) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Maciej Kisielewski (community) | Approve | ||
Review via email: mp+408945@code.launchpad.net |
Commit message
Description of the change
Version refresh of the INXI system information tool
The previous snapshot was from 2018 and was missing some CPU IDs
Tested on AMD64
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/bin/inxi_snapshot b/bin/inxi_snapshot | |||
2 | index 5928ca5..6c4d37b 100755 | |||
3 | --- a/bin/inxi_snapshot | |||
4 | +++ b/bin/inxi_snapshot | |||
5 | @@ -1,11 +1,11 @@ | |||
6 | 1 | #!/usr/bin/env perl | 1 | #!/usr/bin/env perl |
7 | 2 | ## infobash: Copyright (C) 2005-2007 Michiel de Boer aka locsmif | 2 | ## infobash: Copyright (C) 2005-2007 Michiel de Boer aka locsmif |
9 | 3 | ## inxi: Copyright (C) 2008-2018 Harald Hope | 3 | ## inxi: Copyright (C) 2008-2021 Harald Hope |
10 | 4 | ## Additional features (C) Scott Rogers - kde, cpu info | 4 | ## Additional features (C) Scott Rogers - kde, cpu info |
11 | 5 | ## Further fixes (listed as known): Horst Tritremmel <hjt at sidux.com> | 5 | ## Further fixes (listed as known): Horst Tritremmel <hjt at sidux.com> |
12 | 6 | ## Steven Barrett (aka: damentz) - usb audio patch; swap percent used patch | 6 | ## Steven Barrett (aka: damentz) - usb audio patch; swap percent used patch |
15 | 7 | ## Jarett.Stevens - dmidecode -M patch for older systems with the /sys | 7 | ## Jarett.Stevens - dmidecode -M patch for older systems without /sys machine |
16 | 8 | ## | 8 | ## |
17 | 9 | ## License: GNU GPL v3 or greater | 9 | ## License: GNU GPL v3 or greater |
18 | 10 | ## | 10 | ## |
19 | 11 | ## You should have received a copy of the GNU General Public License | 11 | ## You should have received a copy of the GNU General Public License |
20 | @@ -13,83 +13,106 @@ | |||
21 | 13 | ## | 13 | ## |
22 | 14 | ## If you don't understand what Free Software is, please read (or reread) | 14 | ## If you don't understand what Free Software is, please read (or reread) |
23 | 15 | ## this page: http://www.gnu.org/philosophy/free-sw.html | 15 | ## this page: http://www.gnu.org/philosophy/free-sw.html |
24 | 16 | ## | ||
25 | 17 | ## DEVS: NOTE: geany/scite folding is picky. Leave 1 space after # or it breaks! | ||
26 | 16 | 18 | ||
27 | 17 | use strict; | 19 | use strict; |
28 | 18 | use warnings; | 20 | use warnings; |
29 | 19 | # use diagnostics; | 21 | # use diagnostics; |
30 | 20 | use 5.008; | 22 | use 5.008; |
31 | 21 | 23 | ||
33 | 22 | use Cwd qw(abs_path); # qw(abs_path);#abs_path realpath getcwd | 24 | ## Perl 7 things for testing: depend on Perl 5.032 |
34 | 25 | # use 5.032; | ||
35 | 26 | # use compat::perl5; # act like Perl 5's defaults | ||
36 | 27 | # no feature qw(indirect); | ||
37 | 28 | # no multidimensional; | ||
38 | 29 | # no bareword::filehandles; | ||
39 | 30 | |||
40 | 31 | use Cwd qw(abs_path); # #abs_path realpath getcwd | ||
41 | 23 | use Data::Dumper qw(Dumper); # print_r | 32 | use Data::Dumper qw(Dumper); # print_r |
43 | 24 | use File::Find; | 33 | # NOTE: load in SystemDebugger unless encounter issues with require/import |
44 | 34 | # use File::Find; | ||
45 | 35 | use File::stat; # needed for Xorg.0.log file mtime comparisons | ||
46 | 25 | use Getopt::Long qw(GetOptions); | 36 | use Getopt::Long qw(GetOptions); |
48 | 26 | # Note: default auto_abbrev is enabled, that's fine | 37 | # Note: default auto_abbrev is enabled |
49 | 27 | Getopt::Long::Configure ('bundling', 'no_ignore_case', | 38 | Getopt::Long::Configure ('bundling', 'no_ignore_case', |
50 | 28 | 'no_getopt_compat', 'no_auto_abbrev','pass_through'); | 39 | 'no_getopt_compat', 'no_auto_abbrev','pass_through'); |
53 | 29 | use POSIX qw(uname strftime ttyname); | 40 | use POSIX qw(ceil uname strftime ttyname); |
54 | 30 | # use feature qw(state); | 41 | # use Benchmark qw(:all);_ |
55 | 42 | # use Devel::Size qw(size total_size); | ||
56 | 43 | # use feature qw(say state); # 5.10 or newer Perl | ||
57 | 44 | |||
58 | 45 | ### INITIALIZE VARIABLES ### | ||
59 | 31 | 46 | ||
60 | 32 | ## INXI INFO ## | 47 | ## INXI INFO ## |
61 | 33 | my $self_name='inxi'; | 48 | my $self_name='inxi'; |
64 | 34 | my $self_version='3.0.27'; | 49 | my $self_version='3.3.06'; |
65 | 35 | my $self_date='2018-10-14'; | 50 | my $self_date='2021-07-21'; |
66 | 36 | my $self_patch='00'; | 51 | my $self_patch='00'; |
67 | 37 | ## END INXI INFO ## | 52 | ## END INXI INFO ## |
68 | 38 | 53 | ||
70 | 39 | ### INITIALIZE VARIABLES ### | 54 | my ($b_pledge,@pledges); |
71 | 55 | if (eval {require OpenBSD::Pledge}){ | ||
72 | 56 | OpenBSD::Pledge->import(); | ||
73 | 57 | $b_pledge = 1; | ||
74 | 58 | # cpath/wpath: dir/files .inxi, --debug > 9, -c 9x, -w/W; | ||
75 | 59 | # dns/inet: ftp upload --debug > 20; exec/proc/rpath: critical; | ||
76 | 60 | # prot_exec: Perl import; getpw: perl getpwuid() -c 9x, Net::FTP --debug > 20; | ||
77 | 61 | # stdio: default; error: debugging pledge/perl | ||
78 | 62 | # tested. not required: mcast pf ps recvfd sendfd tmppath tty unix vminfo; | ||
79 | 63 | # Pledge removal: OptionsHandler::post_process() [dns,inet,cpath,getpw,wpath]; | ||
80 | 64 | # SelectColors::set_selection() [getpw] | ||
81 | 65 | @pledges = qw(cpath dns exec getpw inet proc prot_exec rpath wpath); | ||
82 | 66 | pledge(@pledges); | ||
83 | 67 | } | ||
84 | 40 | 68 | ||
85 | 41 | ## Self data | 69 | ## Self data |
87 | 42 | my ($self_path, $user_config_dir, $user_config_file,$user_data_dir); | 70 | my ($self_path,$user_config_dir,$user_config_file,$user_data_dir); |
88 | 71 | |||
89 | 72 | ## Hashes | ||
90 | 73 | my (%alerts,%build_prop,%client,%colors,%disks_bsd,%dboot,%devices,%dl, | ||
91 | 74 | %dmmapper,%force,%loaded,%mapper,%program_values,%rows,%sensors_raw, | ||
92 | 75 | %service_tool,%show,%sysctl,%system_files,%usb); | ||
93 | 76 | |||
94 | 77 | ## System Arrays | ||
95 | 78 | my (@app,@dmi,@gpudata,@ifs,@ifs_bsd,@paths,@ps_aux,@ps_cmd,@ps_gui, | ||
96 | 79 | @sensors_exclude,@sensors_use,@uname); | ||
97 | 80 | |||
98 | 81 | ## Disk/Logical/Partition/RAID arrays | ||
99 | 82 | my (@btrfs_raid,@glabel,@labels,@lsblk,@lvm,@lvm_raid,@md_raid,@partitions, | ||
100 | 83 | @proc_partitions,@raw_logical,@soft_raid,@swaps,@uuids,@zfs_raid); | ||
101 | 43 | 84 | ||
102 | 44 | ## Debuggers | 85 | ## Debuggers |
106 | 45 | my $debug=0; | 86 | my %debugger = ('level' => 0); |
107 | 46 | my (@t0,$end,$start,$fh_l,$log_file); # log file handle, file | 87 | my (@dbg,%fake,@t0); |
108 | 47 | my ($b_hires,$t1,$t2,$t3) = (0,0,0,0); | 88 | my ($b_hires,$b_log,$b_log_colors,$b_log_full); |
109 | 89 | my ($end,$start,$fh_l,$log_file); # log file handle, file | ||
110 | 90 | my ($t1,$t2,$t3) = (0,0,0); # timers | ||
111 | 91 | ## debug / temp tools | ||
112 | 92 | $debugger{'sys'} = 1; | ||
113 | 93 | $client{'test-konvi'} = 0; | ||
114 | 94 | |||
115 | 48 | # NOTE: redhat removed HiRes from Perl Core Modules. | 95 | # NOTE: redhat removed HiRes from Perl Core Modules. |
116 | 49 | if (eval {require Time::HiRes}){ | 96 | if (eval {require Time::HiRes}){ |
119 | 50 | Time::HiRes->import('gettimeofday','tv_interval','usleep'); | 97 | Time::HiRes->import('gettimeofday','tv_interval','usleep'); |
120 | 51 | $b_hires = 1; | 98 | $b_hires = 1; |
121 | 52 | } | 99 | } |
122 | 53 | @t0 = eval 'Time::HiRes::gettimeofday()' if $b_hires; # let's start it right away | 100 | @t0 = eval 'Time::HiRes::gettimeofday()' if $b_hires; # let's start it right away |
151 | 54 | ## Hashes | 101 | |
152 | 55 | my ( %alerts,%client,%colors,%debugger,%dl,%files,%rows,%system_files,%use ); | 102 | ## Booleans [busybox_ps not used actively] |
153 | 56 | 103 | my ($b_admin,$b_android,$b_arm,$b_busybox_ps,$b_display,$b_irc, | |
154 | 57 | ## Arrays | 104 | $b_mips,$b_ppc,$b_root,$b_running_in_display,$b_sparc); |
127 | 58 | # ps_aux is full output, ps_cmd is only the last 10 columns to last | ||
128 | 59 | my (@app,@dmesg_boot,@devices_audio,@devices_graphics,@devices_network, | ||
129 | 60 | @devices_hwraid,@devices_timer,@dmi,@gpudata,@ifs,@ifs_bsd, | ||
130 | 61 | @paths,@proc_partitions,@ps_aux,@ps_cmd,@ps_gui, | ||
131 | 62 | @sysctl,@sysctl_battery,@sysctl_sensors,@sysctl_machine,@uname,@usb); | ||
132 | 63 | ## Disk arrays | ||
133 | 64 | my (@dm_boot_disk,@dm_boot_optical,@glabel,@gpart,@hardware_raid,@labels, | ||
134 | 65 | @lsblk,@partitions,@raid,@sysctl_disks,@uuids); | ||
135 | 66 | my @test = (0,0,0,0,0); | ||
136 | 67 | |||
137 | 68 | ## Booleans | ||
138 | 69 | my ($b_admin,$b_arm,$b_bb_ps,$b_block_tool,$b_console_irc, | ||
139 | 70 | $b_display,$b_dmesg_boot_check,$b_dmi,$b_dmidecode_force, | ||
140 | 71 | $b_fake_bsd,$b_fake_dboot,$b_fake_dmidecode,$b_fake_pciconf,$b_fake_sysctl, | ||
141 | 72 | $b_fake_usbdevs,$b_force_display,$b_gpudata,$b_irc, | ||
142 | 73 | $b_log,$b_log_colors,$b_log_full,$b_man,$b_mem,$b_mips, | ||
143 | 74 | $b_pci,$b_pci_tool,$b_ppc,$b_proc_partitions,$b_ps_gui, | ||
144 | 75 | $b_root,$b_running_in_display, | ||
145 | 76 | $b_slot_tool,$b_soc_audio,$b_soc_gfx,$b_soc_net,$b_soc_timer,$b_sparc, | ||
146 | 77 | $b_sudo,$b_sysctl,$b_usb,$b_usb_check,$b_usb_sys,$b_usb_tool,$b_wmctrl); | ||
147 | 78 | ## Disk checks | ||
148 | 79 | my ($b_dm_boot_disk,$b_dm_boot_optical,$b_glabel,$b_hardware_raid, | ||
149 | 80 | $b_label_uuid,$b_lsblk,$b_partitions,$b_raid); | ||
150 | 81 | my ($b_sysctl_disk,$b_update,$b_weather) = (1,1,1); | ||
155 | 82 | 105 | ||
156 | 83 | ## System | 106 | ## System |
159 | 84 | my ($bsd_type,$language,$os,$pci_tool,$device_vm) = ('','','','',''); | 107 | my ($bsd_type,$device_vm,$language,$os,$pci_tool,$wan_url) = ('','','','','',''); |
160 | 85 | my ($bits_sys,$cpu_arch); | 108 | my ($bits_sys,$cpu_arch,$ppid); |
161 | 86 | my ($cpu_sleep,$dl_timeout,$limit,$ps_cols,$ps_count) = (0.35,4,10,0,5); | 109 | my ($cpu_sleep,$dl_timeout,$limit,$ps_cols,$ps_count) = (0.35,4,10,0,5); |
162 | 87 | my $sensors_cpu_nu = 0; | 110 | my $sensors_cpu_nu = 0; |
164 | 88 | my $weather_unit='mi'; | 111 | my ($dl_ua,$weather_source,$weather_unit) = ('s-tools/' . $self_name . '-',100,'mi'); |
165 | 89 | 112 | ||
166 | 90 | ## Tools | 113 | ## Tools |
169 | 91 | my ($display,$ftp_alt,$tty_session); | 114 | my ($bt_tool,$display,$ftp_alt); |
170 | 92 | my ($display_opt,$sudo) = ('',''); | 115 | my ($display_opt,$sudoas) = ('',''); |
171 | 93 | 116 | ||
172 | 94 | ## Output | 117 | ## Output |
173 | 95 | my $extra = 0;# supported values: 0-3 | 118 | my $extra = 0;# supported values: 0-3 |
174 | @@ -98,26 +121,25 @@ my $line1 = "------------------------------------------------------------------- | |||
175 | 98 | my $line2 = "======================================================================\n"; | 121 | my $line2 = "======================================================================\n"; |
176 | 99 | my $line3 = "----------------------------------------\n"; | 122 | my $line3 = "----------------------------------------\n"; |
177 | 100 | my ($output_file,$output_type) = ('','screen'); | 123 | my ($output_file,$output_type) = ('','screen'); |
179 | 101 | my $prefix = 0; # for the primiary row hash key prefix | 124 | my $prefix = 0; # for the primary row hash key prefix |
180 | 102 | 125 | ||
182 | 103 | # these will assign a separator to non irc states. Important! Using ':' can | 126 | ## Initialize internal hashes |
183 | 127 | # these assign a separator to non irc states. Important! Using ':' can | ||
184 | 104 | # trigger stupid emoticon. Note: SEP1/SEP2 from short form not used anymore. | 128 | # trigger stupid emoticon. Note: SEP1/SEP2 from short form not used anymore. |
185 | 105 | # behaviors in output on IRC, so do not use those. | 129 | # behaviors in output on IRC, so do not use those. |
187 | 106 | my %sep = ( | 130 | my %sep = ( |
188 | 107 | 's1-irc' => ':', | 131 | 's1-irc' => ':', |
189 | 108 | 's1-console' => ':', | 132 | 's1-console' => ':', |
190 | 109 | 's2-irc' => '', | 133 | 's2-irc' => '', |
191 | 110 | 's2-console' => ':', | 134 | 's2-console' => ':', |
192 | 111 | ); | 135 | ); |
196 | 112 | 136 | #$show{'host'} = 1; | |
194 | 113 | my %show = ('host' => 1); | ||
195 | 114 | |||
197 | 115 | my %size = ( | 137 | my %size = ( |
198 | 116 | 'console' => 115, | 138 | 'console' => 115, |
199 | 117 | # Default indentation level. NOTE: actual indent is 1 greater to allow for | 139 | # Default indentation level. NOTE: actual indent is 1 greater to allow for |
200 | 118 | # spacing | 140 | # spacing |
201 | 119 | 'indent' => 11, | 141 | 'indent' => 11, |
203 | 120 | 'indent-min' => 90, | 142 | 'wrap-max' => 90, |
204 | 121 | 'irc' => 100, # shorter because IRC clients have nick lists etc | 143 | 'irc' => 100, # shorter because IRC clients have nick lists etc |
205 | 122 | 'max' => 0, | 144 | 'max' => 0, |
206 | 123 | 'no-display' => 130, | 145 | 'no-display' => 130, |
207 | @@ -125,10 +147,10 @@ my %size = ( | |||
208 | 125 | 'term' => 80, | 147 | 'term' => 80, |
209 | 126 | 'term-lines' => 100, | 148 | 'term-lines' => 100, |
210 | 127 | ); | 149 | ); |
215 | 128 | 150 | my %use = ( | |
216 | 129 | ## debug / temp tools | 151 | 'update' => 1, # switched off/on with maintainer config ALLOW_UPDATE |
217 | 130 | $debugger{'sys'} = 1; | 152 | 'weather' => 1, # switched off/on with maintainer config ALLOW_WEATHER |
218 | 131 | $client{'test-konvi'} = 0; | 153 | ); |
219 | 132 | 154 | ||
220 | 133 | ######################################################################## | 155 | ######################################################################## |
221 | 134 | #### STARTUP | 156 | #### STARTUP |
222 | @@ -139,28 +161,29 @@ $client{'test-konvi'} = 0; | |||
223 | 139 | #### ------------------------------------------------------------------- | 161 | #### ------------------------------------------------------------------- |
224 | 140 | 162 | ||
225 | 141 | sub main { | 163 | sub main { |
248 | 142 | # print Dumper \@ARGV; | 164 | # print Dumper \@ARGV; |
249 | 143 | eval $start if $b_log; | 165 | eval $start if $b_log; |
250 | 144 | initialize(); | 166 | initialize(); |
251 | 145 | ## use for start client debugging | 167 | ## Uncomment these two values for start client debugging |
252 | 146 | # $debug = 10; # 3 prints timers | 168 | # $debugger{'level'} = 3; # 3 prints timers / 10 prints to log file |
253 | 147 | # set_debugger(); # for debugging of konvi issues | 169 | # set_debugger(); # for debugging of konvi and other start client issues |
254 | 148 | #my $ob_start = StartClient->new(); | 170 | ## legacy method |
255 | 149 | #$ob_start->get_client_data(); | 171 | # my $ob_start = StartClient->new(); |
256 | 150 | StartClient::get_client_data(); | 172 | #$ob_start->get_client_data(); |
257 | 151 | # print_line( Dumper \%client); | 173 | StartClient::set(); |
258 | 152 | get_options(); | 174 | # print_line(Dumper \%client); |
259 | 153 | set_debugger(); # right after so it's set | 175 | OptionsHandler::get(); |
260 | 154 | check_tools(); | 176 | set_debugger(); # right after so it's set |
261 | 155 | set_colors(); | 177 | CheckTools::set(); |
262 | 156 | set_sep(); | 178 | set_colors(); |
263 | 157 | # print download_file('stdout','https://') . "\n"; | 179 | set_sep(); |
264 | 158 | generate_lines(); | 180 | # print download_file('stdout','https://') . "\n"; |
265 | 159 | eval $end if $b_log; | 181 | OutputGenerator::generate(); |
266 | 160 | cleanup(); | 182 | eval $end if $b_log; |
267 | 161 | # weechat's executor plugin forced me to do this, and rightfully so, | 183 | cleanup(); |
268 | 162 | # because else the exit code from the last command is taken.. | 184 | # weechat's executor plugin forced me to do this, and rightfully so, |
269 | 163 | exit 0; | 185 | # because else the exit code from the last command is taken.. |
270 | 186 | exit 0; | ||
271 | 164 | } | 187 | } |
272 | 165 | 188 | ||
273 | 166 | #### ------------------------------------------------------------------- | 189 | #### ------------------------------------------------------------------- |
274 | @@ -168,417 +191,515 @@ sub main { | |||
275 | 168 | #### ------------------------------------------------------------------- | 191 | #### ------------------------------------------------------------------- |
276 | 169 | 192 | ||
277 | 170 | sub initialize { | 193 | sub initialize { |
437 | 171 | set_os(); | 194 | set_os(); |
438 | 172 | set_path(); | 195 | set_path(); |
439 | 173 | set_user_paths(); | 196 | set_user_paths(); |
440 | 174 | set_basics(); | 197 | set_basics(); |
441 | 175 | system_files('set'); | 198 | set_system_files(); |
442 | 176 | get_configs(); | 199 | Configs::set(); |
443 | 177 | # set_downloader(); | 200 | # set_downloader(); |
444 | 178 | set_display_width('live'); | 201 | set_display_width('live'); |
445 | 179 | } | 202 | } |
446 | 180 | 203 | ||
447 | 181 | sub check_tools { | 204 | ## CheckTools |
448 | 182 | my ($action,$program,$message,@data,%commands,%hash); | 205 | { |
449 | 183 | if ( $b_dmi ){ | 206 | package CheckTools; |
450 | 184 | $action = 'use'; | 207 | my (%commands); |
451 | 185 | if ($program = check_program('dmidecode')) { | 208 | sub set { |
452 | 186 | @data = grabber("$program -t chassis -t baseboard -t processor 2>&1"); | 209 | eval $start if $b_log; |
453 | 187 | if (scalar @data < 15){ | 210 | set_commands(); |
454 | 188 | if ($b_root) { | 211 | my ($action,$program,$message,@data); |
455 | 189 | foreach (@data){ | 212 | foreach my $test (keys %commands){ |
456 | 190 | if ($_ =~ /No SMBIOS/i){ | 213 | ($action,$program) = ('use',''); |
457 | 191 | $action = 'smbios'; | 214 | $message = main::row_defaults('tool-present'); |
458 | 192 | last; | 215 | if ($commands{$test}->[1] && ( |
459 | 193 | } | 216 | ($commands{$test}->[1] eq 'linux' && $os ne 'linux') || |
460 | 194 | elsif ($_ =~ /^\/dev\/mem: Operation/i){ | 217 | ($commands{$test}->[1] eq 'bsd' && $os eq 'linux'))){ |
461 | 195 | $action = 'no-data'; | 218 | $action = 'platform'; |
462 | 196 | last; | 219 | } |
463 | 197 | } | 220 | elsif ($program = main::check_program($test)){ |
464 | 198 | else { | 221 | # > 0 means error in shell |
465 | 199 | $action = 'unknown-error'; | 222 | # my $cmd = "$program $commands{$test} >/dev/null"; |
466 | 200 | last; | 223 | # print "$cmd\n"; |
467 | 201 | } | 224 | $pci_tool = $test if $test =~ /pci/; |
468 | 202 | } | 225 | if ($commands{$test}->[0] eq 'exec-sys'){ |
469 | 203 | } | 226 | $action = 'permissions' if system("$program $commands{$test}->[2] >/dev/null 2>&1"); |
470 | 204 | else { | 227 | } |
471 | 205 | if (grep { $_ =~ /^\/dev\/mem: Permission/i } @data){ | 228 | elsif ($commands{$test}->[0] eq 'exec-string'){ |
472 | 206 | $action = 'permissions'; | 229 | @data = main::grabber("$program $commands{$test}->[2] 2>&1"); |
473 | 207 | } | 230 | # dmidecode errors are so specific it gets its own section |
474 | 208 | else { | 231 | # also sets custom dmidecode error messages |
475 | 209 | $action = 'unknown-error'; | 232 | if ($test eq 'dmidecode'){ |
476 | 210 | } | 233 | $action = set_dmidecode(\@data) if scalar @data < 15; |
477 | 211 | } | 234 | } |
478 | 212 | } | 235 | elsif (grep { $_ =~ /$commands{$test}->[3]/i } @data){ |
479 | 213 | } | 236 | $action = 'permissions'; |
480 | 214 | else { | 237 | } |
481 | 215 | $action = 'missing'; | 238 | } |
482 | 216 | } | 239 | } |
483 | 217 | %hash = ( | 240 | else { |
484 | 218 | 'dmidecode' => { | 241 | $action = 'missing'; |
485 | 219 | 'action' => $action, | 242 | } |
486 | 220 | 'missing' => 'Required program dmidecode not available', | 243 | $alerts{$test}->{'action'} = $action; |
487 | 221 | 'permissions' => 'Unable to run dmidecode. Are you root?', | 244 | $alerts{$test}->{'path'} = $program; |
488 | 222 | 'smbios' => 'No SMBIOS data for dmidecode to process', | 245 | if ($action eq 'missing'){ |
489 | 223 | 'no-data' => 'dmidecode is not allowed to read /dev/mem', | 246 | $alerts{$test}->{'message'} = main::row_defaults('tool-missing-recommends',"$test"); |
490 | 224 | 'unknown-error' => 'dmidecode was unable to generate data', | 247 | } |
491 | 225 | }, | 248 | elsif ($action eq 'permissions'){ |
492 | 226 | ); | 249 | $alerts{$test}->{'message'} = main::row_defaults('tool-permissions',"$test"); |
493 | 227 | %alerts = (%alerts, %hash); | 250 | } |
494 | 228 | } | 251 | elsif ($action eq 'platform'){ |
495 | 229 | # note: gnu/linux has sysctl so it may be used that for something if present | 252 | $alerts{$test}->{'message'} = main::row_defaults('tool-missing-os', $uname[0] . " $test"); |
496 | 230 | # there is lspci for bsds so doesn't hurt to check it | 253 | } |
497 | 231 | if ($b_pci || $b_sysctl){ | 254 | } |
498 | 232 | if (!$bsd_type){ | 255 | print Data::Dumper::Dumper \%alerts if $dbg[25]; |
499 | 233 | if ($b_pci ){ | 256 | set_fake_bsd_tools() if $fake{'bsd'}; |
500 | 234 | %hash = ('lspci' => '-n',); | 257 | set_forced_tools(); |
501 | 235 | %commands = (%commands,%hash); | 258 | eval $end if $b_log; |
502 | 236 | } | 259 | } |
503 | 237 | } | 260 | sub set_dmidecode { |
504 | 238 | else { | 261 | my ($data) = @_; |
505 | 239 | if ($b_pci ){ | 262 | my $action = 'use'; |
506 | 240 | %hash = ('pciconf' => '-l','pcictl' => 'list', 'pcidump' => ''); | 263 | if ($b_root){ |
507 | 241 | %commands = (%commands,%hash); | 264 | foreach (@$data){ |
508 | 242 | } | 265 | # don't need first line or scanning /dev/mem lines |
509 | 243 | if ($b_sysctl ){ | 266 | if (/^(# dmi|Scanning)/){ |
510 | 244 | # note: there is a case of kernel.osrelease but it's a linux distro | 267 | next; |
511 | 245 | %hash = ('sysctl' => 'kern.osrelease',); | 268 | } |
512 | 246 | %commands = (%commands,%hash); | 269 | elsif ($_ =~ /No SMBIOS/i){ |
513 | 247 | } | 270 | $action = 'smbios'; |
514 | 248 | } | 271 | last; |
515 | 249 | foreach ( keys %commands ){ | 272 | } |
516 | 250 | $action = 'use'; | 273 | elsif ($_ =~ /^\/dev\/mem: Operation/i){ |
517 | 251 | if ($program = check_program($_)) { | 274 | $action = 'no-data'; |
518 | 252 | # > 0 means error in shell | 275 | last; |
519 | 253 | #my $cmd = "$program $commands{$_} >/dev/null"; | 276 | } |
520 | 254 | #print "$cmd\n"; | 277 | else { |
521 | 255 | $pci_tool = $_ if $_ =~ /pci/; | 278 | $action = 'unknown-error'; |
522 | 256 | $action = 'permissions' if system("$program $commands{$_} >/dev/null 2>&1"); | 279 | last; |
523 | 257 | } | 280 | } |
524 | 258 | else { | 281 | } |
525 | 259 | $action = 'missing'; | 282 | } |
526 | 260 | } | 283 | else { |
527 | 261 | %hash = ( | 284 | if (grep { $_ =~ /^\/dev\/mem: Permission/i } @$data){ |
528 | 262 | $_ => { | 285 | $action = 'permissions'; |
529 | 263 | 'action' => $action, | 286 | } |
530 | 264 | 'missing' => "Missing system tool: $_. Output will be incomplete", | 287 | else { |
531 | 265 | 'permissions' => "Unable to run $_. Root required?", | 288 | $action = 'unknown-error'; |
532 | 266 | }, | 289 | } |
533 | 267 | ); | 290 | } |
534 | 268 | %alerts = (%alerts, %hash); | 291 | if ($action ne 'use' && $action ne 'permissions'){ |
535 | 269 | } | 292 | if ($action eq 'smbios'){ |
536 | 270 | } | 293 | $alerts{'dmidecode'}->{'message'} = main::row_defaults('dmidecode-smbios'); |
537 | 271 | %commands = (); | 294 | } |
538 | 272 | if ( $show{'sensor'} ){ | 295 | elsif ($action eq 'no-data'){ |
539 | 273 | %commands = ('sensors' => 'linux',); | 296 | $alerts{'dmidecode'}->{'message'} = main::row_defaults('dmidecode-dev-mem'); |
540 | 274 | } | 297 | } |
541 | 275 | # note: lsusb ships in FreeBSD ports sysutils/usbutils | 298 | elsif ($action eq 'unknown-error'){ |
542 | 276 | if ( $b_usb ){ | 299 | $alerts{'dmidecode'}->{'message'} = main::row_defaults('tool-unknown-error','dmidecode'); |
543 | 277 | %hash = ('lsusb' => 'all',); | 300 | } |
544 | 278 | %commands = (%commands,%hash); | 301 | } |
545 | 279 | %hash = ('usbdevs' => 'bsd',); | 302 | return $action; |
546 | 280 | %commands = (%commands,%hash); | 303 | } |
547 | 281 | } | 304 | sub set_commands { |
548 | 282 | if ($show{'ip'} || ($bsd_type && $show{'network-advanced'})){ | 305 | # note: gnu/linux has sysctl so it may be used that for something if present |
549 | 283 | %hash = ( | 306 | # there is lspci for bsds so doesn't hurt to check it |
550 | 284 | 'ip' => 'linux', | 307 | if (!$bsd_type){ |
551 | 285 | 'ifconfig' => 'all', | 308 | if ($use{'pci'}){ |
552 | 286 | ); | 309 | $commands{'lspci'} = ['exec-sys','','-n']; |
553 | 287 | %commands = (%commands,%hash); | 310 | } |
554 | 288 | } | 311 | if ($use{'logical'}){ |
555 | 289 | # can't check permissions since we need to know the partition | 312 | $commands{'lvs'} = ['exec-sys','','']; |
556 | 290 | if ($b_block_tool){ | 313 | } |
557 | 291 | %hash = ( | 314 | } |
558 | 292 | 'blockdev' => 'linux', | 315 | else { |
559 | 293 | 'lsblk' => 'linux', | 316 | if ($use{'pci'}){ |
560 | 294 | ); | 317 | $commands{'pciconf'} = ['exec-sys','','-l']; |
561 | 295 | %commands = (%commands,%hash); | 318 | $commands{'pcictl'} = ['exec-sys','',' pci0 list']; |
562 | 296 | } | 319 | $commands{'pcidump'} = ['exec-sys','','']; |
563 | 297 | foreach ( keys %commands ){ | 320 | } |
564 | 298 | $action = 'use'; | 321 | if ($use{'sysctl'}){ |
565 | 299 | $message = 'Present and working'; | 322 | # note: there is a case of kernel.osrelease but it's a linux distro |
566 | 300 | if ( ($commands{$_} eq 'linux' && $os ne 'linux' ) || ($commands{$_} eq 'bsd' && $os eq 'linux' ) ){ | 323 | $commands{'sysctl'} = ['exec-sys','','kern.osrelease']; |
567 | 301 | $message = "No " . ucfirst($os) . " support. Is a comparable $_ tool available?"; | 324 | } |
568 | 302 | $action = 'platform'; | 325 | if ($use{'bsd-partition'}){ |
569 | 303 | } | 326 | $commands{'bioctl'} = ['missing','','']; |
570 | 304 | elsif (!check_program($_)){ | 327 | $commands{'disklabel'} = ['missing','','']; |
571 | 305 | $message = "Required tool $_ not installed. Check --recommends"; | 328 | $commands{'fdisk'} = ['missing','','']; |
572 | 306 | $action = 'missing'; | 329 | $commands{'gpart'} = ['missing','','']; |
573 | 307 | } | 330 | } |
574 | 308 | %hash = ( | 331 | } |
575 | 309 | $_ => { | 332 | if ($use{'dmidecode'}){ |
576 | 310 | 'action' => $action, | 333 | $commands{'dmidecode'} = ['exec-string','','-t chassis -t baseboard -t processor','']; |
577 | 311 | 'missing' => $message, | 334 | } |
578 | 312 | 'platform' => $message, | 335 | if ($use{'usb'}){ |
579 | 313 | }, | 336 | # note: lsusb ships in FreeBSD ports sysutils/usbutils |
580 | 314 | ); | 337 | $commands{'lsusb'} = ['missing','','','']; |
581 | 315 | %alerts = (%alerts, %hash); | 338 | # we want these set for various null bsd data tests |
582 | 316 | } | 339 | $commands{'usbconfig'} = ['exec-string','bsd','list','permissions']; |
583 | 317 | # print Dumper \%alerts; | 340 | $commands{'usbdevs'} = ['missing','bsd','','']; |
584 | 318 | # only use sudo if not root, -n option requires sudo -V 1.7 or greater. | 341 | } |
585 | 319 | # for some reason sudo -n with < 1.7 in Perl does not print to stderr | 342 | if ($show{'bluetooth'}){ |
586 | 320 | # sudo will just error out which is the safest course here for now, | 343 | $commands{'bluetoothctl'} = ['missing','linux','','']; |
587 | 321 | # otherwise that interactive sudo password thing is too annoying | 344 | # bt-adapter hangs when bluetooth service is disabled |
588 | 322 | # important: -n makes it non interactive, no prompt for password | 345 | $commands{'bt-adapter'} = ['missing','linux','','']; |
589 | 323 | if (!$b_root && $b_sudo && (my $path = main::check_program('sudo') )) { | 346 | $commands{'hciconfig'} = ['missing','linux','','']; |
590 | 324 | my @data = program_values('sudo'); | 347 | } |
591 | 325 | my $version = program_version($path,$data[0],$data[1],$data[2],$data[5]); | 348 | if ($show{'sensor'}){ |
592 | 326 | $version =~ s/^([0-9]+\.[0-9]+).*/$1/; | 349 | $commands{'sensors'} = ['missing','linux','','']; |
593 | 327 | $sudo = "$path -n " if $version >= 1.7; | 350 | } |
594 | 328 | } | 351 | if ($show{'ip'} || ($bsd_type && $show{'network-advanced'})){ |
595 | 329 | set_fake_tools() if $b_fake_bsd; | 352 | $commands{'ip'} = ['missing','linux','','']; |
596 | 353 | $commands{'ifconfig'} = ['missing','','','']; | ||
597 | 354 | } | ||
598 | 355 | # can't check permissions since we need to know the partition/disc | ||
599 | 356 | if ($use{'block-tool'}){ | ||
600 | 357 | $commands{'blockdev'} = ['missing','linux','','']; | ||
601 | 358 | $commands{'lsblk'} = ['missing','linux','','']; | ||
602 | 359 | } | ||
603 | 360 | if ($use{'btrfs'}){ | ||
604 | 361 | $commands{'btrfs'} = ['missing','linux','','']; | ||
605 | 362 | } | ||
606 | 363 | if ($use{'mdadm'}){ | ||
607 | 364 | $commands{'mdadm'} = ['missing','linux','','']; | ||
608 | 365 | } | ||
609 | 366 | if ($use{'smartctl'}){ | ||
610 | 367 | $commands{'smartctl'} = ['missing','','','']; | ||
611 | 368 | } | ||
612 | 369 | if ($show{'unmounted'}){ | ||
613 | 370 | $commands{'disklabel'} = ['missing','bsd','xx']; | ||
614 | 371 | } | ||
615 | 372 | } | ||
616 | 373 | sub set_forced_tools { | ||
617 | 374 | if ($bt_tool){ | ||
618 | 375 | if ($bt_tool ne 'bluetootctl' && $alerts{'bluetoothctl'}->{'action'} eq 'use'){ | ||
619 | 376 | $alerts{'bluetoothctl'}->{'action'} = 'missing'; | ||
620 | 377 | } | ||
621 | 378 | if ($bt_tool ne 'bt-adapter' && $alerts{'bt-adapter'}->{'action'} eq 'use'){ | ||
622 | 379 | $alerts{'bt-adapter'}->{'action'} = 'missing'; | ||
623 | 380 | } | ||
624 | 381 | if ($bt_tool ne 'hciconfig' && $alerts{'hciconfig'}->{'action'} eq 'use'){ | ||
625 | 382 | $alerts{'hciconfig'}->{'action'} = 'missing'; | ||
626 | 383 | } | ||
627 | 384 | } | ||
628 | 385 | } | ||
629 | 386 | # only for dev/debugging BSD | ||
630 | 387 | sub set_fake_bsd_tools { | ||
631 | 388 | $system_files{'dmesg-boot'} = '/var/run/dmesg.boot' if $fake{'dboot'}; | ||
632 | 389 | $alerts{'sysctl'}->{'action'} = 'use' if $fake{'sysctl'}; | ||
633 | 390 | if ($fake{'pciconf'} || $fake{'pcictl'} || $fake{'pcidump'}){ | ||
634 | 391 | $alerts{'pciconf'}->{'action'} = 'use' if $fake{'pciconf'}; | ||
635 | 392 | $alerts{'pcictl'}->{'action'} = 'use' if $fake{'pcictl'}; | ||
636 | 393 | $alerts{'pcidump'}->{'action'} = 'use' if $fake{'pcidump'}; | ||
637 | 394 | $alerts{'lspci'} = { | ||
638 | 395 | 'action' => 'missing', | ||
639 | 396 | 'message' => 'Required program lspci not available', | ||
640 | 397 | }; | ||
641 | 398 | } | ||
642 | 399 | if ($fake{'usbconfig'} || $fake{'usbdevs'}){ | ||
643 | 400 | $alerts{'usbconfig'}->{'action'} = 'use' if $fake{'usbconfig'}; | ||
644 | 401 | $alerts{'usbdevs'}->{'action'} = 'use' if $fake{'usbdevs'}; | ||
645 | 402 | $alerts{'lsusb'} = { | ||
646 | 403 | 'action' => 'missing', | ||
647 | 404 | 'message' => 'Required program lsusb not available', | ||
648 | 405 | }; | ||
649 | 406 | } | ||
650 | 407 | if ($fake{'disklabel'}){ | ||
651 | 408 | $alerts{'disklabel'}->{'action'} = 'use'; | ||
652 | 409 | } | ||
653 | 410 | } | ||
654 | 330 | } | 411 | } |
655 | 331 | 412 | ||
656 | 332 | # args: 1 - desktop/app command for --version; 2 - search string; | 413 | # args: 1 - desktop/app command for --version; 2 - search string; |
657 | 333 | # 3 - space print number; 4 - [optional] version arg: -v, version, etc | 414 | # 3 - space print number; 4 - [optional] version arg: -v, version, etc |
658 | 334 | # 5 - [optional] exit first find 0/1; 6 - [optional] 0/1 stderr output | 415 | # 5 - [optional] exit first find 0/1; 6 - [optional] 0/1 stderr output |
659 | 335 | sub set_basics { | 416 | sub set_basics { |
686 | 336 | ### LOCALIZATION - DO NOT CHANGE! ### | 417 | ### LOCALIZATION - DO NOT CHANGE! ### |
687 | 337 | # set to default LANG to avoid locales errors with , or . | 418 | # set to default LANG to avoid locales errors with , or . |
688 | 338 | # Make sure every program speaks English. | 419 | # Make sure every program speaks English. |
689 | 339 | $ENV{'LANG'}='C'; | 420 | $ENV{'LANG'}='C'; |
690 | 340 | $ENV{'LC_ALL'}='C'; | 421 | $ENV{'LC_ALL'}='C'; |
691 | 341 | # remember, perl uses the opposite t/f return as shell!!! | 422 | # remember, perl uses the opposite t/f return as shell!!! |
692 | 342 | # some versions of busybox do not have tty, like openwrt | 423 | # some versions of busybox do not have tty, like openwrt |
693 | 343 | $b_irc = ( check_program('tty') && system('tty >/dev/null') ) ? 1 : 0; | 424 | $b_irc = (check_program('tty') && system('tty >/dev/null')) ? 1 : 0; |
694 | 344 | # print "birc: $b_irc\n"; | 425 | # print "birc: $b_irc\n"; |
695 | 345 | $b_display = ( $ENV{'DISPLAY'} ) ? 1 : 0; | 426 | $b_display = ($ENV{'DISPLAY'}) ? 1 : 0; |
696 | 346 | $b_root = ( $ENV{'HOME'} eq '/root' ) ? 1 : 0; | 427 | $b_root = $< == 0; # root UID 0, all others > 0 |
697 | 347 | $dl{'dl'} = 'curl'; | 428 | $dl{'dl'} = 'curl'; |
698 | 348 | $dl{'curl'} = 1; | 429 | $dl{'curl'} = 1; |
699 | 349 | $dl{'tiny'} = 1; # note: two modules needed, tested for in set_downloader | 430 | $dl{'tiny'} = 1; # note: two modules needed, tested for in set_downloader |
700 | 350 | $dl{'wget'} = 1; | 431 | $dl{'wget'} = 1; |
701 | 351 | $dl{'fetch'} = 1; | 432 | $dl{'fetch'} = 1; |
702 | 352 | $client{'console-irc'} = 0; | 433 | $client{'console-irc'} = 0; |
703 | 353 | $client{'dcop'} = (check_program('dcop')) ? 1 : 0; | 434 | $client{'dcop'} = (check_program('dcop')) ? 1 : 0; |
704 | 354 | $client{'qdbus'} = (check_program('qdbus')) ? 1 : 0; | 435 | $client{'qdbus'} = (check_program('qdbus')) ? 1 : 0; |
705 | 355 | $client{'konvi'} = 0; | 436 | $client{'konvi'} = 0; |
706 | 356 | $client{'name'} = ''; | 437 | $client{'name'} = ''; |
707 | 357 | $client{'name-print'} = ''; | 438 | $client{'name-print'} = ''; |
708 | 358 | $client{'su-start'} = ''; # shows sudo/su | 439 | $client{'su-start'} = ''; # shows sudo/su |
709 | 359 | $client{'version'} = ''; | 440 | $client{'version'} = ''; |
710 | 360 | $colors{'default'} = 2; | 441 | $colors{'default'} = 2; |
711 | 361 | $show{'partition-sort'} = 'id'; # sort order for partitions | 442 | $show{'partition-sort'} = 'id'; # sort order for partitions |
712 | 443 | @raw_logical = (0,0,0); | ||
713 | 444 | $ppid = getppid(); | ||
714 | 362 | } | 445 | } |
715 | 363 | 446 | ||
716 | 364 | # args: $1 - default OR override default cols max integer count. $_[0] | 447 | # args: $1 - default OR override default cols max integer count. $_[0] |
717 | 365 | # is the display width override. | 448 | # is the display width override. |
718 | 366 | sub set_display_width { | 449 | sub set_display_width { |
775 | 367 | my ($width) = @_; | 450 | my ($width) = @_; |
776 | 368 | if ( $width eq 'live' ){ | 451 | if ($width eq 'live'){ |
777 | 369 | ## sometimes tput will trigger an error (mageia) if irc client | 452 | ## sometimes tput will trigger an error (mageia) if irc client |
778 | 370 | if ( ! $b_irc ){ | 453 | if (!$b_irc){ |
779 | 371 | if ( check_program('tput') ) { | 454 | if (my $program = check_program('tput')){ |
780 | 372 | # trips error if use qx()... | 455 | # Arch urxvt: 'tput: unknown terminal "rxvt-unicode-256color"' |
781 | 373 | chomp($size{'term'}=qx{tput cols}); | 456 | # trips error if use qx(); in FreeBSD, if you use 2>/dev/null |
782 | 374 | chomp($size{'term-lines'}=qx{tput lines}); | 457 | # it makes default value 80x24, who knows why? |
783 | 375 | $size{'term-cols'} = $size{'term'}; | 458 | chomp($size{'term'} = qx{$program cols}); |
784 | 376 | } | 459 | chomp($size{'term-lines'} = qx{$program lines}); |
785 | 377 | # print "tc: $size{'term'} cmc: $size{'console'}\n"; | 460 | $size{'term-cols'} = $size{'term'}; |
786 | 378 | # double check, just in case it's missing functionality or whatever | 461 | } |
787 | 379 | if ( $size{'term'} == 0 || $size{'term'} !~ /\d/ ){ | 462 | # print "tc: $size{'term'} cmc: $size{'console'}\n"; |
788 | 380 | $size{'term'}=80; | 463 | # double check, just in case it's missing functionality or whatever |
789 | 381 | # we'll be using this for terminal dimensions later so don't set default. | 464 | if (!is_int($size{'term'} || $size{'term'} == 0)){ |
790 | 382 | # $size{'term-lines'}=100; | 465 | $size{'term'}=80; |
791 | 383 | } | 466 | # we'll be using this for terminal dimensions later so don't set default. |
792 | 384 | } | 467 | # $size{'term-lines'}=100; |
793 | 385 | # this lets you set different size for in or out of display server | 468 | } |
794 | 386 | if ( ! $b_running_in_display && $size{'no-display'} ){ | 469 | } |
795 | 387 | $size{'console'}=$size{'no-display'}; | 470 | # this lets you set different size for in or out of display server |
796 | 388 | } | 471 | if (!$b_running_in_display && $size{'no-display'}){ |
797 | 389 | # term_cols is set in top globals, using tput cols | 472 | $size{'console'} = $size{'no-display'}; |
798 | 390 | # print "tc: $size{'term'} cmc: $size{'console'}\n"; | 473 | } |
799 | 391 | if ( $size{'term'} < $size{'console'} ){ | 474 | # term_cols is set in top globals, using tput cols |
800 | 392 | $size{'console'}=$size{'term'}; | 475 | # print "tc: $size{'term'} cmc: $size{'console'}\n"; |
801 | 393 | } | 476 | if ($size{'term'} < $size{'console'}){ |
802 | 394 | # adjust, some terminals will wrap if output cols == term cols | 477 | $size{'console'} = $size{'term'}; |
803 | 395 | $size{'console'}=( $size{'console'} - 2 ); | 478 | } |
804 | 396 | # echo cmc: $size{'console'} | 479 | # adjust, some terminals will wrap if output cols == term cols |
805 | 397 | # comes after source for user set stuff | 480 | $size{'console'} = ($size{'console'} - 2); |
806 | 398 | if ( ! $b_irc ){ | 481 | # echo cmc: $size{'console'} |
807 | 399 | $size{'max'}=$size{'console'}; | 482 | # comes after source for user set stuff |
808 | 400 | } | 483 | if (!$b_irc){ |
809 | 401 | else { | 484 | $size{'max'} = $size{'console'}; |
810 | 402 | $size{'max'}=$size{'irc'}; | 485 | } |
811 | 403 | } | 486 | else { |
812 | 404 | } | 487 | $size{'max'} = $size{'irc'}; |
813 | 405 | else { | 488 | } |
814 | 406 | $size{'max'}=$width; | 489 | } |
815 | 407 | } | 490 | else { |
816 | 408 | # print "tc: $size{'term'} cmc: $size{'console'} cm: $size{'max'}\n"; | 491 | $size{'max'} = $width; |
817 | 409 | } | 492 | } |
818 | 410 | 493 | # print "tc: $size{'term'} cmc: $size{'console'} cm: $size{'max'}\n"; | |
763 | 411 | # only for dev/debugging BSD | ||
764 | 412 | sub set_fake_tools { | ||
765 | 413 | $system_files{'dmesg-boot'} = '/var/run/dmesg.boot' if $b_fake_dboot; | ||
766 | 414 | $alerts{'pciconf'} = ({'action' => 'use'}) if $b_fake_pciconf; | ||
767 | 415 | $alerts{'sysctl'} = ({'action' => 'use'}) if $b_fake_sysctl; | ||
768 | 416 | if ($b_fake_usbdevs ){ | ||
769 | 417 | $alerts{'usbdevs'} = ({'action' => 'use'}); | ||
770 | 418 | $alerts{'lsusb'} = ({ | ||
771 | 419 | 'action' => 'missing', | ||
772 | 420 | 'missing' => 'Required program lsusb not available', | ||
773 | 421 | }); | ||
774 | 422 | } | ||
819 | 423 | } | 494 | } |
820 | 424 | 495 | ||
821 | 425 | # NOTE: most tests internally are against !$bsd_type | 496 | # NOTE: most tests internally are against !$bsd_type |
822 | 426 | sub set_os { | 497 | sub set_os { |
856 | 427 | @uname = uname(); | 498 | @uname = uname(); |
857 | 428 | $os = lc($uname[0]); | 499 | $os = lc($uname[0]); |
858 | 429 | $cpu_arch = lc($uname[-1]); | 500 | $cpu_arch = lc($uname[-1]); |
859 | 430 | if ($cpu_arch =~ /arm|aarch/){$b_arm = 1} | 501 | if ($cpu_arch =~ /arm|aarch/){$b_arm = 1;} |
860 | 431 | elsif ($cpu_arch =~ /mips/) {$b_mips = 1} | 502 | elsif ($cpu_arch =~ /mips/){$b_mips = 1} |
861 | 432 | elsif ($cpu_arch =~ /power|ppc/) {$b_ppc = 1} | 503 | elsif ($cpu_arch =~ /power|ppc/){$b_ppc = 1} |
862 | 433 | elsif ($cpu_arch =~ /sparc/) {$b_sparc = 1} | 504 | elsif ($cpu_arch =~ /sparc/){$b_sparc = 1} |
863 | 434 | # aarch32 mips32 intel/amd handled in cpu | 505 | # aarch32 mips32 intel/amd handled in cpu |
864 | 435 | if ($cpu_arch =~ /(armv[1-7]|32|sparc_v9)/){ | 506 | if ($cpu_arch =~ /(armv[1-7]|32|sparc_v9)/){ |
865 | 436 | $bits_sys = 32; | 507 | $bits_sys = 32; |
866 | 437 | } | 508 | } |
867 | 438 | elsif ($cpu_arch =~ /(alpha|64)/){ | 509 | elsif ($cpu_arch =~ /(alpha|64|e2k)/){ |
868 | 439 | $bits_sys = 64; | 510 | $bits_sys = 64; |
869 | 440 | } | 511 | } |
870 | 441 | if ( $os =~ /(aix|bsd|cosix|dragonfly|darwin|hp-?ux|indiana|irix|sunos|solaris|ultrix|unix)/ ){ | 512 | $b_android = 1 if -e '/system/build.prop'; |
871 | 442 | if ( $os =~ /openbsd/ ){ | 513 | if ($os =~ /(aix|bsd|cosix|dragonfly|darwin|hp-?ux|indiana|irix|sunos|solaris|ultrix|unix)/){ |
872 | 443 | $os = 'openbsd'; | 514 | if ($os =~ /openbsd/){ |
873 | 444 | } | 515 | $os = 'openbsd'; |
874 | 445 | elsif ($os =~ /darwin/){ | 516 | } |
875 | 446 | $os = 'darwin'; | 517 | elsif ($os =~ /darwin/){ |
876 | 447 | } | 518 | $os = 'darwin'; |
877 | 448 | if ($os =~ /kfreebsd/){ | 519 | } |
878 | 449 | $bsd_type = 'debian-bsd'; | 520 | if ($os =~ /kfreebsd/){ |
879 | 450 | } | 521 | $bsd_type = 'debian-bsd'; |
880 | 451 | else { | 522 | } |
881 | 452 | $bsd_type = $os; | 523 | else { |
882 | 453 | } | 524 | $bsd_type = $os; |
883 | 454 | } | 525 | } |
884 | 455 | } | 526 | } |
885 | 456 | 527 | } | |
886 | 457 | # This data is hard set top of program but due to a specific project's | 528 | |
887 | 458 | # foolish idea that ignoring the FSH totally is somehow a positive step | 529 | # Sometimes users will have more PATHs local to their setup, so we want those |
888 | 459 | # forwards for free software, we also have to padd the results with PATH. | 530 | # too. |
889 | 460 | sub set_path { | 531 | sub set_path { |
904 | 461 | # Extra path variable to make execute failures less likely, merged below | 532 | # Extra path variable to make execute failures less likely, merged below |
905 | 462 | my (@path); | 533 | my (@path); |
906 | 463 | # NOTE: recent Xorg's show error if you try /usr/bin/Xorg -version but work | 534 | # NOTE: recent Xorg's show error if you try /usr/bin/Xorg -version but work |
907 | 464 | # if you use the /usr/lib/xorg-server/Xorg path. | 535 | # if you use the /usr/lib/xorg-server/Xorg path. |
908 | 465 | @paths = qw(/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin); | 536 | @paths = qw(/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin); |
909 | 466 | @path = split /:/, $ENV{'PATH'} if $ENV{'PATH'}; | 537 | @path = split(':', $ENV{'PATH'}) if $ENV{'PATH'}; |
910 | 467 | # print "paths: @paths\nPATH: $ENV{'PATH'}\n"; | 538 | # print "paths: @paths\nPATH: $ENV{'PATH'}\n"; |
911 | 468 | # Create a difference of $PATH and $extra_paths and add that to $PATH: | 539 | # Create a difference of $PATH and $extra_paths and add that to $PATH: |
912 | 469 | foreach my $id (@path) { | 540 | foreach my $id (@path){ |
913 | 470 | if ( !(grep { /^$id$/ } @paths) && $id !~ /(game)/ ){ | 541 | if (!(grep { /^$id$/ } @paths) && $id !~ /(game)/){ |
914 | 471 | push @paths, $id; | 542 | push(@paths, $id); |
915 | 472 | } | 543 | } |
916 | 473 | } | 544 | } |
917 | 474 | # print "paths: @paths\n"; | 545 | # print "paths: @paths\n"; |
918 | 475 | } | 546 | } |
919 | 476 | 547 | ||
920 | 477 | sub set_sep { | 548 | sub set_sep { |
936 | 478 | if ( $b_irc ){ | 549 | if ($b_irc){ |
937 | 479 | # too hard to read if no colors, so force that for users on irc | 550 | # too hard to read if no colors, so force that for users on irc |
938 | 480 | if ($colors{'scheme'} == 0 ){ | 551 | if ($colors{'scheme'} == 0){ |
939 | 481 | $sep{'s1'} = $sep{'s1-console'}; | 552 | $sep{'s1'} = $sep{'s1-console'}; |
940 | 482 | $sep{'s2'} = $sep{'s2-console'}; | 553 | $sep{'s2'} = $sep{'s2-console'}; |
941 | 483 | } | 554 | } |
942 | 484 | else { | 555 | else { |
943 | 485 | $sep{'s1'} = $sep{'s1-irc'}; | 556 | $sep{'s1'} = $sep{'s1-irc'}; |
944 | 486 | $sep{'s2'} = $sep{'s2-irc'}; | 557 | $sep{'s2'} = $sep{'s2-irc'}; |
945 | 487 | } | 558 | } |
946 | 488 | } | 559 | } |
947 | 489 | else { | 560 | else { |
948 | 490 | $sep{'s1'} = $sep{'s1-console'}; | 561 | $sep{'s1'} = $sep{'s1-console'}; |
949 | 491 | $sep{'s2'} = $sep{'s2-console'}; | 562 | $sep{'s2'} = $sep{'s2-console'}; |
950 | 492 | } | 563 | } |
951 | 564 | } | ||
952 | 565 | |||
953 | 566 | # Important: -n makes it non interactive, no prompt for password | ||
954 | 567 | # only use doas/sudo if not root, -n option requires sudo -V 1.7 or greater. | ||
955 | 568 | # for some reason sudo -n with < 1.7 in Perl does not print to stderr | ||
956 | 569 | # sudo will just error out which is the safest course here for now, | ||
957 | 570 | # otherwise that interactive sudo password thing is too annoying | ||
958 | 571 | sub set_sudo { | ||
959 | 572 | if (!$b_root){ | ||
960 | 573 | my ($path); | ||
961 | 574 | if (!$force{'no-doas'} && ($path = check_program('doas'))){ | ||
962 | 575 | $sudoas = "$path -n "; | ||
963 | 576 | } | ||
964 | 577 | elsif (!$force{'no-sudo'} && ($path = check_program('sudo'))){ | ||
965 | 578 | my @data = program_data('sudo'); | ||
966 | 579 | $data[1] =~ s/^([0-9]+\.[0-9]+).*/$1/; | ||
967 | 580 | # print "sudo v: $data[1]\n"; | ||
968 | 581 | $sudoas = "$path -n " if is_numeric($data[1]) && $data[1] >= 1.7; | ||
969 | 582 | } | ||
970 | 583 | } | ||
971 | 584 | } | ||
972 | 585 | |||
973 | 586 | sub set_system_files { | ||
974 | 587 | my %files = ( | ||
975 | 588 | 'asound-cards' => '/proc/asound/cards', | ||
976 | 589 | 'asound-modules' => '/proc/asound/modules', | ||
977 | 590 | 'asound-version' => '/proc/asound/version', | ||
978 | 591 | 'dmesg-boot' => '/var/run/dmesg.boot', | ||
979 | 592 | 'proc-cmdline' => '/proc/cmdline', | ||
980 | 593 | 'proc-cpuinfo' => '/proc/cpuinfo', | ||
981 | 594 | 'proc-mdstat' => '/proc/mdstat', | ||
982 | 595 | 'proc-meminfo' => '/proc/meminfo', | ||
983 | 596 | 'proc-modules' => '/proc/modules', # not used | ||
984 | 597 | 'proc-mounts' => '/proc/mounts',# not used | ||
985 | 598 | 'proc-partitions' => '/proc/partitions', | ||
986 | 599 | 'proc-scsi' => '/proc/scsi/scsi', | ||
987 | 600 | 'proc-version' => '/proc/version', | ||
988 | 601 | # note: 'xorg-log' is set in set_xorg_log() only if -G is triggered | ||
989 | 602 | ); | ||
990 | 603 | foreach (keys %files){ | ||
991 | 604 | $system_files{$_} = (-e $files{$_}) ? $files{$_} : ''; | ||
992 | 605 | } | ||
993 | 493 | } | 606 | } |
994 | 494 | 607 | ||
995 | 495 | sub set_user_paths { | 608 | sub set_user_paths { |
1082 | 496 | my ( $b_conf, $b_data ); | 609 | my ($b_conf,$b_data); |
1083 | 497 | # this needs to be set here because various options call the parent | 610 | # this needs to be set here because various options call the parent |
1084 | 498 | # initialize function directly. | 611 | # initialize function directly. |
1085 | 499 | $self_path = $0; | 612 | $self_path = $0; |
1086 | 500 | $self_path =~ s/[^\/]+$//; | 613 | $self_path =~ s/[^\/]+$//; |
1087 | 501 | # print "0: $0 sp: $self_path\n"; | 614 | # print "0: $0 sp: $self_path\n"; |
1088 | 502 | 615 | if (defined $ENV{'XDG_CONFIG_HOME'} && $ENV{'XDG_CONFIG_HOME'}){ | |
1089 | 503 | if ( defined $ENV{'XDG_CONFIG_HOME'} && $ENV{'XDG_CONFIG_HOME'} ){ | 616 | $user_config_dir=$ENV{'XDG_CONFIG_HOME'}; |
1090 | 504 | $user_config_dir=$ENV{'XDG_CONFIG_HOME'}; | 617 | $b_conf=1; |
1091 | 505 | $b_conf=1; | 618 | } |
1092 | 506 | } | 619 | elsif (-d "$ENV{'HOME'}/.config"){ |
1093 | 507 | elsif ( -d "$ENV{'HOME'}/.config" ){ | 620 | $user_config_dir="$ENV{'HOME'}/.config"; |
1094 | 508 | $user_config_dir="$ENV{'HOME'}/.config"; | 621 | $b_conf=1; |
1095 | 509 | $b_conf=1; | 622 | } |
1096 | 510 | } | 623 | else { |
1097 | 511 | else { | 624 | $user_config_dir="$ENV{'HOME'}/.$self_name"; |
1098 | 512 | $user_config_dir="$ENV{'HOME'}/.$self_name"; | 625 | } |
1099 | 513 | } | 626 | if (defined $ENV{'XDG_DATA_HOME'} && $ENV{'XDG_DATA_HOME'}){ |
1100 | 514 | if ( defined $ENV{'XDG_DATA_HOME'} && $ENV{'XDG_DATA_HOME'} ){ | 627 | $user_data_dir="$ENV{'XDG_DATA_HOME'}/$self_name"; |
1101 | 515 | $user_data_dir="$ENV{'XDG_DATA_HOME'}/$self_name"; | 628 | $b_data=1; |
1102 | 516 | $b_data=1; | 629 | } |
1103 | 517 | } | 630 | elsif (-d "$ENV{'HOME'}/.local/share"){ |
1104 | 518 | elsif ( -d "$ENV{'HOME'}/.local/share" ){ | 631 | $user_data_dir="$ENV{'HOME'}/.local/share/$self_name"; |
1105 | 519 | $user_data_dir="$ENV{'HOME'}/.local/share/$self_name"; | 632 | $b_data=1; |
1106 | 520 | $b_data=1; | 633 | } |
1107 | 521 | } | 634 | else { |
1108 | 522 | else { | 635 | $user_data_dir="$ENV{'HOME'}/.$self_name"; |
1109 | 523 | $user_data_dir="$ENV{'HOME'}/.$self_name"; | 636 | } |
1110 | 524 | } | 637 | # note, this used to be created/checked in specific instance, but we'll just |
1111 | 525 | # note, this used to be created/checked in specific instance, but we'll just do it | 638 | # do it universally so it's done at script start. |
1112 | 526 | # universally so it's done at script start. | 639 | if (! -d $user_data_dir){ |
1113 | 527 | if ( ! -d $user_data_dir ){ | 640 | mkdir $user_data_dir; |
1114 | 528 | mkdir $user_data_dir; | 641 | # system "echo", "Made: $user_data_dir"; |
1115 | 529 | # system "echo", "Made: $user_data_dir"; | 642 | } |
1116 | 530 | } | 643 | if ($b_conf && -f "$ENV{'HOME'}/.$self_name/$self_name.conf"){ |
1117 | 531 | if ( $b_conf && -f "$ENV{'HOME'}/.$self_name/$self_name.conf" ){ | 644 | # system 'mv', "-f $ENV{'HOME'}/.$self_name/$self_name.conf", $user_config_dir; |
1118 | 532 | #system 'mv', "-f $ENV{'HOME'}/.$self_name/$self_name.conf", $user_config_dir; | 645 | # print "WOULD: Moved $self_name.conf from $ENV{'HOME'}/.$self_name to $user_config_dir\n"; |
1119 | 533 | # print "WOULD: Moved $self_name.conf from $ENV{'HOME'}/.$self_name to $user_config_dir\n"; | 646 | } |
1120 | 534 | } | 647 | if ($b_data && -d "$ENV{'HOME'}/.$self_name"){ |
1121 | 535 | if ( $b_data && -d "$ENV{'HOME'}/.$self_name" ){ | 648 | # system 'mv', '-f', "$ENV{'HOME'}/.$self_name/*", $user_data_dir; |
1122 | 536 | #system 'mv', '-f', "$ENV{'HOME'}/.$self_name/*", $user_data_dir; | 649 | # system 'rm', '-Rf', "$ENV{'HOME'}/.$self_name"; |
1123 | 537 | #system 'rm', '-Rf', "$ENV{'HOME'}/.$self_name"; | 650 | # print "WOULD: Moved data dir $ENV{'HOME'}/.$self_name to $user_data_dir\n"; |
1124 | 538 | # print "WOULD: Moved data dir $ENV{'HOME'}/.$self_name to $user_data_dir\n"; | 651 | } |
1125 | 539 | } | 652 | $log_file="$user_data_dir/$self_name.log"; |
1126 | 540 | $log_file="$user_data_dir/$self_name.log"; | 653 | # system 'echo', "$ENV{'HOME'}/.$self_name/* $user_data_dir"; |
1127 | 541 | #system 'echo', "$ENV{'HOME'}/.$self_name/* $user_data_dir"; | 654 | # print "scd: $user_config_dir sdd: $user_data_dir \n"; |
1128 | 542 | # print "scd: $user_config_dir sdd: $user_data_dir \n"; | 655 | } |
1129 | 543 | } | 656 | |
1130 | 544 | 657 | sub set_xorg_log { | |
1131 | 545 | # args: 1: set|hash key to return either null or path | 658 | eval $start if $b_log; |
1132 | 546 | sub system_files { | 659 | my (@temp,@x_logs); |
1133 | 547 | my ($file) = @_; | 660 | my ($file_holder,$time_holder,$x_mtime) = ('',0,0); |
1134 | 548 | if ( $file eq 'set'){ | 661 | # NOTE: other variations may be /var/run/gdm3/... but not confirmed |
1135 | 549 | %files = ( | 662 | # worry about we are just going to get all the Xorg logs we can find, |
1136 | 550 | 'asound-cards' => '/proc/asound/cards', | 663 | # and not which is 'right'. |
1137 | 551 | 'asound-modules' => '/proc/asound/modules', | 664 | @temp = globber('/var/log/Xorg.*.log'); |
1138 | 552 | 'asound-version' => '/proc/asound/version', | 665 | push(@x_logs, @temp) if @temp; |
1139 | 553 | 'cpuinfo' => '/proc/cpuinfo', | 666 | @temp = globber('/var/lib/gdm/.local/share/xorg/Xorg.*.log'); |
1140 | 554 | 'dmesg-boot' => '/var/run/dmesg.boot', | 667 | push(@x_logs, @temp) if @temp; |
1141 | 555 | 'lsb-release' => '/etc/lsb-release', | 668 | @temp = globber($ENV{'HOME'} . '/.local/share/xorg/Xorg.*.log',); |
1142 | 556 | 'mdstat' => '/proc/mdstat', | 669 | push(@x_logs, @temp) if @temp; |
1143 | 557 | 'meminfo' => '/proc/meminfo', | 670 | # root will not have a /root/.local/share/xorg directory so need to use a |
1144 | 558 | 'modules' => '/proc/modules', | 671 | # user one if we can find one. |
1145 | 559 | 'mounts' => '/proc/mounts', | 672 | if ($b_root){ |
1146 | 560 | 'os-release' => '/etc/os-release', | 673 | @temp = globber('/home/*/.local/share/xorg/Xorg.*.log'); |
1147 | 561 | 'partitions' => '/proc/partitions', | 674 | push(@x_logs, @temp) if @temp; |
1148 | 562 | 'scsi' => '/proc/scsi/scsi', | 675 | } |
1149 | 563 | 'version' => '/proc/version', | 676 | foreach (@x_logs){ |
1150 | 564 | 'xorg-log' => '/var/log/Xorg.0.log' | 677 | if (-r $_){ |
1151 | 565 | ); | 678 | my $src_info = File::stat::stat("$_"); |
1152 | 566 | foreach ( keys %files ){ | 679 | # print "$_\n"; |
1153 | 567 | $system_files{$_} = ( -e $files{$_} ) ? $files{$_} : ''; | 680 | if ($src_info){ |
1154 | 568 | } | 681 | $x_mtime = $src_info->mtime; |
1155 | 569 | if ( ! $system_files{'xorg-log'} && check_program('xset') ){ | 682 | # print $_ . ": $x_time" . "\n"; |
1156 | 570 | my $data = qx(xset q 2>/dev/null); | 683 | if ($x_mtime > $time_holder){ |
1157 | 571 | foreach ( split /\n/, $data){ | 684 | $time_holder = $x_mtime; |
1158 | 572 | if ($_ =~ /Log file/i){ | 685 | $file_holder = $_; |
1159 | 573 | $system_files{'xorg-log'} = get_piece($_,3); | 686 | } |
1160 | 574 | last; | 687 | } |
1161 | 575 | } | 688 | } |
1162 | 576 | } | 689 | } |
1163 | 577 | } | 690 | if (!$file_holder && check_program('xset')){ |
1164 | 578 | } | 691 | my $data = qx(xset q 2>/dev/null); |
1165 | 579 | else { | 692 | foreach (split('\n', $data)){ |
1166 | 580 | return $system_files{$file}; | 693 | if ($_ =~ /Log file/i){ |
1167 | 581 | } | 694 | $file_holder = get_piece($_,3); |
1168 | 695 | last; | ||
1169 | 696 | } | ||
1170 | 697 | } | ||
1171 | 698 | } | ||
1172 | 699 | print "Xorg log file: $file_holder\nLast modified: $time_holder\n" if $dbg[14]; | ||
1173 | 700 | log_data('data',"Xorg log file: $file_holder") if $b_log; | ||
1174 | 701 | $system_files{'xorg-log'} = $file_holder; | ||
1175 | 702 | eval $end if $b_log; | ||
1176 | 582 | } | 703 | } |
1177 | 583 | 704 | ||
1178 | 584 | ######################################################################## | 705 | ######################################################################## |
1179 | @@ -591,425 +712,420 @@ sub system_files { | |||
1180 | 591 | 712 | ||
1181 | 592 | ## arg: 1 - the type of action, either integer, count, or full | 713 | ## arg: 1 - the type of action, either integer, count, or full |
1182 | 593 | sub get_color_scheme { | 714 | sub get_color_scheme { |
1245 | 594 | my ($type) = @_; | 715 | my ($type) = @_; |
1246 | 595 | eval $start if $b_log; | 716 | eval $start if $b_log; |
1247 | 596 | my @color_schemes = ( | 717 | my @color_schemes = ( |
1248 | 597 | [qw(EMPTY EMPTY EMPTY )], | 718 | [qw(EMPTY EMPTY EMPTY)], |
1249 | 598 | [qw(NORMAL NORMAL NORMAL )], | 719 | [qw(NORMAL NORMAL NORMAL)], |
1250 | 599 | # for dark OR light backgrounds | 720 | # for dark OR light backgrounds |
1251 | 600 | [qw(BLUE NORMAL NORMAL)], | 721 | [qw(BLUE NORMAL NORMAL)], |
1252 | 601 | [qw(BLUE RED NORMAL )], | 722 | [qw(BLUE RED NORMAL)], |
1253 | 602 | [qw(CYAN BLUE NORMAL )], | 723 | [qw(CYAN BLUE NORMAL)], |
1254 | 603 | [qw(DCYAN NORMAL NORMAL)], | 724 | [qw(DCYAN NORMAL NORMAL)], |
1255 | 604 | [qw(DCYAN BLUE NORMAL )], | 725 | [qw(DCYAN BLUE NORMAL)], |
1256 | 605 | [qw(DGREEN NORMAL NORMAL )], | 726 | [qw(DGREEN NORMAL NORMAL)], |
1257 | 606 | [qw(DYELLOW NORMAL NORMAL )], | 727 | [qw(DYELLOW NORMAL NORMAL)], |
1258 | 607 | [qw(GREEN DGREEN NORMAL )], | 728 | [qw(GREEN DGREEN NORMAL)], |
1259 | 608 | [qw(GREEN NORMAL NORMAL )], | 729 | [qw(GREEN NORMAL NORMAL)], |
1260 | 609 | [qw(MAGENTA NORMAL NORMAL)], | 730 | [qw(MAGENTA NORMAL NORMAL)], |
1261 | 610 | [qw(RED NORMAL NORMAL)], | 731 | [qw(RED NORMAL NORMAL)], |
1262 | 611 | # for light backgrounds | 732 | # for light backgrounds |
1263 | 612 | [qw(BLACK DGREY NORMAL)], | 733 | [qw(BLACK DGREY NORMAL)], |
1264 | 613 | [qw(DBLUE DGREY NORMAL )], | 734 | [qw(DBLUE DGREY NORMAL)], |
1265 | 614 | [qw(DBLUE DMAGENTA NORMAL)], | 735 | [qw(DBLUE DMAGENTA NORMAL)], |
1266 | 615 | [qw(DBLUE DRED NORMAL )], | 736 | [qw(DBLUE DRED NORMAL)], |
1267 | 616 | [qw(DBLUE BLACK NORMAL)], | 737 | [qw(DBLUE BLACK NORMAL)], |
1268 | 617 | [qw(DGREEN DYELLOW NORMAL )], | 738 | [qw(DGREEN DYELLOW NORMAL)], |
1269 | 618 | [qw(DYELLOW BLACK NORMAL)], | 739 | [qw(DYELLOW BLACK NORMAL)], |
1270 | 619 | [qw(DMAGENTA BLACK NORMAL)], | 740 | [qw(DMAGENTA BLACK NORMAL)], |
1271 | 620 | [qw(DCYAN DBLUE NORMAL)], | 741 | [qw(DCYAN DBLUE NORMAL)], |
1272 | 621 | # for dark backgrounds | 742 | # for dark backgrounds |
1273 | 622 | [qw(WHITE GREY NORMAL)], | 743 | [qw(WHITE GREY NORMAL)], |
1274 | 623 | [qw(GREY WHITE NORMAL)], | 744 | [qw(GREY WHITE NORMAL)], |
1275 | 624 | [qw(CYAN GREY NORMAL )], | 745 | [qw(CYAN GREY NORMAL)], |
1276 | 625 | [qw(GREEN WHITE NORMAL )], | 746 | [qw(GREEN WHITE NORMAL)], |
1277 | 626 | [qw(GREEN YELLOW NORMAL )], | 747 | [qw(GREEN YELLOW NORMAL)], |
1278 | 627 | [qw(YELLOW WHITE NORMAL )], | 748 | [qw(YELLOW WHITE NORMAL)], |
1279 | 628 | [qw(MAGENTA CYAN NORMAL )], | 749 | [qw(MAGENTA CYAN NORMAL)], |
1280 | 629 | [qw(MAGENTA YELLOW NORMAL)], | 750 | [qw(MAGENTA YELLOW NORMAL)], |
1281 | 630 | [qw(RED CYAN NORMAL)], | 751 | [qw(RED CYAN NORMAL)], |
1282 | 631 | [qw(RED WHITE NORMAL )], | 752 | [qw(RED WHITE NORMAL)], |
1283 | 632 | [qw(BLUE WHITE NORMAL)], | 753 | [qw(BLUE WHITE NORMAL)], |
1284 | 633 | # miscellaneous | 754 | # miscellaneous |
1285 | 634 | [qw(RED BLUE NORMAL )], | 755 | [qw(RED BLUE NORMAL)], |
1286 | 635 | [qw(RED DBLUE NORMAL)], | 756 | [qw(RED DBLUE NORMAL)], |
1287 | 636 | [qw(BLACK BLUE NORMAL)], | 757 | [qw(BLACK BLUE NORMAL)], |
1288 | 637 | [qw(BLACK DBLUE NORMAL)], | 758 | [qw(BLACK DBLUE NORMAL)], |
1289 | 638 | [qw(NORMAL BLUE NORMAL)], | 759 | [qw(NORMAL BLUE NORMAL)], |
1290 | 639 | [qw(BLUE MAGENTA NORMAL)], | 760 | [qw(BLUE MAGENTA NORMAL)], |
1291 | 640 | [qw(DBLUE MAGENTA NORMAL)], | 761 | [qw(DBLUE MAGENTA NORMAL)], |
1292 | 641 | [qw(BLACK MAGENTA NORMAL)], | 762 | [qw(BLACK MAGENTA NORMAL)], |
1293 | 642 | [qw(MAGENTA BLUE NORMAL)], | 763 | [qw(MAGENTA BLUE NORMAL)], |
1294 | 643 | [qw(MAGENTA DBLUE NORMAL)], | 764 | [qw(MAGENTA DBLUE NORMAL)], |
1295 | 644 | ); | 765 | ); |
1296 | 645 | if ($type eq 'count' ){ | 766 | eval $end if $b_log; |
1297 | 646 | return scalar @color_schemes; | 767 | if ($type eq 'count'){ |
1298 | 647 | } | 768 | return scalar @color_schemes; |
1299 | 648 | if ($type eq 'full' ){ | 769 | } |
1300 | 649 | return @color_schemes; | 770 | if ($type eq 'full'){ |
1301 | 650 | } | 771 | return @color_schemes; |
1302 | 651 | else { | 772 | } |
1303 | 652 | return @{$color_schemes[$type]}; | 773 | else { |
1304 | 653 | # print Dumper $color_schemes[$scheme_nu]; | 774 | return @{$color_schemes[$type]}; |
1305 | 654 | } | 775 | # print Dumper $color_schemes[$scheme_nu]; |
1306 | 655 | eval $end if $b_log; | 776 | } |
1307 | 656 | } | 777 | } |
1308 | 657 | 778 | ||
1309 | 658 | sub set_color_scheme { | 779 | sub set_color_scheme { |
1344 | 659 | eval $start if $b_log; | 780 | eval $start if $b_log; |
1345 | 660 | my ($scheme) = @_; | 781 | my ($scheme) = @_; |
1346 | 661 | $colors{'scheme'} = $scheme; | 782 | $colors{'scheme'} = $scheme; |
1347 | 662 | my $index = ( $b_irc ) ? 1 : 0; # defaults to non irc | 783 | my $index = ($b_irc) ? 1 : 0; # defaults to non irc |
1348 | 663 | 784 | ||
1349 | 664 | # NOTE: qw(...) kills the escape, it is NOT the same as using | 785 | # NOTE: qw(...) kills the escape, it is NOT the same as using |
1350 | 665 | # Literal "..", ".." despite docs saying it is. | 786 | # Literal "..", ".." despite docs saying it is. |
1351 | 666 | my %color_palette = ( | 787 | my %color_palette = ( |
1352 | 667 | 'EMPTY' => [ '', '' ], | 788 | 'EMPTY' => [ '', '' ], |
1353 | 668 | 'DGREY' => [ "\e[1;30m", "\x0314" ], | 789 | 'DGREY' => [ "\e[1;30m", "\x0314" ], |
1354 | 669 | 'BLACK' => [ "\e[0;30m", "\x0301" ], | 790 | 'BLACK' => [ "\e[0;30m", "\x0301" ], |
1355 | 670 | 'RED' => [ "\e[1;31m", "\x0304" ], | 791 | 'RED' => [ "\e[1;31m", "\x0304" ], |
1356 | 671 | 'DRED' => [ "\e[0;31m", "\x0305" ], | 792 | 'DRED' => [ "\e[0;31m", "\x0305" ], |
1357 | 672 | 'GREEN' => [ "\e[1;32m", "\x0309" ], | 793 | 'GREEN' => [ "\e[1;32m", "\x0309" ], |
1358 | 673 | 'DGREEN' => [ "\e[0;32m", "\x0303" ], | 794 | 'DGREEN' => [ "\e[0;32m", "\x0303" ], |
1359 | 674 | 'YELLOW' => [ "\e[1;33m", "\x0308" ], | 795 | 'YELLOW' => [ "\e[1;33m", "\x0308" ], |
1360 | 675 | 'DYELLOW' => [ "\e[0;33m", "\x0307" ], | 796 | 'DYELLOW' => [ "\e[0;33m", "\x0307" ], |
1361 | 676 | 'BLUE' => [ "\e[1;34m", "\x0312" ], | 797 | 'BLUE' => [ "\e[1;34m", "\x0312" ], |
1362 | 677 | 'DBLUE' => [ "\e[0;34m", "\x0302" ], | 798 | 'DBLUE' => [ "\e[0;34m", "\x0302" ], |
1363 | 678 | 'MAGENTA' => [ "\e[1;35m", "\x0313" ], | 799 | 'MAGENTA' => [ "\e[1;35m", "\x0313" ], |
1364 | 679 | 'DMAGENTA' => [ "\e[0;35m", "\x0306" ], | 800 | 'DMAGENTA' => [ "\e[0;35m", "\x0306" ], |
1365 | 680 | 'CYAN' => [ "\e[1;36m", "\x0311" ], | 801 | 'CYAN' => [ "\e[1;36m", "\x0311" ], |
1366 | 681 | 'DCYAN' => [ "\e[0;36m", "\x0310" ], | 802 | 'DCYAN' => [ "\e[0;36m", "\x0310" ], |
1367 | 682 | 'WHITE' => [ "\e[1;37m", "\x0300" ], | 803 | 'WHITE' => [ "\e[1;37m", "\x0300" ], |
1368 | 683 | 'GREY' => [ "\e[0;37m", "\x0315" ], | 804 | 'GREY' => [ "\e[0;37m", "\x0315" ], |
1369 | 684 | 'NORMAL' => [ "\e[0m", "\x03" ], | 805 | 'NORMAL' => [ "\e[0m", "\x03" ], |
1370 | 685 | ); | 806 | ); |
1371 | 686 | my @scheme = get_color_scheme($colors{'scheme'}); | 807 | my @scheme = get_color_scheme($colors{'scheme'}); |
1372 | 687 | $colors{'c1'} = $color_palette{$scheme[0]}[$index]; | 808 | $colors{'c1'} = $color_palette{$scheme[0]}->[$index]; |
1373 | 688 | $colors{'c2'} = $color_palette{$scheme[1]}[$index]; | 809 | $colors{'c2'} = $color_palette{$scheme[1]}->[$index]; |
1374 | 689 | $colors{'cn'} = $color_palette{$scheme[2]}[$index]; | 810 | $colors{'cn'} = $color_palette{$scheme[2]}->[$index]; |
1375 | 690 | # print Dumper \@scheme; | 811 | # print Dumper \@scheme; |
1376 | 691 | # print "$colors{'c1'}here$colors{'c2'} we are!$colors{'cn'}\n"; | 812 | # print "$colors{'c1'}here$colors{'c2'} we are!$colors{'cn'}\n"; |
1377 | 692 | eval $end if $b_log; | 813 | eval $end if $b_log; |
1378 | 693 | } | 814 | } |
1379 | 694 | 815 | ||
1380 | 695 | sub set_colors { | 816 | sub set_colors { |
1427 | 696 | eval $start if $b_log; | 817 | eval $start if $b_log; |
1428 | 697 | # it's already been set with -c 0-43 | 818 | # it's already been set with -c 0-43 |
1429 | 698 | if ( exists $colors{'c1'} ){ | 819 | if (exists $colors{'c1'}){ |
1430 | 699 | return 1; | 820 | return 1; |
1431 | 700 | } | 821 | } |
1432 | 701 | # This let's user pick their color scheme. For IRC, only shows the color schemes, | 822 | # This let's user pick their color scheme. For IRC, only shows the color |
1433 | 702 | # no interactive. The override value only will be placed in user config files. | 823 | # schemes, no interactive. The override value only will be placed in user |
1434 | 703 | # /etc/inxi.conf can also override | 824 | # config files. /etc/inxi.conf can also override |
1435 | 704 | if (exists $colors{'selector'}){ | 825 | if (exists $colors{'selector'}){ |
1436 | 705 | my $ob_selector = SelectColors->new($colors{'selector'}); | 826 | my $ob_selector = SelectColors->new($colors{'selector'}); |
1437 | 706 | $ob_selector->select_schema(); | 827 | $ob_selector->select_schema(); |
1438 | 707 | return 1; | 828 | return 1; |
1439 | 708 | } | 829 | } |
1440 | 709 | # set the default, then override as required | 830 | # set the default, then override as required |
1441 | 710 | my $color_scheme = $colors{'default'}; | 831 | my $color_scheme = $colors{'default'}; |
1442 | 711 | # these are set in user configs | 832 | # these are set in user configs |
1443 | 712 | if (defined $colors{'global'}){ | 833 | if (defined $colors{'global'}){ |
1444 | 713 | $color_scheme = $colors{'global'}; | 834 | $color_scheme = $colors{'global'}; |
1445 | 714 | } | 835 | } |
1446 | 715 | else { | 836 | else { |
1447 | 716 | if ( $b_irc ){ | 837 | if ($b_irc){ |
1448 | 717 | if (defined $colors{'irc-virt-term'} && $b_display && $client{'console-irc'}){ | 838 | if (defined $colors{'irc-virt-term'} && $b_display && $client{'console-irc'}){ |
1449 | 718 | $color_scheme = $colors{'irc-virt-term'}; | 839 | $color_scheme = $colors{'irc-virt-term'}; |
1450 | 719 | } | 840 | } |
1451 | 720 | elsif (defined $colors{'irc-console'} && !$b_display){ | 841 | elsif (defined $colors{'irc-console'} && !$b_display){ |
1452 | 721 | $color_scheme = $colors{'irc-console'}; | 842 | $color_scheme = $colors{'irc-console'}; |
1453 | 722 | } | 843 | } |
1454 | 723 | elsif ( defined $colors{'irc-gui'}) { | 844 | elsif (defined $colors{'irc-gui'}){ |
1455 | 724 | $color_scheme = $colors{'irc-gui'}; | 845 | $color_scheme = $colors{'irc-gui'}; |
1456 | 725 | } | 846 | } |
1457 | 726 | } | 847 | } |
1458 | 727 | else { | 848 | else { |
1459 | 728 | if (defined $colors{'console'} && !$b_display){ | 849 | if (defined $colors{'console'} && !$b_display){ |
1460 | 729 | $color_scheme = $colors{'console'}; | 850 | $color_scheme = $colors{'console'}; |
1461 | 730 | } | 851 | } |
1462 | 731 | elsif (defined $colors{'virt-term'}){ | 852 | elsif (defined $colors{'virt-term'}){ |
1463 | 732 | $color_scheme = $colors{'virt-term'}; | 853 | $color_scheme = $colors{'virt-term'}; |
1464 | 733 | } | 854 | } |
1465 | 734 | } | 855 | } |
1466 | 735 | } | 856 | } |
1467 | 736 | # force 0 for | or > output, all others prints to irc or screen | 857 | # force 0 for | or > output, all others prints to irc or screen |
1468 | 737 | if (!$b_irc && ! -t STDOUT ){ | 858 | if (!$b_irc && ! -t STDOUT){ |
1469 | 738 | $color_scheme = 0; | 859 | $color_scheme = 0; |
1470 | 739 | } | 860 | } |
1471 | 740 | set_color_scheme($color_scheme); | 861 | set_color_scheme($color_scheme); |
1472 | 741 | eval $end if $b_log; | 862 | eval $end if $b_log; |
1473 | 742 | } | 863 | } |
1474 | 743 | 864 | ||
1475 | 744 | ## SelectColors | 865 | ## SelectColors |
1476 | 745 | { | 866 | { |
1477 | 746 | package SelectColors; | 867 | package SelectColors; |
1485 | 747 | 868 | my (@data,%configs,%status); | |
1479 | 748 | # use warnings; | ||
1480 | 749 | # use strict; | ||
1481 | 750 | # use diagnostics; | ||
1482 | 751 | # use 5.008; | ||
1483 | 752 | |||
1484 | 753 | my (@data,@rows,%configs,%status); | ||
1486 | 754 | my ($type,$w_fh); | 869 | my ($type,$w_fh); |
1487 | 755 | my $safe_color_count = 12; # null/normal + default color group | 870 | my $safe_color_count = 12; # null/normal + default color group |
1488 | 756 | my $count = 0; | 871 | my $count = 0; |
1489 | 757 | |||
1490 | 758 | # args: 1 - type | 872 | # args: 1 - type |
1491 | 759 | sub new { | 873 | sub new { |
1496 | 760 | my $class = shift; | 874 | my $class = shift; |
1497 | 761 | ($type) = @_; | 875 | ($type) = @_; |
1498 | 762 | my $self = {}; | 876 | my $self = {}; |
1499 | 763 | return bless $self, $class; | 877 | return bless $self, $class; |
1500 | 764 | } | 878 | } |
1501 | 765 | sub select_schema { | 879 | sub select_schema { |
1516 | 766 | eval $start if $b_log; | 880 | eval $start if $b_log; |
1517 | 767 | assign_selectors(); | 881 | assign_selectors(); |
1518 | 768 | main::set_color_scheme(0); | 882 | main::set_color_scheme(0); |
1519 | 769 | set_status(); | 883 | set_status(); |
1520 | 770 | start_selector(); | 884 | start_selector(); |
1521 | 771 | create_color_selections(); | 885 | create_color_selections(); |
1522 | 772 | if (! $b_irc ){ | 886 | if (!$b_irc){ |
1523 | 773 | main::check_config_file(); | 887 | Configs::check_file(); |
1524 | 774 | get_selection(); | 888 | get_selection(); |
1525 | 775 | } | 889 | } |
1526 | 776 | else { | 890 | else { |
1527 | 777 | print_irc_message(); | 891 | print_irc_message(); |
1528 | 778 | } | 892 | } |
1529 | 779 | eval $end if $b_log; | 893 | eval $end if $b_log; |
1530 | 780 | } | 894 | } |
1531 | 781 | 895 | ||
1532 | 782 | sub set_status { | 896 | sub set_status { |
1539 | 783 | $status{'console'} = (defined $colors{'console'}) ? "Set: $colors{'console'}" : 'Not Set'; | 897 | $status{'console'} = (defined $colors{'console'}) ? "Set: $colors{'console'}" : 'Not Set'; |
1540 | 784 | $status{'virt-term'} = (defined $colors{'virt-term'}) ? "Set: $colors{'virt-term'}" : 'Not Set'; | 898 | $status{'virt-term'} = (defined $colors{'virt-term'}) ? "Set: $colors{'virt-term'}" : 'Not Set'; |
1541 | 785 | $status{'irc-console'} = (defined $colors{'irc-console'}) ? "Set: $colors{'irc-console'}" : 'Not Set'; | 899 | $status{'irc-console'} = (defined $colors{'irc-console'}) ? "Set: $colors{'irc-console'}" : 'Not Set'; |
1542 | 786 | $status{'irc-gui'} = (defined $colors{'irc-gui'}) ? "Set: $colors{'irc-gui'}" : 'Not Set'; | 900 | $status{'irc-gui'} = (defined $colors{'irc-gui'}) ? "Set: $colors{'irc-gui'}" : 'Not Set'; |
1543 | 787 | $status{'irc-virt-term'} = (defined $colors{'irc-virt-term'}) ? "Set: $colors{'irc-virt-term'}" : 'Not Set'; | 901 | $status{'irc-virt-term'} = (defined $colors{'irc-virt-term'}) ? "Set: $colors{'irc-virt-term'}" : 'Not Set'; |
1544 | 788 | $status{'global'} = (defined $colors{'global'}) ? "Set: $colors{'global'}" : 'Not Set'; | 902 | $status{'global'} = (defined $colors{'global'}) ? "Set: $colors{'global'}" : 'Not Set'; |
1545 | 789 | } | 903 | } |
1546 | 790 | 904 | ||
1547 | 791 | sub assign_selectors { | 905 | sub assign_selectors { |
1572 | 792 | if ($type == 94){ | 906 | if ($type == 94){ |
1573 | 793 | $configs{'variable'} = 'CONSOLE_COLOR_SCHEME'; | 907 | $configs{'variable'} = 'CONSOLE_COLOR_SCHEME'; |
1574 | 794 | $configs{'selection'} = 'console'; | 908 | $configs{'selection'} = 'console'; |
1575 | 795 | } | 909 | } |
1576 | 796 | elsif ($type == 95){ | 910 | elsif ($type == 95){ |
1577 | 797 | $configs{'variable'} = 'VIRT_TERM_COLOR_SCHEME'; | 911 | $configs{'variable'} = 'VIRT_TERM_COLOR_SCHEME'; |
1578 | 798 | $configs{'selection'} = 'virt-term'; | 912 | $configs{'selection'} = 'virt-term'; |
1579 | 799 | } | 913 | } |
1580 | 800 | elsif ($type == 96){ | 914 | elsif ($type == 96){ |
1581 | 801 | $configs{'variable'} = 'IRC_COLOR_SCHEME'; | 915 | $configs{'variable'} = 'IRC_COLOR_SCHEME'; |
1582 | 802 | $configs{'selection'} = 'irc-gui'; | 916 | $configs{'selection'} = 'irc-gui'; |
1583 | 803 | } | 917 | } |
1584 | 804 | elsif ($type == 97){ | 918 | elsif ($type == 97){ |
1585 | 805 | $configs{'variable'} = 'IRC_X_TERM_COLOR_SCHEME'; | 919 | $configs{'variable'} = 'IRC_X_TERM_COLOR_SCHEME'; |
1586 | 806 | $configs{'selection'} = 'irc-virt-term'; | 920 | $configs{'selection'} = 'irc-virt-term'; |
1587 | 807 | } | 921 | } |
1588 | 808 | elsif ($type == 98){ | 922 | elsif ($type == 98){ |
1589 | 809 | $configs{'variable'} = 'IRC_CONS_COLOR_SCHEME'; | 923 | $configs{'variable'} = 'IRC_CONS_COLOR_SCHEME'; |
1590 | 810 | $configs{'selection'} = 'irc-console'; | 924 | $configs{'selection'} = 'irc-console'; |
1591 | 811 | } | 925 | } |
1592 | 812 | elsif ($type == 99){ | 926 | elsif ($type == 99){ |
1593 | 813 | $configs{'variable'} = 'GLOBAL_COLOR_SCHEME'; | 927 | $configs{'variable'} = 'GLOBAL_COLOR_SCHEME'; |
1594 | 814 | $configs{'selection'} = 'global'; | 928 | $configs{'selection'} = 'global'; |
1595 | 815 | } | 929 | } |
1596 | 816 | } | 930 | } |
1597 | 817 | sub start_selector { | 931 | sub start_selector { |
1629 | 818 | my $whoami = getpwuid($<) || "unknown???"; | 932 | my $whoami = getpwuid($<) || "unknown???"; |
1630 | 819 | if ( ! $b_irc ){ | 933 | if (!$b_irc){ |
1631 | 820 | @data = ( | 934 | @data = ( |
1632 | 821 | [ 0, '', '', "Welcome to $self_name! Please select the default | 935 | [ 0, '', '', "Welcome to $self_name! Please select the default |
1633 | 822 | $configs{'selection'} color scheme."], | 936 | $configs{'selection'} color scheme."], |
1634 | 823 | ); | 937 | ); |
1635 | 824 | } | 938 | } |
1636 | 825 | @rows = ( | 939 | push(@data, |
1637 | 826 | [ 0, '', '', "Because there is no way to know your $configs{'selection'} | 940 | [ 0, '', '', "Because there is no way to know your $configs{'selection'} |
1638 | 827 | foreground/background colors, you can set your color preferences from | 941 | foreground/background colors, you can set your color preferences from |
1639 | 828 | color scheme option list below:"], | 942 | color scheme option list below:"], |
1640 | 829 | [ 0, '', '', "0 is no colors; 1 is neutral."], | 943 | [ 0, '', '', "0 is no colors; 1 is neutral."], |
1641 | 830 | [ 0, '', '', "After these, there are 4 sets:"], | 944 | [ 0, '', '', "After these, there are 4 sets:"], |
1642 | 831 | [ 0, '', '', "1-dark^or^light^backgrounds; 2-light^backgrounds; | 945 | [ 0, '', '', "1-dark^or^light^backgrounds; 2-light^backgrounds; |
1643 | 832 | 3-dark^backgrounds; 4-miscellaneous"], | 946 | 3-dark^backgrounds; 4-miscellaneous"], |
1644 | 833 | [ 0, '', '', ""], | 947 | [ 0, '', '', ""], |
1645 | 834 | ); | 948 | ); |
1646 | 835 | push @data, @rows; | 949 | if (!$b_irc){ |
1647 | 836 | if ( ! $b_irc ){ | 950 | push(@data, |
1648 | 837 | @rows = ( | 951 | [ 0, '', '', "Please note that this will set the $configs{'selection'} |
1649 | 838 | [ 0, '', '', "Please note that this will set the $configs{'selection'} | 952 | preferences only for user: $whoami"], |
1650 | 839 | preferences only for user: $whoami"], | 953 | ); |
1651 | 840 | ); | 954 | } |
1652 | 841 | push @data, @rows; | 955 | push(@data, |
1653 | 842 | } | 956 | [ 0, '', '', "$line1"], |
1654 | 843 | @rows = ( | 957 | ); |
1655 | 844 | [ 0, '', '', "$line1"], | 958 | main::print_basic(\@data); |
1656 | 845 | ); | 959 | @data = (); |
1626 | 846 | push @data, @rows; | ||
1627 | 847 | main::print_basic(@data); | ||
1628 | 848 | @data = (); | ||
1657 | 849 | } | 960 | } |
1658 | 850 | sub create_color_selections { | 961 | sub create_color_selections { |
1678 | 851 | my $spacer = '^^'; # printer removes double spaces, but replaces ^ with ' ' | 962 | my $spacer = '^^'; # printer removes double spaces, but replaces ^ with ' ' |
1679 | 852 | $count = ( main::get_color_scheme('count') - 1 ); | 963 | $count = (main::get_color_scheme('count') - 1); |
1680 | 853 | for my $i (0 .. $count){ | 964 | foreach my $i (0 .. $count){ |
1681 | 854 | if ($i > 9){ | 965 | if ($i > 9){ |
1682 | 855 | $spacer = '^'; | 966 | $spacer = '^'; |
1683 | 856 | } | 967 | } |
1684 | 857 | if ($configs{'selection'} =~ /^(global|irc-gui|irc-console|irc-virt-term)$/ && $i > $safe_color_count ){ | 968 | if ($configs{'selection'} =~ /^(global|irc-gui|irc-console|irc-virt-term)$/ && $i > $safe_color_count){ |
1685 | 858 | last; | 969 | last; |
1686 | 859 | } | 970 | } |
1687 | 860 | main::set_color_scheme($i); | 971 | main::set_color_scheme($i); |
1688 | 861 | @rows = ( | 972 | push(@data, |
1689 | 862 | [0, '', '', "$i)$spacer$colors{'c1'}Card:$colors{'c2'}^nVidia^GT218 | 973 | [0, '', '', "$i)$spacer$colors{'c1'}Card:$colors{'c2'}^nVidia^GT218 |
1690 | 863 | $colors{'c1'}Display^Server$colors{'c2'}^x11^(X.Org^1.7.7)$colors{'cn'}"], | 974 | $colors{'c1'}Display^Server$colors{'c2'}^x11^(X.Org^1.7.7)$colors{'cn'}"], |
1691 | 864 | ); | 975 | ); |
1692 | 865 | push @data, @rows; | 976 | } |
1693 | 866 | } | 977 | main::print_basic(\@data); |
1694 | 867 | main::print_basic(@data); | 978 | @data = (); |
1695 | 868 | @data = (); | 979 | main::set_color_scheme(0); |
1677 | 869 | main::set_color_scheme(0); | ||
1696 | 870 | } | 980 | } |
1697 | 871 | sub get_selection { | 981 | sub get_selection { |
1737 | 872 | my $number = $count + 1; | 982 | my $number = $count + 1; |
1738 | 873 | @data = ( | 983 | @data = ( |
1739 | 874 | [0, '', '', ($number++) . ")^Remove all color settings. Restore $self_name default."], | 984 | [0, '', '', ($number++) . ")^Remove all color settings. Restore $self_name default."], |
1740 | 875 | [0, '', '', ($number++) . ")^Continue, no changes or config file setting."], | 985 | [0, '', '', ($number++) . ")^Continue, no changes or config file setting."], |
1741 | 876 | [0, '', '', ($number++) . ")^Exit, use another terminal, or set manually."], | 986 | [0, '', '', ($number++) . ")^Exit, use another terminal, or set manually."], |
1742 | 877 | [0, '', '', "$line1"], | 987 | [0, '', '', "$line1"], |
1743 | 878 | [0, '', '', "Simply type the number for the color scheme that looks best to your | 988 | [0, '', '', "Simply type the number for the color scheme that looks best to your |
1744 | 879 | eyes for your $configs{'selection'} settings and hit <ENTER>. NOTE: You can bring this | 989 | eyes for your $configs{'selection'} settings and hit <ENTER>. NOTE: You can bring this |
1745 | 880 | option list up by starting $self_name with option: -c plus one of these numbers:"], | 990 | option list up by starting $self_name with option: -c plus one of these numbers:"], |
1746 | 881 | [0, '', '', "94^-^console,^not^in^desktop^-^$status{'console'}"], | 991 | [0, '', '', "94^-^console,^not^in^desktop^-^$status{'console'}"], |
1747 | 882 | [0, '', '', "95^-^terminal,^desktop^-^$status{'virt-term'}"], | 992 | [0, '', '', "95^-^terminal,^desktop^-^$status{'virt-term'}"], |
1748 | 883 | [0, '', '', "96^-^irc,^gui,^desktop^-^$status{'irc-gui'}"], | 993 | [0, '', '', "96^-^irc,^gui,^desktop^-^$status{'irc-gui'}"], |
1749 | 884 | [0, '', '', "97^-^irc,^desktop,^in^terminal^-^$status{'irc-virt-term'}"], | 994 | [0, '', '', "97^-^irc,^desktop,^in^terminal^-^$status{'irc-virt-term'}"], |
1750 | 885 | [0, '', '', "98^-^irc,^not^in^desktop^-^$status{'irc-console'}"], | 995 | [0, '', '', "98^-^irc,^not^in^desktop^-^$status{'irc-console'}"], |
1751 | 886 | [0, '', '', "99^-^global^-^$status{'global'}"], | 996 | [0, '', '', "99^-^global^-^$status{'global'}"], |
1752 | 887 | [0, '', '', ""], | 997 | [0, '', '', ""], |
1753 | 888 | [0, '', '', "Your selection(s) will be stored here: $user_config_file"], | 998 | [0, '', '', "Your selection(s) will be stored here: $user_config_file"], |
1754 | 889 | [0, '', '', "Global overrides all individual color schemes. Individual | 999 | [0, '', '', "Global overrides all individual color schemes. Individual |
1755 | 890 | schemes remove the global setting."], | 1000 | schemes remove the global setting."], |
1756 | 891 | [0, '', '', "$line1"], | 1001 | [0, '', '', "$line1"], |
1757 | 892 | ); | 1002 | ); |
1758 | 893 | main::print_basic(@data); | 1003 | main::print_basic(\@data); |
1759 | 894 | @data = (); | 1004 | @data = (); |
1760 | 895 | my $response = <STDIN>; | 1005 | my $response = <STDIN>; |
1761 | 896 | chomp $response; | 1006 | chomp($response); |
1762 | 897 | if (!main::is_int($response) || $response > ($count + 3) ){ | 1007 | if (!main::is_int($response) || $response > ($count + 3)){ |
1763 | 898 | @data = ( | 1008 | @data = ( |
1764 | 899 | [0, '', '', "Error - Invalid Selection. You entered this: $response. Hit <ENTER> to continue."], | 1009 | [0, '', '', "Error - Invalid Selection. You entered this: $response. Hit <ENTER> to continue."], |
1765 | 900 | [0, '', '', "$line1"], | 1010 | [0, '', '', "$line1"], |
1766 | 901 | ); | 1011 | ); |
1767 | 902 | main::print_basic(@data); | 1012 | main::print_basic(\@data); |
1768 | 903 | my $response = <STDIN>; | 1013 | my $response = <STDIN>; |
1769 | 904 | start_selector(); | 1014 | start_selector(); |
1770 | 905 | create_color_selections(); | 1015 | create_color_selections(); |
1771 | 906 | get_selection(); | 1016 | get_selection(); |
1772 | 907 | } | 1017 | } |
1773 | 908 | else { | 1018 | else { |
1774 | 909 | process_selection($response); | 1019 | process_selection($response); |
1775 | 910 | } | 1020 | } |
1776 | 1021 | if ($b_pledge){ | ||
1777 | 1022 | @pledges = grep {$_ ne 'getpw'} @pledges; | ||
1778 | 1023 | OpenBSD::Pledge::pledge(@pledges); | ||
1779 | 1024 | } | ||
1780 | 911 | } | 1025 | } |
1781 | 912 | sub process_selection { | 1026 | sub process_selection { |
1828 | 913 | my $response = shift; | 1027 | my $response = shift; |
1829 | 914 | if ($response == ($count + 3) ){ | 1028 | if ($response == ($count + 3)){ |
1830 | 915 | @data = ([0, '', '', "Ok, exiting $self_name now. You can set the colors later."],); | 1029 | @data = ( |
1831 | 916 | main::print_basic(@data); | 1030 | [0, '', '', "Ok, exiting $self_name now. You can set the colors later."], |
1832 | 917 | exit 0; | 1031 | ); |
1833 | 918 | } | 1032 | main::print_basic(\@data); |
1834 | 919 | elsif ($response == ($count + 2)){ | 1033 | exit 0; |
1835 | 920 | @data = ( | 1034 | } |
1836 | 921 | [0, '', '', "Ok, continuing $self_name unchanged."], | 1035 | elsif ($response == ($count + 2)){ |
1837 | 922 | [0, '', '', "$line1"], | 1036 | @data = ( |
1838 | 923 | ); | 1037 | [0, '', '', "Ok, continuing $self_name unchanged."], |
1839 | 924 | main::print_basic(@data); | 1038 | [0, '', '', "$line1"], |
1840 | 925 | if ( defined $colors{'console'} && !$b_display ){ | 1039 | ); |
1841 | 926 | main::set_color_scheme($colors{'console'}); | 1040 | main::print_basic(\@data); |
1842 | 927 | } | 1041 | if (defined $colors{'console'} && !$b_display){ |
1843 | 928 | if ( defined $colors{'virt-term'} ){ | 1042 | main::set_color_scheme($colors{'console'}); |
1844 | 929 | main::set_color_scheme($colors{'virt-term'}); | 1043 | } |
1845 | 930 | } | 1044 | if (defined $colors{'virt-term'}){ |
1846 | 931 | else { | 1045 | main::set_color_scheme($colors{'virt-term'}); |
1847 | 932 | main::set_color_scheme($colors{'default'}); | 1046 | } |
1848 | 933 | } | 1047 | else { |
1849 | 934 | } | 1048 | main::set_color_scheme($colors{'default'}); |
1850 | 935 | elsif ($response == ($count + 1)){ | 1049 | } |
1851 | 936 | @data = ( | 1050 | } |
1852 | 937 | [0, '', '', "Removing all color settings from config file now..."], | 1051 | elsif ($response == ($count + 1)){ |
1853 | 938 | [0, '', '', "$line1"], | 1052 | @data = ( |
1854 | 939 | ); | 1053 | [0, '', '', "Removing all color settings from config file now..."], |
1855 | 940 | main::print_basic(@data); | 1054 | [0, '', '', "$line1"], |
1856 | 941 | delete_all_config_colors(); | 1055 | ); |
1857 | 942 | main::set_color_scheme($colors{'default'}); | 1056 | main::print_basic(\@data); |
1858 | 943 | } | 1057 | delete_all_config_colors(); |
1859 | 944 | else { | 1058 | main::set_color_scheme($colors{'default'}); |
1860 | 945 | main::set_color_scheme($response); | 1059 | } |
1861 | 946 | @data = ( | 1060 | else { |
1862 | 947 | [0, '', '', "Updating config file for $configs{'selection'} color scheme now..."], | 1061 | main::set_color_scheme($response); |
1863 | 948 | [0, '', '', "$line1"], | 1062 | @data = ( |
1864 | 949 | ); | 1063 | [0, '', '', "Updating config file for $configs{'selection'} color scheme now..."], |
1865 | 950 | main::print_basic(@data); | 1064 | [0, '', '', "$line1"], |
1866 | 951 | if ($configs{'selection'} eq 'global'){ | 1065 | ); |
1867 | 952 | delete_all_colors(); | 1066 | main::print_basic(\@data); |
1868 | 953 | } | 1067 | if ($configs{'selection'} eq 'global'){ |
1869 | 954 | else { | 1068 | delete_all_colors(); |
1870 | 955 | delete_global_color(); | 1069 | } |
1871 | 956 | } | 1070 | else { |
1872 | 957 | set_config_color_scheme($response); | 1071 | delete_global_color(); |
1873 | 958 | } | 1072 | } |
1874 | 1073 | set_config_color_scheme($response); | ||
1875 | 1074 | } | ||
1876 | 959 | } | 1075 | } |
1877 | 960 | sub delete_all_colors { | 1076 | sub delete_all_colors { |
1886 | 961 | my @file_lines = main::reader( $user_config_file ); | 1077 | my @file_lines = main::reader($user_config_file); |
1887 | 962 | open( $w_fh, '>', $user_config_file ) or error_handler('open', $user_config_file, $!); | 1078 | open($w_fh, '>', $user_config_file) or main::error_handler('open', $user_config_file, $!); |
1888 | 963 | foreach ( @file_lines ) { | 1079 | foreach (@file_lines){ |
1889 | 964 | if ( $_ !~ /^(CONSOLE_COLOR_SCHEME|GLOBAL_COLOR_SCHEME|IRC_COLOR_SCHEME|IRC_CONS_COLOR_SCHEME|IRC_X_TERM_COLOR_SCHEME|VIRT_TERM_COLOR_SCHEME)/){ | 1080 | if ($_ !~ /^(CONSOLE_COLOR_SCHEME|GLOBAL_COLOR_SCHEME|IRC_COLOR_SCHEME|IRC_CONS_COLOR_SCHEME|IRC_X_TERM_COLOR_SCHEME|VIRT_TERM_COLOR_SCHEME)/){ |
1890 | 965 | print {$w_fh} "$_"; | 1081 | print {$w_fh} "$_"; |
1891 | 966 | } | 1082 | } |
1892 | 967 | } | 1083 | } |
1893 | 968 | close $w_fh; | 1084 | close $w_fh; |
1894 | 969 | } | 1085 | } |
1895 | 970 | sub delete_global_color { | 1086 | sub delete_global_color { |
1904 | 971 | my @file_lines = main::reader( $user_config_file ); | 1087 | my @file_lines = main::reader($user_config_file); |
1905 | 972 | open( $w_fh, '>', $user_config_file ) or error_handler('open', $user_config_file, $!); | 1088 | open($w_fh, '>', $user_config_file) or main::error_handler('open', $user_config_file, $!); |
1906 | 973 | foreach ( @file_lines ) { | 1089 | foreach (@file_lines){ |
1907 | 974 | if ( $_ !~ /^GLOBAL_COLOR_SCHEME/){ | 1090 | if ($_ !~ /^GLOBAL_COLOR_SCHEME/){ |
1908 | 975 | print {$w_fh} "$_"; | 1091 | print {$w_fh} "$_"; |
1909 | 976 | } | 1092 | } |
1910 | 977 | } | 1093 | } |
1911 | 978 | close $w_fh; | 1094 | close $w_fh; |
1912 | 979 | } | 1095 | } |
1913 | 980 | sub set_config_color_scheme { | 1096 | sub set_config_color_scheme { |
1929 | 981 | my $value = shift; | 1097 | my $value = shift; |
1930 | 982 | my @file_lines = main::reader( $user_config_file ); | 1098 | my @file_lines = main::reader($user_config_file); |
1931 | 983 | my $b_found = 0; | 1099 | my $b_found = 0; |
1932 | 984 | open( $w_fh, '>', $user_config_file ) or error_handler('open', $user_config_file, $!); | 1100 | open($w_fh, '>', $user_config_file) or main::error_handler('open', $user_config_file, $!); |
1933 | 985 | foreach ( @file_lines ) { | 1101 | foreach (@file_lines){ |
1934 | 986 | if ( $_ =~ /^$configs{'variable'}/ ){ | 1102 | if ($_ =~ /^$configs{'variable'}/){ |
1935 | 987 | $_ = "$configs{'variable'}=$value"; | 1103 | $_ = "$configs{'variable'}=$value"; |
1936 | 988 | $b_found = 1; | 1104 | $b_found = 1; |
1937 | 989 | } | 1105 | } |
1938 | 990 | print $w_fh "$_\n"; | 1106 | print $w_fh "$_\n"; |
1939 | 991 | } | 1107 | } |
1940 | 992 | if (! $b_found ){ | 1108 | if (!$b_found){ |
1941 | 993 | print $w_fh "$configs{'variable'}=$value\n"; | 1109 | print $w_fh "$configs{'variable'}=$value\n"; |
1942 | 994 | } | 1110 | } |
1943 | 995 | close $w_fh; | 1111 | close $w_fh; |
1944 | 996 | } | 1112 | } |
1945 | 997 | 1113 | ||
1946 | 998 | sub print_irc_message { | 1114 | sub print_irc_message { |
1961 | 999 | @data = ( | 1115 | @data = ( |
1962 | 1000 | [ 0, '', '', "$line1"], | 1116 | [ 0, '', '', "$line1"], |
1963 | 1001 | [ 0, '', '', "After finding the scheme number you like, simply run this again | 1117 | [ 0, '', '', "After finding the scheme number you like, simply run this again |
1964 | 1002 | in a terminal to set the configuration data file for your irc client. You can | 1118 | in a terminal to set the configuration data file for your irc client. You can |
1965 | 1003 | set color schemes for the following: start inxi with -c plus:"], | 1119 | set color schemes for the following: start inxi with -c plus:"], |
1966 | 1004 | [ 0, '', '', "94 (console,^not^in^desktop^-^$status{'console'})"], | 1120 | [ 0, '', '', "94 (console,^not^in^desktop^-^$status{'console'})"], |
1967 | 1005 | [ 0, '', '', "95 (terminal, desktop^-^$status{'virt-term'})"], | 1121 | [ 0, '', '', "95 (terminal, desktop^-^$status{'virt-term'})"], |
1968 | 1006 | [ 0, '', '', "96 (irc,^gui,^desktop^-^$status{'irc-gui'})"], | 1122 | [ 0, '', '', "96 (irc,^gui,^desktop^-^$status{'irc-gui'})"], |
1969 | 1007 | [ 0, '', '', "97 (irc,^desktop,^in terminal^-^$status{'irc-virt-term'})"], | 1123 | [ 0, '', '', "97 (irc,^desktop,^in terminal^-^$status{'irc-virt-term'})"], |
1970 | 1008 | [ 0, '', '', "98 (irc,^not^in^desktop^-^$status{'irc-console'})"], | 1124 | [ 0, '', '', "98 (irc,^not^in^desktop^-^$status{'irc-console'})"], |
1971 | 1009 | [ 0, '', '', "99 (global^-^$status{'global'})"] | 1125 | [ 0, '', '', "99 (global^-^$status{'global'})"] |
1972 | 1010 | ); | 1126 | ); |
1973 | 1011 | main::print_basic(@data); | 1127 | main::print_basic(\@data); |
1974 | 1012 | exit 0; | 1128 | exit 0; |
1975 | 1013 | } | 1129 | } |
1976 | 1014 | 1130 | ||
1977 | 1015 | } | 1131 | } |
1978 | @@ -1018,100 +1134,158 @@ sub print_irc_message { | |||
1979 | 1018 | #### CONFIGS | 1134 | #### CONFIGS |
1980 | 1019 | #### ------------------------------------------------------------------- | 1135 | #### ------------------------------------------------------------------- |
1981 | 1020 | 1136 | ||
2025 | 1021 | sub check_config_file { | 1137 | ## Configs |
2026 | 1022 | $user_config_file = "$user_config_dir/$self_name.conf"; | 1138 | # public: set() check_file() |
2027 | 1023 | if ( ! -f $user_config_file ){ | 1139 | { |
2028 | 1024 | open( my $fh, '>', $user_config_file ) or error_handler('create', $user_config_file, $!); | 1140 | package Configs; |
2029 | 1025 | } | 1141 | sub set { |
2030 | 1026 | } | 1142 | my ($configs) = @_; |
2031 | 1027 | 1143 | my ($key, $val,@config_files); | |
2032 | 1028 | sub get_configs { | 1144 | if (!$configs){ |
2033 | 1029 | my (@configs) = @_; | 1145 | @config_files = ( |
2034 | 1030 | my ($key, $val,@config_files); | 1146 | qq(/etc/$self_name.conf), |
2035 | 1031 | if (!@configs){ | 1147 | qq($user_config_dir/$self_name.conf) |
2036 | 1032 | @config_files = ( | 1148 | ); |
2037 | 1033 | qq(/etc/$self_name.conf), | 1149 | } |
2038 | 1034 | qq($user_config_dir/$self_name.conf) | 1150 | else { |
2039 | 1035 | ); | 1151 | @config_files = @$configs; |
2040 | 1036 | } | 1152 | } |
2041 | 1037 | else { | 1153 | # Config files should be passed in an array as a param to this function. |
2042 | 1038 | @config_files = (@configs); | 1154 | # Default intended use: global @CONFIGS; |
2043 | 1039 | } | 1155 | foreach (@config_files){ |
2044 | 1040 | # Config files should be passed in an array as a param to this function. | 1156 | next unless open(my $fh, '<', "$_"); |
2045 | 1041 | # Default intended use: global @CONFIGS; | 1157 | while (<$fh>){ |
2046 | 1042 | foreach (@config_files) { | 1158 | chomp; |
2047 | 1043 | next unless open (my $fh, '<', "$_"); | 1159 | s/#.*//; |
2048 | 1044 | while (<$fh>) { | 1160 | s/^\s+//; |
2049 | 1045 | chomp; | 1161 | s/\s+$//; |
2050 | 1046 | s/#.*//; | 1162 | s/'|"//g; |
2051 | 1047 | s/^\s+//; | 1163 | s/true/1/i; # switch to 1/0 perl boolean |
2052 | 1048 | s/\s+$//; | 1164 | s/false/0/i; # switch to 1/0 perl boolean |
2053 | 1049 | s/'|"//g; | 1165 | next unless length; |
2054 | 1050 | s/true/1/i; # switch to 1/0 perl boolean | 1166 | ($key, $val) = split(/\s*=\s*/, $_, 2); |
2055 | 1051 | s/false/0/i; # switch to 1/0 perl boolean | 1167 | next unless length($val); |
2056 | 1052 | next unless length; | 1168 | process_item($key,$val); |
2057 | 1053 | ($key, $val) = split(/\s*=\s*/, $_, 2); | 1169 | # print "f: $file key: $key val: $val\n"; |
2058 | 1054 | next unless length($val); | 1170 | } |
2059 | 1055 | get_config_item($key,$val); | 1171 | close $fh; |
2060 | 1056 | # print "f: $file key: $key val: $val\n"; | 1172 | } |
2061 | 1057 | } | 1173 | } |
2062 | 1058 | close $fh; | 1174 | # note: someone managed to make a config file with corrupted values, so check |
2063 | 1059 | } | 1175 | # int explicitly, don't assume it was done correctly. |
2021 | 1060 | } | ||
2022 | 1061 | |||
2023 | 1062 | # note: someone managed to make a config file with corrupted values, so check int | ||
2024 | 1063 | # explicitly, don't assume it was done correctly. | ||
2064 | 1064 | # args: 0: key; 1: value | 1176 | # args: 0: key; 1: value |
2115 | 1065 | sub get_config_item { | 1177 | sub process_item { |
2116 | 1066 | my ($key,$val) = @_; | 1178 | my ($key,$val) = @_; |
2117 | 1067 | if ($key eq 'ALLOW_UPDATE' || $key eq 'B_ALLOW_UPDATE') {$b_update = $val if is_int($val)} | 1179 | if ($key eq 'ALLOW_UPDATE' || $key eq 'B_ALLOW_UPDATE'){ |
2118 | 1068 | elsif ($key eq 'ALLOW_WEATHER' || $key eq 'B_ALLOW_WEATHER') {$b_weather = $val if is_int($val)} | 1180 | $use{'update'} = $val if main::is_int($val)} |
2119 | 1069 | elsif ($key eq 'CPU_SLEEP') {$cpu_sleep = $val if is_numeric($val)} | 1181 | elsif ($key eq 'ALLOW_WEATHER' || $key eq 'B_ALLOW_WEATHER'){ |
2120 | 1070 | elsif ($key eq 'DL_TIMEOUT') {$dl_timeout = $val if is_int($val)} | 1182 | $use{'weather'} = $val if main::is_int($val)} |
2121 | 1071 | elsif ($key eq 'DOWNLOADER') { | 1183 | elsif ($key eq 'CPU_SLEEP'){ |
2122 | 1072 | if ($val =~ /^(curl|fetch|ftp|perl|wget)$/){ | 1184 | $cpu_sleep = $val if main::is_numeric($val)} |
2123 | 1073 | # this dumps all the other data and resets %dl for only the | 1185 | elsif ($key eq 'DL_TIMEOUT'){ |
2124 | 1074 | # desired downloader. | 1186 | $dl_timeout = $val if main::is_int($val)} |
2125 | 1075 | $val = set_perl_downloader($val); | 1187 | elsif ($key eq 'DOWNLOADER'){ |
2126 | 1076 | %dl = ('dl' => $val, $val => 1); | 1188 | if ($val =~ /^(curl|fetch|ftp|perl|wget)$/){ |
2127 | 1077 | }} | 1189 | # this dumps all the other data and resets %dl for only the |
2128 | 1078 | elsif ($key eq 'FILTER_STRING') {$filter_string = $val} | 1190 | # desired downloader. |
2129 | 1079 | elsif ($key eq 'LANGUAGE') {$language = $val if $val =~ /^(en)$/} | 1191 | $val = main::set_perl_downloader($val); |
2130 | 1080 | elsif ($key eq 'LIMIT') {$limit = $val if is_int($val)} | 1192 | %dl = ('dl' => $val, $val => 1); |
2131 | 1081 | elsif ($key eq 'OUTPUT_TYPE') {$output_type = $val if $val =~ /^(json|screen|xml)$/} | 1193 | }} |
2132 | 1082 | elsif ($key eq 'PARTITION_SORT') {$show{'partition-sort'} = $val if ($val =~ /^(dev-base|fs|id|label|percent-used|size|uuid|used)$/) } | 1194 | elsif ($key eq 'FILTER_STRING'){ |
2133 | 1083 | elsif ($key eq 'PS_COUNT') {$ps_count = $val if is_int($val) } | 1195 | $filter_string = $val} |
2134 | 1084 | elsif ($key eq 'SENSORS_CPU_NO') {$sensors_cpu_nu = $val if is_int($val)} | 1196 | elsif ($key eq 'LANGUAGE'){ |
2135 | 1085 | elsif ($key eq 'SHOW_HOST' || $key eq 'B_SHOW_HOST') { $show{'host'} = $val if is_int($val)} | 1197 | $language = $val if $val =~ /^(en)$/} |
2136 | 1086 | elsif ($key eq 'USB_SYS') {$b_usb_sys = $val if is_int($val)} | 1198 | elsif ($key eq 'LIMIT'){ |
2137 | 1087 | elsif ($key eq 'WEATHER_UNIT') { | 1199 | $limit = $val if main::is_int($val)} |
2138 | 1088 | $val = lc($val) if $val; | 1200 | elsif ($key eq 'OUTPUT_TYPE'){ |
2139 | 1089 | if ($val && $val =~ /^(c|f|cf|fc|i|m|im|mi)$/){ | 1201 | $output_type = $val if $val =~ /^(json|screen|xml)$/} |
2140 | 1090 | my %units = ('c'=>'m','f'=>'i','cf'=>'mi','fc'=>'im'); | 1202 | elsif ($key eq 'NO_DIG'){ |
2141 | 1091 | $val = $units{$val} if defined $units{$val}; | 1203 | $force{'no-dig'} = $val if main::is_int($val)} |
2142 | 1092 | $weather_unit = $val; | 1204 | elsif ($key eq 'NO_DOAS'){ |
2143 | 1093 | } | 1205 | $force{'no-doas'} = $val if main::is_int($val)} |
2144 | 1094 | } | 1206 | elsif ($key eq 'NO_HTML_WAN'){ |
2145 | 1095 | # layout | 1207 | $force{'no-html-wan'} = $val if main::is_int($val)} |
2146 | 1096 | elsif ($key eq 'CONSOLE_COLOR_SCHEME') {$colors{'console'} = $val if is_int($val)} | 1208 | elsif ($key eq 'NO_SUDO'){ |
2147 | 1097 | elsif ($key eq 'GLOBAL_COLOR_SCHEME') {$colors{'global'} = $val if is_int($val)} | 1209 | $force{'no-sudo'} = $val if main::is_int($val)} |
2148 | 1098 | elsif ($key eq 'IRC_COLOR_SCHEME') {$colors{'irc-gui'} = $val if is_int($val)} | 1210 | elsif ($key eq 'PARTITION_SORT'){ |
2149 | 1099 | elsif ($key eq 'IRC_CONS_COLOR_SCHEME') {$colors{'irc-console'} = $val if is_int($val)} | 1211 | if ($val =~ /^(dev-base|fs|id|label|percent-used|size|uuid|used)$/){ |
2150 | 1100 | elsif ($key eq 'IRC_X_TERM_COLOR_SCHEME') {$colors{'irc-virt-term'} = $val if is_int($val)} | 1212 | $show{'partition-sort'} = $val; |
2151 | 1101 | elsif ($key eq 'VIRT_TERM_COLOR_SCHEME') {$colors{'virt-term'} = $val if is_int($val)} | 1213 | }} |
2152 | 1102 | # note: not using the old short SEP1/SEP2 | 1214 | elsif ($key eq 'PS_COUNT'){ |
2153 | 1103 | elsif ($key eq 'SEP1_IRC') {$sep{'s1-irc'} = $val} | 1215 | $ps_count = $val if main::is_int($val) } |
2154 | 1104 | elsif ($key eq 'SEP1_CONSOLE') {$sep{'s1-console'} = $val} | 1216 | elsif ($key eq 'SENSORS_CPU_NO'){ |
2155 | 1105 | elsif ($key eq 'SEP2_IRC') {$sep{'s2-irc'} = $val} | 1217 | $sensors_cpu_nu = $val if main::is_int($val)} |
2156 | 1106 | elsif ($key eq 'SEP2_CONSOLE') {$sep{'s2-console'} = $val} | 1218 | elsif ($key eq 'SENSORS_EXCLUDE'){ |
2157 | 1107 | # size | 1219 | @sensors_exclude = split(/\s*,\s*/, $val) if $val} |
2158 | 1108 | elsif ($key eq 'COLS_MAX_CONSOLE') {$size{'console'} = $val if is_int($val)} | 1220 | elsif ($key eq 'SENSORS_USE'){ |
2159 | 1109 | elsif ($key eq 'COLS_MAX_IRC') {$size{'irc'} = $val if is_int($val)} | 1221 | @sensors_use = split(/\s*,\s*/, $val) if $val} |
2160 | 1110 | elsif ($key eq 'COLS_MAX_NO_DISPLAY') {$size{'no-display'} = $val if is_int($val)} | 1222 | elsif ($key eq 'SHOW_HOST' || $key eq 'B_SHOW_HOST'){ |
2161 | 1111 | elsif ($key eq 'INDENT') {$size{'indent'} = $val if is_int($val)} | 1223 | if (main::is_int($val)){ |
2162 | 1112 | elsif ($key eq 'INDENT_MIN') {$size{'indent-min'} = $val if is_int($val)} | 1224 | $show{'host'} = $val; |
2163 | 1113 | # print "mc: key: $key val: $val\n"; | 1225 | $show{'no-host'} = 1 if !$show{'host'}; |
2164 | 1114 | # print Dumper (keys %size) . "\n"; | 1226 | } |
2165 | 1227 | } | ||
2166 | 1228 | elsif ($key eq 'USB_SYS'){ | ||
2167 | 1229 | $force{'usb-sys'} = $val if main::is_int($val)} | ||
2168 | 1230 | elsif ($key eq 'WAN_IP_URL'){ | ||
2169 | 1231 | if ($val =~ /^(ht|f)tp[s]?:\//i){ | ||
2170 | 1232 | $wan_url = $val; | ||
2171 | 1233 | $force{'no-dig'} = 1; | ||
2172 | 1234 | } | ||
2173 | 1235 | } | ||
2174 | 1236 | elsif ($key eq 'WEATHER_SOURCE'){ | ||
2175 | 1237 | $weather_source = $val if main::is_int($val)} | ||
2176 | 1238 | elsif ($key eq 'WEATHER_UNIT'){ | ||
2177 | 1239 | $val = lc($val) if $val; | ||
2178 | 1240 | if ($val && $val =~ /^(c|f|cf|fc|i|m|im|mi)$/){ | ||
2179 | 1241 | my %units = ('c'=>'m','f'=>'i','cf'=>'mi','fc'=>'im'); | ||
2180 | 1242 | $val = $units{$val} if defined $units{$val}; | ||
2181 | 1243 | $weather_unit = $val; | ||
2182 | 1244 | } | ||
2183 | 1245 | } | ||
2184 | 1246 | # layout | ||
2185 | 1247 | elsif ($key eq 'CONSOLE_COLOR_SCHEME'){ | ||
2186 | 1248 | $colors{'console'} = $val if main::is_int($val)} | ||
2187 | 1249 | elsif ($key eq 'GLOBAL_COLOR_SCHEME'){ | ||
2188 | 1250 | $colors{'global'} = $val if main::is_int($val)} | ||
2189 | 1251 | elsif ($key eq 'IRC_COLOR_SCHEME'){ | ||
2190 | 1252 | $colors{'irc-gui'} = $val if main::is_int($val)} | ||
2191 | 1253 | elsif ($key eq 'IRC_CONS_COLOR_SCHEME'){ | ||
2192 | 1254 | $colors{'irc-console'} = $val if main::is_int($val)} | ||
2193 | 1255 | elsif ($key eq 'IRC_X_TERM_COLOR_SCHEME'){ | ||
2194 | 1256 | $colors{'irc-virt-term'} = $val if main::is_int($val)} | ||
2195 | 1257 | elsif ($key eq 'VIRT_TERM_COLOR_SCHEME'){ | ||
2196 | 1258 | $colors{'virt-term'} = $val if main::is_int($val)} | ||
2197 | 1259 | # note: not using the old short SEP1/SEP2 | ||
2198 | 1260 | elsif ($key eq 'SEP1_IRC'){ | ||
2199 | 1261 | $sep{'s1-irc'} = $val} | ||
2200 | 1262 | elsif ($key eq 'SEP1_CONSOLE'){ | ||
2201 | 1263 | $sep{'s1-console'} = $val} | ||
2202 | 1264 | elsif ($key eq 'SEP2_IRC'){ | ||
2203 | 1265 | $sep{'s2-irc'} = $val} | ||
2204 | 1266 | elsif ($key eq 'SEP2_CONSOLE'){ | ||
2205 | 1267 | $sep{'s2-console'} = $val} | ||
2206 | 1268 | # size | ||
2207 | 1269 | elsif ($key eq 'COLS_MAX_CONSOLE'){ | ||
2208 | 1270 | $size{'console'} = $val if main::is_int($val)} | ||
2209 | 1271 | elsif ($key eq 'COLS_MAX_IRC'){ | ||
2210 | 1272 | $size{'irc'} = $val if main::is_int($val)} | ||
2211 | 1273 | elsif ($key eq 'COLS_MAX_NO_DISPLAY'){ | ||
2212 | 1274 | $size{'no-display'} = $val if main::is_int($val)} | ||
2213 | 1275 | elsif ($key eq 'INDENT'){ | ||
2214 | 1276 | $size{'indent'} = $val if main::is_int($val)} | ||
2215 | 1277 | elsif ($key eq 'WRAP_MAX' || $key eq 'INDENT_MIN'){ | ||
2216 | 1278 | $size{'wrap-max'} = $val if main::is_int($val)} | ||
2217 | 1279 | # print "mc: key: $key val: $val\n"; | ||
2218 | 1280 | # print Dumper (keys %size) . "\n"; | ||
2219 | 1281 | } | ||
2220 | 1282 | sub check_file { | ||
2221 | 1283 | $user_config_file = "$user_config_dir/$self_name.conf"; | ||
2222 | 1284 | if (! -f $user_config_file){ | ||
2223 | 1285 | open(my $fh, '>', $user_config_file) or | ||
2224 | 1286 | main::error_handler('create', $user_config_file, $!); | ||
2225 | 1287 | } | ||
2226 | 1288 | } | ||
2227 | 1115 | } | 1289 | } |
2228 | 1116 | 1290 | ||
2229 | 1117 | #### ------------------------------------------------------------------- | 1291 | #### ------------------------------------------------------------------- |
2230 | @@ -1122,40 +1296,40 @@ sub get_config_item { | |||
2231 | 1122 | # as soon as possible # will have max 3 files, inxi.log, inxi.1.log, | 1296 | # as soon as possible # will have max 3 files, inxi.log, inxi.1.log, |
2232 | 1123 | # inxi.2.log | 1297 | # inxi.2.log |
2233 | 1124 | sub begin_logging { | 1298 | sub begin_logging { |
2268 | 1125 | return 1 if $fh_l; # if we want to start logging for testing before options | 1299 | return 1 if $fh_l; # if we want to start logging for testing before options |
2269 | 1126 | my $log_file_2="$user_data_dir/$self_name.1.log"; | 1300 | my $log_file_2="$user_data_dir/$self_name.1.log"; |
2270 | 1127 | my $log_file_3="$user_data_dir/$self_name.2.log"; | 1301 | my $log_file_3="$user_data_dir/$self_name.2.log"; |
2271 | 1128 | my $data = ''; | 1302 | my $data = ''; |
2272 | 1129 | $end='main::log_data("fe", (caller(1))[3], "");'; | 1303 | $end='main::log_data("fe", (caller(1))[3], "");'; |
2273 | 1130 | $start='main::log_data("fs", (caller(1))[3], \@_);'; | 1304 | $start='main::log_data("fs", (caller(1))[3], \@_);'; |
2274 | 1131 | #$t3 = tv_interval ($t0, [gettimeofday]); | 1305 | #$t3 = tv_interval ($t0, [gettimeofday]); |
2275 | 1132 | $t3 = eval 'Time::HiRes::tv_interval (\@t0, [Time::HiRes::gettimeofday()]);' if $b_hires; | 1306 | $t3 = eval 'Time::HiRes::tv_interval (\@t0, [Time::HiRes::gettimeofday()]);' if $b_hires; |
2276 | 1133 | #print Dumper $@; | 1307 | # print Dumper $@; |
2277 | 1134 | my $now = strftime "%Y-%m-%d %H:%M:%S", localtime; | 1308 | my $now = strftime "%Y-%m-%d %H:%M:%S", localtime; |
2278 | 1135 | return if $debugger{'timers'}; | 1309 | return if $debugger{'timers'}; |
2279 | 1136 | # do the rotation if logfile exists | 1310 | # do the rotation if logfile exists |
2280 | 1137 | if ( -f $log_file ){ | 1311 | if (-f $log_file){ |
2281 | 1138 | # copy if present second to third | 1312 | # copy if present second to third |
2282 | 1139 | if ( -f $log_file_2 ){ | 1313 | if (-f $log_file_2){ |
2283 | 1140 | rename $log_file_2, $log_file_3 or error_handler('rename', "$log_file_2 -> $log_file_3", "$!"); | 1314 | rename $log_file_2, $log_file_3 or error_handler('rename', "$log_file_2 -> $log_file_3", "$!"); |
2284 | 1141 | } | 1315 | } |
2285 | 1142 | # then copy initial to second | 1316 | # then copy initial to second |
2286 | 1143 | rename $log_file, $log_file_2 or error_handler('rename', "$log_file -> $log_file_2", "$!"); | 1317 | rename $log_file, $log_file_2 or error_handler('rename', "$log_file -> $log_file_2", "$!"); |
2287 | 1144 | } | 1318 | } |
2288 | 1145 | # now create the logfile | 1319 | # now create the logfile |
2289 | 1146 | # print "Opening log file for reading: $log_file\n"; | 1320 | # print "Opening log file for reading: $log_file\n"; |
2290 | 1147 | open $fh_l, '>', $log_file or error_handler(4, $log_file, "$!"); | 1321 | open($fh_l, '>', $log_file) or error_handler(4, $log_file, "$!"); |
2291 | 1148 | # and echo the start data | 1322 | # and echo the start data |
2292 | 1149 | $data = $line2; | 1323 | $data = $line2; |
2293 | 1150 | $data .= "START $self_name LOGGING:\n"; | 1324 | $data .= "START $self_name LOGGING:\n"; |
2294 | 1151 | $data .= "NOTE: HiRes timer not available.\n" if !$b_hires; | 1325 | $data .= "NOTE: HiRes timer not available.\n" if !$b_hires; |
2295 | 1152 | $data .= "$now\n"; | 1326 | $data .= "$now\n"; |
2296 | 1153 | $data .= "Elapsed since start: $t3\n"; | 1327 | $data .= "Elapsed since start: $t3\n"; |
2297 | 1154 | $data .= "n: $self_name v: $self_version p: $self_patch d: $self_date\n"; | 1328 | $data .= "n: $self_name v: $self_version p: $self_patch d: $self_date\n"; |
2298 | 1155 | $data .= '@paths:' . joiner(\@paths, '::', 'unset') . "\n"; | 1329 | $data .= '@paths:' . joiner(\@paths, '::', 'unset') . "\n"; |
2299 | 1156 | $data .= $line2; | 1330 | $data .= $line2; |
2300 | 1157 | 1331 | ||
2301 | 1158 | print $fh_l $data; | 1332 | print $fh_l $data; |
2302 | 1159 | } | 1333 | } |
2303 | 1160 | 1334 | ||
2304 | 1161 | # NOTE: no logging available until get_parameters is run, since that's what | 1335 | # NOTE: no logging available until get_parameters is run, since that's what |
2305 | @@ -1166,985 +1340,1120 @@ sub begin_logging { | |||
2306 | 1166 | # arg: $one type (fs/fe/cat/dump/raw) or logged data; | 1340 | # arg: $one type (fs/fe/cat/dump/raw) or logged data; |
2307 | 1167 | # [$two is function name; [$three - function args]] | 1341 | # [$two is function name; [$three - function args]] |
2308 | 1168 | sub log_data { | 1342 | sub log_data { |
2387 | 1169 | return if ! $b_log; | 1343 | return if !$b_log; |
2388 | 1170 | my ($one, $two, $three) = @_; | 1344 | my ($one, $two, $three) = @_; |
2389 | 1171 | my ($args,$data,$timer) = ('','',''); | 1345 | my ($args,$data,$timer) = ('','',''); |
2390 | 1172 | my $spacer = ' '; | 1346 | my $spacer = ' '; |
2391 | 1173 | # print "1: $one 2: $two 3: $three\n"; | 1347 | # print "1: $one 2: $two 3: $three\n"; |
2392 | 1174 | if ($one eq 'fs') { | 1348 | if ($one eq 'fs'){ |
2393 | 1175 | if (ref $three eq 'ARRAY'){ | 1349 | if (ref $three eq 'ARRAY'){ |
2394 | 1176 | my @temp = @$three; | 1350 | # print Data::Dumper::Dumper $three; |
2395 | 1177 | # print Data::Dumper::Dumper \@$three; | 1351 | $args = "\n${spacer}Args: " . joiner($three, '; ', 'unset'); |
2396 | 1178 | $args = "\n${spacer}Args: " . joiner($three, '; ', 'unset'); | 1352 | } |
2397 | 1179 | } | 1353 | else { |
2398 | 1180 | else { | 1354 | $args = "\n${spacer}Args: None"; |
2399 | 1181 | $args = "\n${spacer}Args: None"; | 1355 | } |
2400 | 1182 | } | 1356 | # $t1 = [gettimeofday]; |
2401 | 1183 | # $t1 = [gettimeofday]; | 1357 | #$t3 = tv_interval ($t0, [gettimeofday]); |
2402 | 1184 | #$t3 = tv_interval ($t0, [gettimeofday]); | 1358 | $t3 = eval 'Time::HiRes::tv_interval(\@t0, [Time::HiRes::gettimeofday()])' if $b_hires; |
2403 | 1185 | $t3 = eval 'Time::HiRes::tv_interval(\@t0, [Time::HiRes::gettimeofday()])' if $b_hires; | 1359 | # print Dumper $@; |
2404 | 1186 | #print Dumper $@; | 1360 | $data = "Start: Function: $two$args\n${spacer}Elapsed: $t3\n"; |
2405 | 1187 | $data = "Start: Function: $two$args\n${spacer}Elapsed: $t3\n"; | 1361 | $spacer=''; |
2406 | 1188 | $spacer=''; | 1362 | $timer = $data if $debugger{'timers'}; |
2407 | 1189 | $timer = $data if $debugger{'timers'}; | 1363 | } |
2408 | 1190 | } | 1364 | elsif ($one eq 'fe'){ |
2409 | 1191 | elsif ( $one eq 'fe') { | 1365 | # print 'timer:', Time::HiRes::tv_interval(\@t0, [Time::HiRes::gettimeofday()]),"\n"; |
2410 | 1192 | # print 'timer:', Time::HiRes::tv_interval(\@t0, [Time::HiRes::gettimeofday()]),"\n"; | 1366 | #$t3 = tv_interval ($t0, [gettimeofday]); |
2411 | 1193 | #$t3 = tv_interval ($t0, [gettimeofday]); | 1367 | eval '$t3 = Time::HiRes::tv_interval(\@t0, [Time::HiRes::gettimeofday()])' if $b_hires; |
2412 | 1194 | eval '$t3 = Time::HiRes::tv_interval(\@t0, [Time::HiRes::gettimeofday()])' if $b_hires; | 1368 | # print Dumper $t3; |
2413 | 1195 | #print Dumper $t3; | 1369 | $data = "${spacer}Elapsed: $t3\nEnd: Function: $two\n"; |
2414 | 1196 | $data = "${spacer}Elapsed: $t3\nEnd: Function: $two\n"; | 1370 | $spacer=''; |
2415 | 1197 | $spacer=''; | 1371 | $timer = $data if $debugger{'timers'}; |
2416 | 1198 | $timer = $data if $debugger{'timers'}; | 1372 | } |
2417 | 1199 | } | 1373 | elsif ($one eq 'cat'){ |
2418 | 1200 | elsif ( $one eq 'cat') { | 1374 | if ($b_log_full){ |
2419 | 1201 | if ( $b_log_full ){ | 1375 | foreach my $file ($two){ |
2420 | 1202 | for my $file ($two){ | 1376 | my $contents = do { local(@ARGV, $/) = $file; <> }; # or: qx(cat $file) |
2421 | 1203 | my $contents = do { local( @ARGV, $/ ) = $file; <> }; # or: qx(cat $file) | 1377 | $data = "$data${line3}Full file data: $file\n\n$contents\n$line3\n"; |
2422 | 1204 | $data = "$data${line3}Full file data: $file\n\n$contents\n$line3\n"; | 1378 | } |
2423 | 1205 | } | 1379 | $spacer=''; |
2424 | 1206 | $spacer=''; | 1380 | } |
2425 | 1207 | } | 1381 | } |
2426 | 1208 | } | 1382 | elsif ($one eq 'cmd'){ |
2427 | 1209 | elsif ($one eq 'cmd'){ | 1383 | $data = "Command: $two\n"; |
2428 | 1210 | $data = "Command: $two\n"; | 1384 | $data .= qx($two); |
2429 | 1211 | $data .= qx($two); | 1385 | } |
2430 | 1212 | } | 1386 | elsif ($one eq 'data'){ |
2431 | 1213 | elsif ($one eq 'data'){ | 1387 | $data = "$two\n"; |
2432 | 1214 | $data = "$two\n"; | 1388 | } |
2433 | 1215 | } | 1389 | elsif ($one eq 'dump'){ |
2434 | 1216 | elsif ( $one eq 'dump') { | 1390 | $data = "$two:\n"; |
2435 | 1217 | $data = "$two:\n"; | 1391 | if (ref $three eq 'HASH'){ |
2436 | 1218 | if (ref $three eq 'HASH'){ | 1392 | $data .= Data::Dumper::Dumper $three; |
2437 | 1219 | $data .= Data::Dumper::Dumper \%$three; | 1393 | } |
2438 | 1220 | } | 1394 | elsif (ref $three eq 'ARRAY'){ |
2439 | 1221 | elsif (ref $three eq 'ARRAY'){ | 1395 | # print Data::Dumper::Dumper $three; |
2440 | 1222 | # print Data::Dumper::Dumper \@$three; | 1396 | $data .= Data::Dumper::Dumper $three; |
2441 | 1223 | $data .= Data::Dumper::Dumper \@$three; | 1397 | } |
2442 | 1224 | } | 1398 | else { |
2443 | 1225 | else { | 1399 | $data .= Data::Dumper::Dumper $three; |
2444 | 1226 | $data .= Data::Dumper::Dumper $three; | 1400 | } |
2445 | 1227 | } | 1401 | $data .= "\n"; |
2446 | 1228 | $data .= "\n"; | 1402 | # print $data; |
2447 | 1229 | # print $data; | 1403 | } |
2448 | 1230 | } | 1404 | elsif ($one eq 'raw'){ |
2449 | 1231 | elsif ( $one eq 'raw') { | 1405 | if ($b_log_full){ |
2450 | 1232 | if ( $b_log_full ){ | 1406 | $data = "\n${line3}Raw System Data:\n\n$two\n$line3"; |
2451 | 1233 | $data = "\n${line3}Raw System Data:\n\n$two\n$line3"; | 1407 | $spacer=''; |
2452 | 1234 | $spacer=''; | 1408 | } |
2453 | 1235 | } | 1409 | } |
2454 | 1236 | } | 1410 | else { |
2455 | 1237 | else { | 1411 | $data = "$two\n"; |
2456 | 1238 | $data = "$two\n"; | 1412 | } |
2457 | 1239 | } | 1413 | if ($debugger{'timers'}){ |
2458 | 1240 | if ($debugger{'timers'}){ | 1414 | print $timer if $timer; |
2459 | 1241 | print $timer if $timer; | 1415 | } |
2460 | 1242 | } | 1416 | # print "d: $data"; |
2461 | 1243 | #print "d: $data"; | 1417 | elsif ($data){ |
2462 | 1244 | elsif ($data){ | 1418 | print $fh_l "$spacer$data"; |
2463 | 1245 | print $fh_l "$spacer$data"; | 1419 | } |
2386 | 1246 | } | ||
2464 | 1247 | } | 1420 | } |
2465 | 1248 | 1421 | ||
2466 | 1249 | sub set_debugger { | 1422 | sub set_debugger { |
2498 | 1250 | user_debug_test_1() if $debugger{'test-1'}; | 1423 | user_debug_test_1() if $debugger{'test-1'}; |
2499 | 1251 | if ( $debug >= 20){ | 1424 | if ($debugger{'level'} >= 20){ |
2500 | 1252 | error_handler('not-in-irc', 'debug data generator') if $b_irc; | 1425 | error_handler('not-in-irc', 'debug data generator') if $b_irc; |
2501 | 1253 | my $option = ( $debug > 22 ) ? 'main-full' : 'main'; | 1426 | my $option = ($debugger{'level'} > 22) ? 'main-full' : 'main'; |
2502 | 1254 | $debugger{'gz'} = 1 if ($debug == 22 || $debug == 24); | 1427 | $debugger{'gz'} = 1 if ($debugger{'level'} == 22 || $debugger{'level'} == 24); |
2503 | 1255 | my $ob_sys = SystemDebugger->new($option); | 1428 | my $ob_sys = SystemDebugger->new($option); |
2504 | 1256 | $ob_sys->run_debugger(); | 1429 | $ob_sys->run_debugger(); |
2505 | 1257 | $ob_sys->upload_file($ftp_alt) if $debug > 20; | 1430 | $ob_sys->upload_file($ftp_alt) if $debugger{'level'} > 20; |
2506 | 1258 | exit 0; | 1431 | exit 0; |
2507 | 1259 | } | 1432 | } |
2508 | 1260 | elsif ($debug >= 10 && $debug <= 12){ | 1433 | elsif ($debugger{'level'} >= 10 && $debugger{'level'} <= 12){ |
2509 | 1261 | $b_log = 1; | 1434 | $b_log = 1; |
2510 | 1262 | if ($debug == 11){ | 1435 | if ($debugger{'level'} == 11){ |
2511 | 1263 | $b_log_full = 1; | 1436 | $b_log_full = 1; |
2512 | 1264 | } | 1437 | } |
2513 | 1265 | elsif ($debug == 12){ | 1438 | elsif ($debugger{'level'} == 12){ |
2514 | 1266 | $b_log_colors = 1; | 1439 | $b_log_colors = 1; |
2515 | 1267 | } | 1440 | } |
2516 | 1268 | begin_logging(); | 1441 | begin_logging(); |
2517 | 1269 | } | 1442 | } |
2518 | 1270 | elsif ($debug <= 3){ | 1443 | elsif ($debugger{'level'} <= 3){ |
2519 | 1271 | if ($debug == 3){ | 1444 | if ($debugger{'level'} == 3){ |
2520 | 1272 | $b_log = 1; | 1445 | $b_log = 1; |
2521 | 1273 | $debugger{'timers'} = 1; | 1446 | $debugger{'timers'} = 1; |
2522 | 1274 | begin_logging(); | 1447 | begin_logging(); |
2523 | 1275 | } | 1448 | } |
2524 | 1276 | else { | 1449 | else { |
2525 | 1277 | $end = ''; | 1450 | $end = ''; |
2526 | 1278 | $start = ''; | 1451 | $start = ''; |
2527 | 1279 | } | 1452 | } |
2528 | 1280 | } | 1453 | } |
2529 | 1281 | } | 1454 | } |
2530 | 1282 | 1455 | ||
2531 | 1283 | ## SystemDebugger | 1456 | ## SystemDebugger |
2532 | 1284 | { | 1457 | { |
2533 | 1285 | package SystemDebugger; | 1458 | package SystemDebugger; |
2534 | 1286 | |||
2535 | 1287 | # use File::Find q(find); | ||
2536 | 1288 | #no warnings 'File::Find'; | ||
2537 | 1289 | # use File::Spec::Functions; | ||
2538 | 1290 | #use File::Copy; | ||
2539 | 1291 | #use POSIX qw(strftime); | ||
2540 | 1292 | |||
2541 | 1293 | my $option = 'main'; | 1459 | my $option = 'main'; |
2542 | 1294 | my ($data_dir,$debug_dir,$debug_gz,$parse_src,$upload) = ('','','','',''); | 1460 | my ($data_dir,$debug_dir,$debug_gz,$parse_src,$upload) = ('','','','',''); |
2544 | 1295 | my @content = (); | 1461 | my @content; |
2545 | 1296 | my $b_debug = 0; | 1462 | my $b_debug = 0; |
2546 | 1297 | my $b_delete_dir = 1; | 1463 | my $b_delete_dir = 1; |
2547 | 1298 | # args: 1 - type | 1464 | # args: 1 - type |
2548 | 1299 | # args: 2 - upload | 1465 | # args: 2 - upload |
2549 | 1300 | sub new { | 1466 | sub new { |
2556 | 1301 | my $class = shift; | 1467 | my $class = shift; |
2557 | 1302 | ($option) = @_; | 1468 | ($option) = @_; |
2558 | 1303 | my $self = {}; | 1469 | my $self = {}; |
2559 | 1304 | # print "$f\n"; | 1470 | # print "$f\n"; |
2560 | 1305 | # print "$option\n"; | 1471 | # print "$option\n"; |
2561 | 1306 | return bless $self, $class; | 1472 | return bless $self, $class; |
2562 | 1307 | } | 1473 | } |
2563 | 1308 | 1474 | ||
2564 | 1309 | sub run_debugger { | 1475 | sub run_debugger { |
2612 | 1310 | #require File::Find; | 1476 | print "Starting $self_name debugging data collector...\n"; |
2613 | 1311 | #import File::Find::Functions; | 1477 | print "Loading required debugger Perl File:: modules... \n"; |
2614 | 1312 | require File::Copy; | 1478 | # Fedora/Redhat doesn't include File::Find File::Copy in |
2615 | 1313 | import File::Copy; | 1479 | # core modules. why? Or rather, they deliberately removed them. |
2616 | 1314 | require File::Spec::Functions; | 1480 | if (main::check_perl_module('File::Find')){ |
2617 | 1315 | import File::Spec::Functions; | 1481 | File::Find->import; |
2618 | 1316 | 1482 | } | |
2619 | 1317 | print "Starting $self_name debugging data collector...\n"; | 1483 | else { |
2620 | 1318 | create_debug_directory(); | 1484 | main::error_handler('required-module', 'File', 'File::Find'); |
2621 | 1319 | print "Note: for dmidecode data you must be root.\n" if !$b_root; | 1485 | } |
2622 | 1320 | print $line3; | 1486 | if (main::check_perl_module('File::Copy')){ |
2623 | 1321 | if (!$b_debug){ | 1487 | File::Copy->import; |
2624 | 1322 | audio_data(); | 1488 | } |
2625 | 1323 | disk_data(); | 1489 | else { |
2626 | 1324 | display_data(); | 1490 | main::error_handler('required-module', 'File', 'File::Copy'); |
2627 | 1325 | network_data(); | 1491 | } |
2628 | 1326 | perl_modules(); | 1492 | if (main::check_perl_module('File::Spec::Functions')){ |
2629 | 1327 | system_data(); | 1493 | File::Spec::Functions->import; |
2630 | 1328 | } | 1494 | } |
2631 | 1329 | system_files(); | 1495 | else { |
2632 | 1330 | print $line3; | 1496 | main::error_handler('required-module', 'File', 'File::Spec::Functions'); |
2633 | 1331 | if (!$b_debug){ | 1497 | } |
2634 | 1332 | # note: android has unreadable /sys, but -x and -r tests pass | 1498 | if ($debugger{'level'} > 20){ |
2635 | 1333 | # main::globber('/sys/*') && | 1499 | if (main::check_perl_module('Net::FTP')){ |
2636 | 1334 | if ( main::count_dir_files('/sys') ){ | 1500 | Net::FTP->import; |
2637 | 1335 | build_tree('sys'); | 1501 | } |
2638 | 1336 | # kernel crash, not sure what creates it, for ppc, as root | 1502 | else { |
2639 | 1337 | sys_traverse_data() if ($debugger{'sys'} && ($debugger{'sys-force'} || !$b_root || !$b_ppc )) ; | 1503 | main::error_handler('required-module', 'Net', 'Net::FTP'); |
2640 | 1338 | } | 1504 | } |
2641 | 1339 | else { | 1505 | } |
2642 | 1340 | print "Skipping /sys data collection. /sys not present, or empty.\n"; | 1506 | create_debug_directory(); |
2643 | 1341 | } | 1507 | print "Note: for dmidecode, smartctl, lvm data you must be root.\n" if !$b_root; |
2644 | 1342 | print $line3; | 1508 | print $line3; |
2645 | 1343 | # note: proc has some files that are apparently kernel processes, I've tried | 1509 | if (!$b_debug){ |
2646 | 1344 | # filtering them out but more keep appearing, so only run proc debugger if not root | 1510 | audio_data(); |
2647 | 1345 | if ( !$debugger{'no-proc'} && (!$b_root || $debugger{'proc'} ) && -d '/proc' && main::count_dir_files('/proc') ){ | 1511 | bluetooth_data(); |
2648 | 1346 | build_tree('proc'); | 1512 | disk_data(); |
2649 | 1347 | proc_traverse_data(); | 1513 | display_data(); |
2650 | 1348 | } | 1514 | network_data(); |
2651 | 1349 | else { | 1515 | perl_modules(); |
2652 | 1350 | print "Skipping /proc data collection.\n"; | 1516 | system_data(); |
2653 | 1351 | } | 1517 | } |
2654 | 1352 | print $line3; | 1518 | system_files(); |
2655 | 1353 | } | 1519 | print $line3; |
2656 | 1354 | run_self(); | 1520 | if (!$b_debug){ |
2657 | 1355 | print $line3; | 1521 | # note: android has unreadable /sys, but -x and -r tests pass |
2658 | 1356 | compress_dir(); | 1522 | # main::globber('/sys/*') && |
2659 | 1523 | if ($debugger{'sys'} && main::count_dir_files('/sys')){ | ||
2660 | 1524 | build_tree('sys'); | ||
2661 | 1525 | # kernel crash, not sure what creates it, for ppc, as root | ||
2662 | 1526 | sys_traverse_data() if ($debugger{'sys'} && ($debugger{'sys-force'} || !$b_root || !$b_ppc)) ; | ||
2663 | 1527 | } | ||
2664 | 1528 | else { | ||
2665 | 1529 | print "Skipping /sys data collection.\n"; | ||
2666 | 1530 | } | ||
2667 | 1531 | print $line3; | ||
2668 | 1532 | # note: proc has some files that are apparently kernel processes, I've tried | ||
2669 | 1533 | # filtering them out but more keep appearing, so only run proc debugger if not root | ||
2670 | 1534 | if (!$debugger{'no-proc'} && (!$b_root || $debugger{'proc'}) && -d '/proc' && main::count_dir_files('/proc')){ | ||
2671 | 1535 | build_tree('proc'); | ||
2672 | 1536 | proc_traverse_data(); | ||
2673 | 1537 | } | ||
2674 | 1538 | else { | ||
2675 | 1539 | print "Skipping /proc data collection.\n"; | ||
2676 | 1540 | } | ||
2677 | 1541 | print $line3; | ||
2678 | 1542 | } | ||
2679 | 1543 | run_self(); | ||
2680 | 1544 | print $line3; | ||
2681 | 1545 | compress_dir(); | ||
2682 | 1357 | } | 1546 | } |
2683 | 1358 | 1547 | ||
2684 | 1359 | sub create_debug_directory { | 1548 | sub create_debug_directory { |
2721 | 1360 | my $host = main::get_hostname(); | 1549 | my $host = main::get_hostname(); |
2722 | 1361 | $host =~ s/ /-/g; | 1550 | $host =~ s/ /-/g; |
2723 | 1362 | $host = 'no-host' if !$host || $host eq 'N/A'; | 1551 | $host = 'no-host' if !$host || $host eq 'N/A'; |
2724 | 1363 | my ($alt_string,$bsd_string,$root_string) = ('','',''); | 1552 | my ($alt_string,$bsd_string,$root_string) = ('','',''); |
2725 | 1364 | # note: Time::Piece was introduced in perl 5.9.5 | 1553 | # note: Time::Piece was introduced in perl 5.9.5 |
2726 | 1365 | my ($sec,$min,$hour,$mday,$mon,$year) = localtime; | 1554 | my ($sec,$min,$hour,$mday,$mon,$year) = localtime; |
2727 | 1366 | $year = $year+1900; | 1555 | $year = $year+1900; |
2728 | 1367 | $mon += 1; | 1556 | $mon += 1; |
2729 | 1368 | if (length($sec) == 1) {$sec = "0$sec";} | 1557 | if (length($sec) == 1){$sec = "0$sec";} |
2730 | 1369 | if (length($min) == 1) {$min = "0$min";} | 1558 | if (length($min) == 1){$min = "0$min";} |
2731 | 1370 | if (length($hour) == 1) {$hour = "0$hour";} | 1559 | if (length($hour) == 1){$hour = "0$hour";} |
2732 | 1371 | if (length($mon) == 1) {$mon = "0$mon";} | 1560 | if (length($mon) == 1){$mon = "0$mon";} |
2733 | 1372 | if (length($mday) == 1) {$mday = "0$mday";} | 1561 | if (length($mday) == 1){$mday = "0$mday";} |
2734 | 1373 | 1562 | my $today = "$year-$mon-${mday}_$hour$min$sec"; | |
2735 | 1374 | my $today = "$year-$mon-${mday}_$hour$min$sec"; | 1563 | # my $date = strftime "-%Y-%m-%d_", localtime; |
2736 | 1375 | # my $date = strftime "-%Y-%m-%d_", localtime; | 1564 | if ($b_root){ |
2737 | 1376 | if ($b_root){ | 1565 | $root_string = '-root'; |
2738 | 1377 | $root_string = '-root'; | 1566 | } |
2739 | 1378 | } | 1567 | $bsd_string = "-BSD-$bsd_type" if $bsd_type; |
2740 | 1379 | $bsd_string = "-BSD-$bsd_type" if $bsd_type; | 1568 | my $id = ($debugger{'id'}) ? '-' . $debugger{'id'}: ''; |
2741 | 1380 | if ($b_arm ){$alt_string = '-ARM'} | 1569 | if ($b_arm){$alt_string = '-ARM'} |
2742 | 1381 | elsif ($b_mips) {$alt_string = '-MIPS'} | 1570 | elsif ($b_mips){$alt_string = '-MIPS'} |
2743 | 1382 | elsif ($b_ppc) {$alt_string = '-PPC'} | 1571 | elsif ($b_ppc){$alt_string = '-PPC'} |
2744 | 1383 | elsif ($b_sparc) {$alt_string = '-SPARC'} | 1572 | elsif ($b_sparc){$alt_string = '-SPARC'} |
2745 | 1384 | $debug_dir = "$self_name$alt_string$bsd_string-$host-$today$root_string-$self_version"; | 1573 | $debug_dir = "$self_name$alt_string$bsd_string-$host$id-$today$root_string-$self_version-$self_patch"; |
2746 | 1385 | $debug_gz = "$debug_dir.tar.gz"; | 1574 | $debug_gz = "$debug_dir.tar.gz"; |
2747 | 1386 | $data_dir = "$user_data_dir/$debug_dir"; | 1575 | $data_dir = "$user_data_dir/$debug_dir"; |
2748 | 1387 | if ( -d $data_dir ){ | 1576 | if (-d $data_dir){ |
2749 | 1388 | unlink $data_dir or main::error_handler('remove', "$data_dir", "$!"); | 1577 | unlink $data_dir or main::error_handler('remove', "$data_dir", "$!"); |
2750 | 1389 | } | 1578 | } |
2751 | 1390 | mkdir $data_dir or main::error_handler('mkdir', "$data_dir", "$!"); | 1579 | mkdir $data_dir or main::error_handler('mkdir', "$data_dir", "$!"); |
2752 | 1391 | if ( -e "$user_data_dir/$debug_gz" ){ | 1580 | if (-e "$user_data_dir/$debug_gz"){ |
2753 | 1392 | #rmdir "$user_data_dir$debug_gz" or main::error_handler('remove', "$user_data_dir/$debug_gz", "$!"); | 1581 | #rmdir "$user_data_dir$debug_gz" or main::error_handler('remove', "$user_data_dir/$debug_gz", "$!"); |
2754 | 1393 | print "Failed removing leftover directory:\n$user_data_dir$debug_gz error: $?" if system('rm','-rf',"$user_data_dir$debug_gz"); | 1582 | print "Failed removing leftover directory:\n$user_data_dir$debug_gz error: $?" if system('rm','-rf',"$user_data_dir$debug_gz"); |
2755 | 1394 | } | 1583 | } |
2756 | 1395 | print "Data going into:\n$data_dir\n"; | 1584 | print "Debugger data going into:\n$data_dir\n"; |
2757 | 1396 | } | 1585 | } |
2758 | 1397 | sub compress_dir { | 1586 | sub compress_dir { |
2771 | 1398 | print "Creating tar.gz compressed file of this material...\n"; | 1587 | print "Creating tar.gz compressed file of this material...\n"; |
2772 | 1399 | print "File: $debug_gz\n"; | 1588 | print "File: $debug_gz\n"; |
2773 | 1400 | system("cd $user_data_dir; tar -czf $debug_gz $debug_dir"); | 1589 | system("cd $user_data_dir; tar -czf $debug_gz $debug_dir"); |
2774 | 1401 | print "Removing $data_dir...\n"; | 1590 | print "Removing $data_dir...\n"; |
2775 | 1402 | #rmdir $data_dir or print "failed removing: $data_dir error: $!\n"; | 1591 | #rmdir $data_dir or print "failed removing: $data_dir error: $!\n"; |
2776 | 1403 | return 1 if !$b_delete_dir; | 1592 | return 1 if !$b_delete_dir; |
2777 | 1404 | if (system('rm','-rf',$data_dir) ){ | 1593 | if (system('rm','-rf',$data_dir)){ |
2778 | 1405 | print "Failed removing: $data_dir\nError: $?\n"; | 1594 | print "Failed removing: $data_dir\nError: $?\n"; |
2779 | 1406 | } | 1595 | } |
2780 | 1407 | else { | 1596 | else { |
2781 | 1408 | print "Directory removed.\n"; | 1597 | print "Directory removed.\n"; |
2782 | 1409 | } | 1598 | } |
2783 | 1410 | } | 1599 | } |
2784 | 1411 | # NOTE: incomplete, don't know how to ever find out | 1600 | # NOTE: incomplete, don't know how to ever find out |
2785 | 1412 | # what sound server is actually running, and is in control | 1601 | # what sound server is actually running, and is in control |
2786 | 1413 | sub audio_data { | 1602 | sub audio_data { |
2811 | 1414 | my (%data,@files,@files2); | 1603 | my (%data,@files,@files2); |
2812 | 1415 | print "Collecting audio data...\n"; | 1604 | print "Collecting audio data...\n"; |
2813 | 1416 | my @cmds = ( | 1605 | my @cmds = ( |
2814 | 1417 | ['aplay', '-l'], # alsa | 1606 | ['aplay', '-l'], # alsa |
2815 | 1418 | ['pactl', 'list'], # pulseaudio | 1607 | ['pactl', 'list'], # pulseaudio |
2816 | 1419 | ); | 1608 | ); |
2817 | 1420 | run_commands(\@cmds,'audio'); | 1609 | run_commands(\@cmds,'audio'); |
2818 | 1421 | @files = main::globber('/proc/asound/card*/codec*'); | 1610 | @files = main::globber('/proc/asound/card*/codec*'); |
2819 | 1422 | if (@files){ | 1611 | if (@files){ |
2820 | 1423 | my $asound = qx(head -n 1 /proc/asound/card*/codec* 2>&1); | 1612 | my $asound = qx(head -n 1 /proc/asound/card*/codec* 2>&1); |
2821 | 1424 | $data{'proc-asound-codecs'} = $asound; | 1613 | $data{'proc-asound-codecs'} = $asound; |
2822 | 1425 | } | 1614 | } |
2823 | 1426 | else { | 1615 | else { |
2824 | 1427 | $data{'proc-asound-codecs'} = undef; | 1616 | $data{'proc-asound-codecs'} = undef; |
2825 | 1428 | } | 1617 | } |
2826 | 1429 | 1618 | write_data(\%data,'audio'); | |
2827 | 1430 | write_data(\%data,'audio'); | 1619 | @files = ( |
2828 | 1431 | @files = ( | 1620 | '/proc/asound/cards', |
2829 | 1432 | '/proc/asound/cards', | 1621 | '/proc/asound/version', |
2830 | 1433 | '/proc/asound/version', | 1622 | ); |
2831 | 1434 | ); | 1623 | @files2 = main::globber('/proc/asound/*/usbid'); |
2832 | 1435 | @files2 = main::globber('/proc/asound/*/usbid'); | 1624 | push(@files,@files2) if @files2; |
2833 | 1436 | @files = (@files,@files2) if @files2; | 1625 | copy_files(\@files,'audio'); |
2834 | 1437 | copy_files(\@files,'audio'); | 1626 | } |
2835 | 1627 | sub bluetooth_data { | ||
2836 | 1628 | print "Collecting bluetooth data...\n"; | ||
2837 | 1629 | # no warnings 'uninitialized'; | ||
2838 | 1630 | my @cmds = ( | ||
2839 | 1631 | ['hciconfig','-a'], | ||
2840 | 1632 | #['hcidump',''], # hangs sometimes | ||
2841 | 1633 | ['hcitool','dev'], | ||
2842 | 1634 | ['rfkill','--output-all'], | ||
2843 | 1635 | ); | ||
2844 | 1636 | # these hang if bluetoothd not enabled | ||
2845 | 1637 | if (@ps_cmd && (grep {m|/bluetoothd|} @ps_cmd)){ | ||
2846 | 1638 | push(@cmds, | ||
2847 | 1639 | ['bt-adapter','--list'], | ||
2848 | 1640 | ['bt-adapter','--info'], | ||
2849 | 1641 | ['bluetoothctl','-- list'], | ||
2850 | 1642 | ['bluetoothctl','-- show'] | ||
2851 | 1643 | ); | ||
2852 | 1644 | } | ||
2853 | 1645 | run_commands(\@cmds,'bluetooth'); | ||
2854 | 1438 | } | 1646 | } |
2855 | 1647 | |||
2856 | 1439 | ## NOTE: >/dev/null 2>&1 is sh, and &>/dev/null is bash, fix this | 1648 | ## NOTE: >/dev/null 2>&1 is sh, and &>/dev/null is bash, fix this |
2857 | 1440 | # ls -w 1 /sysrs > tester 2>&1 | 1649 | # ls -w 1 /sysrs > tester 2>&1 |
2858 | 1441 | sub disk_data { | 1650 | sub disk_data { |
2947 | 1442 | my (%data,@files,@files2); | 1651 | my (%data,@files,@files2); |
2948 | 1443 | print "Collecting dev, label, disk, uuid data, df...\n"; | 1652 | print "Collecting dev, label, disk, uuid data, df...\n"; |
2949 | 1444 | @files = ( | 1653 | @files = ( |
2950 | 1445 | '/etc/fstab', | 1654 | '/etc/fstab', |
2951 | 1446 | '/etc/mtab', | 1655 | '/etc/mtab', |
2952 | 1447 | '/proc/mdstat', | 1656 | '/proc/devices', |
2953 | 1448 | '/proc/mounts', | 1657 | '/proc/mdstat', |
2954 | 1449 | '/proc/partitions', | 1658 | '/proc/mounts', |
2955 | 1450 | '/proc/scsi/scsi', | 1659 | '/proc/partitions', |
2956 | 1451 | '/proc/sys/dev/cdrom/info', | 1660 | '/proc/scsi/scsi', |
2957 | 1452 | ); | 1661 | '/proc/sys/dev/cdrom/info', |
2958 | 1453 | # very old systems | 1662 | ); |
2959 | 1454 | if (-d '/proc/ide/'){ | 1663 | # very old systems |
2960 | 1455 | my @ides = main::globber('/proc/ide/*/*'); | 1664 | if (-d '/proc/ide/'){ |
2961 | 1456 | @files = (@files, @ides) if @ides; | 1665 | my @ides = main::globber('/proc/ide/*/*'); |
2962 | 1457 | } | 1666 | push(@files, @ides) if @ides; |
2963 | 1458 | else { | 1667 | } |
2964 | 1459 | push (@files, '/proc-ide-directory'); | 1668 | else { |
2965 | 1460 | } | 1669 | push(@files, '/proc-ide-directory'); |
2966 | 1461 | copy_files(\@files, 'disk'); | 1670 | } |
2967 | 1462 | my @cmds = ( | 1671 | copy_files(\@files, 'disk'); |
2968 | 1463 | ['blockdev', '--report'], | 1672 | my @cmds = ( |
2969 | 1464 | ['btrfs', 'filesystem show'], | 1673 | ['blockdev', '--report'], |
2970 | 1465 | ['btrfs', 'filesystem show --mounted'], | 1674 | ['btrfs', 'fi show'], |
2971 | 1466 | # ['btrfs', 'filesystem show --all-devices'], | 1675 | ['btrfs', 'filesystem show'], |
2972 | 1467 | ['df', '-h -T'], | 1676 | ['btrfs', 'filesystem show --mounted'], |
2973 | 1468 | ['df', '-h'], | 1677 | # ['btrfs', 'filesystem show --all-devices'], |
2974 | 1469 | ['df', '-k'], | 1678 | ['df', '-h -T'], |
2975 | 1470 | ['df', '-k -T'], | 1679 | ['df', '-h'], |
2976 | 1471 | ['df', '-k -T -P'], | 1680 | ['df', '-k'], |
2977 | 1472 | ['df', '-k -T -P -a'], | 1681 | ['df', '-k -T'], |
2978 | 1473 | ['df', '-P'], | 1682 | ['df', '-k -T -P'], |
2979 | 1474 | ['findmnt', ''], | 1683 | ['df', '-k -T -P -a'], |
2980 | 1475 | ['findmnt', '--df --no-truncate'], | 1684 | ['df', '-P'], |
2981 | 1476 | ['findmnt', '--list --no-truncate'], | 1685 | ['dmsetup', 'ls --tree'], |
2982 | 1477 | ['lsblk', '-fs'], | 1686 | ['findmnt', ''], |
2983 | 1478 | ['lsblk', '-fsr'], | 1687 | ['findmnt', '--df --no-truncate'], |
2984 | 1479 | ['lsblk', '-fsP'], | 1688 | ['findmnt', '--list --no-truncate'], |
2985 | 1480 | ['lsblk', '-a'], | 1689 | ['gpart', 'list'], |
2986 | 1481 | ['lsblk', '-aP'], | 1690 | ['gpart', 'show'], |
2987 | 1482 | ['lsblk', '-ar'], | 1691 | ['gpart', 'status'], |
2988 | 1483 | ['lsblk', '-p'], | 1692 | ['ls', '-l /dev'], |
2989 | 1484 | ['lsblk', '-pr'], | 1693 | # block is for mmcblk / arm devices |
2990 | 1485 | ['lsblk', '-pP'], | 1694 | ['ls', '-l /dev/block'], |
2991 | 1486 | ['lsblk', '-r'], | 1695 | ['ls', '-l /dev/block/bootdevice'], |
2992 | 1487 | ['lsblk', '-r --output NAME,PKNAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,MOUNTPOINT,PHY-SEC,LOG-SEC'], | 1696 | ['ls', '-l /dev/block/bootdevice/by-name'], |
2993 | 1488 | ['lsblk', '-rb --output NAME,PKNAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,MOUNTPOINT,PHY-SEC,LOG-SEC'], | 1697 | ['ls', '-l /dev/disk'], |
2994 | 1489 | ['lsblk', '-Pb --output NAME,PKNAME,TYPE,RM,FSTYPE,SIZE'], | 1698 | ['ls', '-l /dev/disk/by-id'], |
2995 | 1490 | ['lsblk', '-Pb --output NAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,SERIAL,MOUNTPOINT,PHY-SEC,LOG-SEC'], | 1699 | ['ls', '-l /dev/disk/by-label'], |
2996 | 1491 | ['gpart', 'list'], | 1700 | ['ls', '-l /dev/disk/by-partlabel'], |
2997 | 1492 | ['gpart', 'show'], | 1701 | ['ls', '-l /dev/disk/by-partuuid'], |
2998 | 1493 | ['gpart', 'status'], | 1702 | ['ls', '-l /dev/disk/by-path'], |
2999 | 1494 | ['ls', '-l /dev'], | 1703 | ['ls', '-l /dev/disk/by-uuid'], |
3000 | 1495 | ['ls', '-l /dev/disk'], | 1704 | # http://comments.gmane.org/gmane.linux.file-systems.zfs.user/2032 |
3001 | 1496 | ['ls', '-l /dev/disk/by-id'], | 1705 | ['ls', '-l /dev/disk/by-wwn'], |
3002 | 1497 | ['ls', '-l /dev/disk/by-label'], | 1706 | ['ls', '-l /dev/mapper'], |
3003 | 1498 | ['ls', '-l /dev/disk/by-uuid'], | 1707 | ['lsblk', '-fs'], |
3004 | 1499 | # http://comments.gmane.org/gmane.linux.file-systems.zfs.user/2032 | 1708 | ['lsblk', '-fsr'], |
3005 | 1500 | ['ls', '-l /dev/disk/by-wwn'], | 1709 | ['lsblk', '-fsP'], |
3006 | 1501 | ['ls', '-l /dev/disk/by-path'], | 1710 | ['lsblk', '-a'], |
3007 | 1502 | ['ls', '-l /dev/mapper'], | 1711 | ['lsblk', '-aP'], |
3008 | 1503 | # LSI raid https://hwraid.le-vert.net/wiki/LSIMegaRAIDSAS | 1712 | ['lsblk', '-ar'], |
3009 | 1504 | ['megacli', '-AdpAllInfo -aAll'], | 1713 | ['lsblk', '-p'], |
3010 | 1505 | ['megacli', '-LDInfo -L0 -a0'], | 1714 | ['lsblk', '-pr'], |
3011 | 1506 | ['megacli', '-PDList -a0'], | 1715 | ['lsblk', '-pP'], |
3012 | 1507 | ['megaclisas-status', ''], | 1716 | ['lsblk', '-r'], |
3013 | 1508 | ['megaraidsas-status', ''], | 1717 | ['lsblk', '-r --output NAME,PKNAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,MOUNTPOINT,PHY-SEC,LOG-SEC,PARTFLAGS'], |
3014 | 1509 | ['megasasctl', ''], | 1718 | ['lsblk', '-rb --output NAME,PKNAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,MOUNTPOINT,PHY-SEC,LOG-SEC,PARTFLAGS'], |
3015 | 1510 | ['mount', ''], | 1719 | ['lsblk', '-rb --output NAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,SERIAL,MOUNTPOINT,PHY-SEC,LOG-SEC,PARTFLAGS,MAJ:MIN,PKNAME'], |
3016 | 1511 | ['nvme', 'present'], | 1720 | ['lsblk', '-Pb --output NAME,PKNAME,TYPE,RM,FSTYPE,SIZE'], |
3017 | 1512 | ['readlink', '/dev/root'], | 1721 | ['lsblk', '-Pb --output NAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,SERIAL,MOUNTPOINT,PHY-SEC,LOG-SEC,PARTFLAGS'], |
3018 | 1513 | ['swapon', '-s'], | 1722 | # this should always be the live command used internally: |
3019 | 1514 | # 3ware-raid | 1723 | ['lsblk', '-bP --output NAME,TYPE,RM,FSTYPE,SIZE,LABEL,UUID,SERIAL,MOUNTPOINT,PHY-SEC,LOG-SEC,PARTFLAGS,MAJ:MIN,PKNAME'], |
3020 | 1515 | ['tw-cli', 'info'], | 1724 | ['lvdisplay', '-c'], |
3021 | 1516 | ['zfs', 'list'], | 1725 | ['lvdisplay', '-cv'], |
3022 | 1517 | ['zpool', 'list'], | 1726 | ['lvdisplay', '-cv --segments'], |
3023 | 1518 | ['zpool', 'list -v'], | 1727 | ['lvdisplay', '-m --segments'], |
3024 | 1519 | ); | 1728 | ['lvdisplay', '-ma --segments'], |
3025 | 1520 | run_commands(\@cmds,'disk'); | 1729 | ['lvs', '--separator :'], |
3026 | 1521 | @cmds = ( | 1730 | ['lvs', '--separator : --segments'], |
3027 | 1522 | ['atacontrol', 'list'], | 1731 | ['lvs', '-o +devices --separator : --segments'], |
3028 | 1523 | ['camcontrol', 'devlist'], | 1732 | ['lvs', '-o +devices -v --separator : --segments'], |
3029 | 1524 | ['glabel', 'status'], | 1733 | ['lvs', '-o +devices -av --separator : --segments'], |
3030 | 1525 | ['swapctl', '-l -k'], | 1734 | ['lvs', '-o +devices -aPv --separator : --segments'], |
3031 | 1526 | ['swapctl', '-l -k'], | 1735 | # LSI raid https://hwraid.le-vert.net/wiki/LSIMegaRAIDSAS |
3032 | 1527 | ['vmstat', '-H'], | 1736 | ['megacli', '-AdpAllInfo -aAll'], |
3033 | 1528 | ); | 1737 | ['megacli', '-LDInfo -L0 -a0'], |
3034 | 1529 | run_commands(\@cmds,'disk-bsd'); | 1738 | ['megacli', '-PDList -a0'], |
3035 | 1739 | ['megaclisas-status', ''], | ||
3036 | 1740 | ['megaraidsas-status', ''], | ||
3037 | 1741 | ['megasasctl', ''], | ||
3038 | 1742 | ['mount', ''], | ||
3039 | 1743 | ['nvme', 'present'], | ||
3040 | 1744 | ['pvdisplay', '-c'], | ||
3041 | 1745 | ['pvdisplay', '-cv'], | ||
3042 | 1746 | ['pvdisplay', '-m'], | ||
3043 | 1747 | ['pvdisplay', '-ma'], | ||
3044 | 1748 | ['pvs', '--separator :'], | ||
3045 | 1749 | ['pvs', '--separator : --segments'], | ||
3046 | 1750 | ['pvs', '-a --separator : --segments'], | ||
3047 | 1751 | ['pvs', '-av --separator : --segments'], | ||
3048 | 1752 | ['pvs', '-aPv --separator : --segments -o +pv_major,pv_minor'], | ||
3049 | 1753 | ['pvs', '-v --separator : --segments'], | ||
3050 | 1754 | ['pvs', '-Pv --separator : --segments'], | ||
3051 | 1755 | ['pvs', '--segments -o pv_name,pv_size,seg_size,vg_name,lv_name,lv_size,seg_pe_ranges'], | ||
3052 | 1756 | ['readlink', '/dev/root'], | ||
3053 | 1757 | ['swapon', '-s'], | ||
3054 | 1758 | # 3ware-raid | ||
3055 | 1759 | ['tw-cli', 'info'], | ||
3056 | 1760 | ['vgdisplay', ''], | ||
3057 | 1761 | ['vgdisplay', '-v'], | ||
3058 | 1762 | ['vgdisplay', '-c'], | ||
3059 | 1763 | ['vgdisplay', '-vc'], | ||
3060 | 1764 | ['vgs', '--separator :'], | ||
3061 | 1765 | ['vgs', '-av --separator :'], | ||
3062 | 1766 | ['vgs', '-aPv --separator :'], | ||
3063 | 1767 | ['vgs', '-v --separator :'], | ||
3064 | 1768 | ['vgs', '-o +pv_name --separator :'], | ||
3065 | 1769 | ['zfs', 'list'], | ||
3066 | 1770 | ['zpool', 'list'], | ||
3067 | 1771 | ['zpool', 'list -v'], | ||
3068 | 1772 | ); | ||
3069 | 1773 | run_commands(\@cmds,'disk'); | ||
3070 | 1774 | @cmds = ( | ||
3071 | 1775 | ['atacontrol', 'list'], | ||
3072 | 1776 | ['camcontrol', 'devlist'], | ||
3073 | 1777 | ['camcontrol', 'devlist -v'], | ||
3074 | 1778 | ['geom', 'part list'], | ||
3075 | 1779 | ['glabel', 'status'], | ||
3076 | 1780 | ['gpart', 'list'], # gpart in linux/bsd but do it here again | ||
3077 | 1781 | ['gpart', 'show'], | ||
3078 | 1782 | ['gpart', 'status'], | ||
3079 | 1783 | ['swapctl', '-l -k'], | ||
3080 | 1784 | ['swapctl', '-l -k'], | ||
3081 | 1785 | ['vmstat', ''], | ||
3082 | 1786 | ['vmstat', '-H'], | ||
3083 | 1787 | ); | ||
3084 | 1788 | run_commands(\@cmds,'disk-bsd'); | ||
3085 | 1530 | } | 1789 | } |
3086 | 1531 | sub display_data { | 1790 | sub display_data { |
3166 | 1532 | my (%data,@files,@files2); | 1791 | my (%data,@files,@files2); |
3167 | 1533 | my $working = ''; | 1792 | my $working = ''; |
3168 | 1534 | if ( ! $b_display ){ | 1793 | if (!$b_display){ |
3169 | 1535 | print "Warning: only some of the data collection can occur if you are not in X\n"; | 1794 | print "Warning: only some of the data collection can occur if you are not in X\n"; |
3170 | 1536 | main::toucher("$data_dir/display-data-warning-user-not-in-x"); | 1795 | main::toucher("$data_dir/display-data-warning-user-not-in-x"); |
3171 | 1537 | } | 1796 | } |
3172 | 1538 | if ( $b_root ){ | 1797 | if ($b_root){ |
3173 | 1539 | print "Warning: only some of the data collection can occur if you are running as Root user\n"; | 1798 | print "Warning: only some of the data collection can occur if you are running as Root user\n"; |
3174 | 1540 | main::toucher("$data_dir/display-data-warning-root-user"); | 1799 | main::toucher("$data_dir/display-data-warning-root-user"); |
3175 | 1541 | } | 1800 | } |
3176 | 1542 | print "Collecting Xorg log and xorg.conf files...\n"; | 1801 | print "Collecting Xorg log and xorg.conf files...\n"; |
3177 | 1543 | if ( -d "/etc/X11/xorg.conf.d/" ){ | 1802 | if (-d "/etc/X11/xorg.conf.d/"){ |
3178 | 1544 | @files = main::globber("/etc/X11/xorg.conf.d/*"); | 1803 | @files = main::globber("/etc/X11/xorg.conf.d/*"); |
3179 | 1545 | } | 1804 | } |
3180 | 1546 | else { | 1805 | else { |
3181 | 1547 | @files = ('/xorg-conf-d'); | 1806 | @files = ('/xorg-conf-d'); |
3182 | 1548 | } | 1807 | } |
3183 | 1549 | push (@files, $files{'xorg-log'}); | 1808 | # keep this updated to handle all possible locations we know about for Xorg.0.log |
3184 | 1550 | push (@files, '/etc/X11/xorg.conf'); | 1809 | # not using $system_files{'xorg-log'} for now though it would be best to know what file is used |
3185 | 1551 | copy_files(\@files,'display-xorg'); | 1810 | main::set_xorg_log(); |
3186 | 1552 | print "Collecting X, xprop, glxinfo, xrandr, xdpyinfo data, wayland, weston...\n"; | 1811 | push(@files, '/var/log/Xorg.0.log'); |
3187 | 1553 | %data = ( | 1812 | push(@files, '/var/lib/gdm/.local/share/xorg/Xorg.0.log'); |
3188 | 1554 | 'desktop-session' => $ENV{'DESKTOP_SESSION'}, | 1813 | push(@files, $ENV{'HOME'} . '/.local/share/xorg/Xorg.0.log'); |
3189 | 1555 | 'gdmsession' => $ENV{'GDMSESSION'}, | 1814 | push(@files, $system_files{'xorg-log'}) if $system_files{'xorg-log'}; |
3190 | 1556 | 'gnome-desktop-session-id' => $ENV{'GNOME_DESKTOP_SESSION_ID'}, | 1815 | push(@files, '/etc/X11/xorg.conf'); |
3191 | 1557 | 'kde-full-session' => $ENV{'KDE_FULL_SESSION'}, | 1816 | copy_files(\@files,'display-xorg'); |
3192 | 1558 | 'kde-session-version' => $ENV{'KDE_SESSION_VERSION'}, | 1817 | print "Collecting X, xprop, glxinfo, xrandr, xdpyinfo data, wayland, weston...\n"; |
3193 | 1559 | 'vdpau-driver' => $ENV{'VDPAU_DRIVER'}, | 1818 | %data = ( |
3194 | 1560 | 'xdg-current-desktop' => $ENV{'XDG_CURRENT_DESKTOP'}, | 1819 | 'desktop-session' => $ENV{'DESKTOP_SESSION'}, |
3195 | 1561 | 'xdg-session-desktop' => $ENV{'XDG_SESSION_DESKTOP'}, | 1820 | 'gdmsession' => $ENV{'GDMSESSION'}, |
3196 | 1562 | 'xdg-vtnr' => $ENV{'XDG_VTNR'}, | 1821 | 'gnome-desktop-session-id' => $ENV{'GNOME_DESKTOP_SESSION_ID'}, |
3197 | 1563 | # wayland data collectors: | 1822 | 'kde-full-session' => $ENV{'KDE_FULL_SESSION'}, |
3198 | 1564 | 'xdg-session-type' => $ENV{'XDG_SESSION_TYPE'}, | 1823 | 'kde-session-version' => $ENV{'KDE_SESSION_VERSION'}, |
3199 | 1565 | 'wayland-display' => $ENV{'WAYLAND_DISPLAY'}, | 1824 | 'vdpau-driver' => $ENV{'VDPAU_DRIVER'}, |
3200 | 1566 | 'gdk-backend' => $ENV{'GDK_BACKEND'}, | 1825 | 'xdg-current-desktop' => $ENV{'XDG_CURRENT_DESKTOP'}, |
3201 | 1567 | 'qt-qpa-platform' => $ENV{'QT_QPA_PLATFORM'}, | 1826 | 'xdg-session-desktop' => $ENV{'XDG_SESSION_DESKTOP'}, |
3202 | 1568 | 'clutter-backend' => $ENV{'CLUTTER_BACKEND'}, | 1827 | 'xdg-vtnr' => $ENV{'XDG_VTNR'}, |
3203 | 1569 | 'sdl-videodriver' => $ENV{'SDL_VIDEODRIVER'}, | 1828 | # wayland data collectors: |
3204 | 1570 | # program display values | 1829 | 'xdg-session-type' => $ENV{'XDG_SESSION_TYPE'}, |
3205 | 1571 | 'size-indent' => $size{'indent'}, | 1830 | 'wayland-display' => $ENV{'WAYLAND_DISPLAY'}, |
3206 | 1572 | 'size-indent-min' => $size{'indent-min'}, | 1831 | 'gdk-backend' => $ENV{'GDK_BACKEND'}, |
3207 | 1573 | 'size-cols-max' => $size{'max'}, | 1832 | 'qt-qpa-platform' => $ENV{'QT_QPA_PLATFORM'}, |
3208 | 1574 | ); | 1833 | 'clutter-backend' => $ENV{'CLUTTER_BACKEND'}, |
3209 | 1575 | write_data(\%data,'display'); | 1834 | 'sdl-videodriver' => $ENV{'SDL_VIDEODRIVER'}, |
3210 | 1576 | my @cmds = ( | 1835 | # program display values |
3211 | 1577 | # kde 5/plasma desktop 5, this is maybe an extra package and won't be used | 1836 | 'size-cols-max' => $size{'max'}, |
3212 | 1578 | ['about-distro',''], | 1837 | 'size-indent' => $size{'indent'}, |
3213 | 1579 | ['aticonfig','--adapter=all --od-gettemperature'], | 1838 | 'size-wrap-width' => $size{'wrap-max'}, |
3214 | 1580 | ['glxinfo',''], | 1839 | ); |
3215 | 1581 | ['glxinfo','-B'], | 1840 | write_data(\%data,'display'); |
3216 | 1582 | ['kded','--version'], | 1841 | my @cmds = ( |
3217 | 1583 | ['kded1','--version'], | 1842 | # kde 5/plasma desktop 5, this is maybe an extra package and won't be used |
3218 | 1584 | ['kded2','--version'], | 1843 | ['about-distro',''], |
3219 | 1585 | ['kded3','--version'], | 1844 | ['aticonfig','--adapter=all --od-gettemperature'], |
3220 | 1586 | ['kded4','--version'], | 1845 | ['glxinfo',''], |
3221 | 1587 | ['kded5','--version'], | 1846 | ['glxinfo','-B'], |
3222 | 1588 | ['kded6','--version'], | 1847 | ['kded','--version'], |
3223 | 1589 | ['kf4-config','--version'], | 1848 | ['kded1','--version'], |
3224 | 1590 | ['kf5-config','--version'], | 1849 | ['kded2','--version'], |
3225 | 1591 | ['kf6-config','--version'], | 1850 | ['kded3','--version'], |
3226 | 1592 | ['kwin_x11','--version'], | 1851 | ['kded4','--version'], |
3227 | 1593 | # ['locate','/Xorg'], # for Xorg.wrap problem | 1852 | ['kded5','--version'], |
3228 | 1594 | ['loginctl','--no-pager list-sessions'], | 1853 | ['kded6','--version'], |
3229 | 1595 | ['nvidia-settings','-q screens'], | 1854 | ['kded7','--version'], |
3230 | 1596 | ['nvidia-settings','-c :0.0 -q all'], | 1855 | ['kf-config','--version'], |
3231 | 1597 | ['nvidia-smi','-q'], | 1856 | ['kf4-config','--version'], |
3232 | 1598 | ['nvidia-smi','-q -x'], | 1857 | ['kf5-config','--version'], |
3233 | 1599 | ['plasmashell','--version'], | 1858 | ['kf6-config','--version'], |
3234 | 1600 | ['vainfo',''], | 1859 | ['kf7-config','--version'], |
3235 | 1601 | ['vdpauinfo',''], | 1860 | ['kwin_x11','--version'], |
3236 | 1602 | ['weston-info',''], | 1861 | # ['locate','/Xorg'], # for Xorg.wrap problem |
3237 | 1603 | ['wmctrl','-m'], | 1862 | ['loginctl','--no-pager list-sessions'], |
3238 | 1604 | ['weston','--version'], | 1863 | ['nvidia-settings','-q screens'], |
3239 | 1605 | ['xdpyinfo',''], | 1864 | ['nvidia-settings','-c :0.0 -q all'], |
3240 | 1606 | ['Xorg','-version'], | 1865 | ['nvidia-smi','-q'], |
3241 | 1607 | ['xprop','-root'], | 1866 | ['nvidia-smi','-q -x'], |
3242 | 1608 | ['xrandr',''], | 1867 | ['plasmashell','--version'], |
3243 | 1609 | ); | 1868 | ['vainfo',''], |
3244 | 1610 | run_commands(\@cmds,'display'); | 1869 | ['vdpauinfo',''], |
3245 | 1870 | ['vulkaninfo',''], | ||
3246 | 1871 | ['weston-info',''], | ||
3247 | 1872 | ['wmctrl','-m'], | ||
3248 | 1873 | ['weston','--version'], | ||
3249 | 1874 | ['xdpyinfo',''], | ||
3250 | 1875 | ['Xorg','-version'], | ||
3251 | 1876 | ['xprop','-root'], | ||
3252 | 1877 | ['xrandr',''], | ||
3253 | 1878 | ); | ||
3254 | 1879 | run_commands(\@cmds,'display'); | ||
3255 | 1611 | } | 1880 | } |
3256 | 1612 | sub network_data { | 1881 | sub network_data { |
3265 | 1613 | print "Collecting networking data...\n"; | 1882 | print "Collecting networking data...\n"; |
3266 | 1614 | # no warnings 'uninitialized'; | 1883 | # no warnings 'uninitialized'; |
3267 | 1615 | my @cmds = ( | 1884 | my @cmds = ( |
3268 | 1616 | ['ifconfig',''], | 1885 | ['ifconfig',''], |
3269 | 1617 | ['ip','addr'], | 1886 | ['ip','addr'], |
3270 | 1618 | ['ip','-s link'], | 1887 | ['ip','-s link'], |
3271 | 1619 | ); | 1888 | ); |
3272 | 1620 | run_commands(\@cmds,'network'); | 1889 | run_commands(\@cmds,'network'); |
3273 | 1621 | } | 1890 | } |
3274 | 1622 | sub perl_modules { | 1891 | sub perl_modules { |
3315 | 1623 | print "Collecting Perl module data (this can take a while)...\n"; | 1892 | print "Collecting Perl module data (this can take a while)...\n"; |
3316 | 1624 | my @modules = (); | 1893 | my @modules; |
3317 | 1625 | my ($dirname,$holder,$mods,$value) = ('','','',''); | 1894 | my ($dirname,$holder,$mods,$value) = ('','','',''); |
3318 | 1626 | my $filename = 'perl-modules.txt'; | 1895 | my $filename = 'perl-modules.txt'; |
3319 | 1627 | my @inc; | 1896 | my @inc; |
3320 | 1628 | foreach (sort @INC){ | 1897 | foreach (sort @INC){ |
3321 | 1629 | # some BSD installs have '.' n @INC path | 1898 | # some BSD installs have '.' n @INC path |
3322 | 1630 | if (-d $_ && $_ ne '.'){ | 1899 | if (-d $_ && $_ ne '.'){ |
3323 | 1631 | $_ =~ s/\/$//; # just in case, trim off trailing slash | 1900 | $_ =~ s/\/$//; # just in case, trim off trailing slash |
3324 | 1632 | $value .= "EXISTS: $_\n"; | 1901 | $value .= "EXISTS: $_\n"; |
3325 | 1633 | push @inc, $_; | 1902 | push(@inc, $_); |
3326 | 1634 | } | 1903 | } |
3327 | 1635 | else { | 1904 | else { |
3328 | 1636 | $value .= "ABSENT: $_\n"; | 1905 | $value .= "ABSENT: $_\n"; |
3329 | 1637 | } | 1906 | } |
3330 | 1638 | } | 1907 | } |
3331 | 1639 | main::writer("$data_dir/perl-inc-data.txt",$value); | 1908 | main::writer("$data_dir/perl-inc-data.txt",$value); |
3332 | 1640 | File::Find::find { wanted => sub { | 1909 | File::Find::find({ wanted => sub { |
3333 | 1641 | push @modules, File::Spec->canonpath($_) if /\.pm\z/ | 1910 | push(@modules, File::Spec->canonpath($_)) if /\.pm\z/ |
3334 | 1642 | }, no_chdir => 1 }, @inc; | 1911 | }, no_chdir => 1 }, @inc); |
3335 | 1643 | @modules = sort(@modules); | 1912 | @modules = sort @modules; |
3336 | 1644 | foreach (@modules){ | 1913 | foreach (@modules){ |
3337 | 1645 | my $dir = $_; | 1914 | my $dir = $_; |
3338 | 1646 | $dir =~ s/[^\/]+$//; | 1915 | $dir =~ s/[^\/]+$//; |
3339 | 1647 | if (!$holder || $holder ne $dir ){ | 1916 | if (!$holder || $holder ne $dir){ |
3340 | 1648 | $holder = $dir; | 1917 | $holder = $dir; |
3341 | 1649 | $value = "DIR: $dir\n"; | 1918 | $value = "DIR: $dir\n"; |
3342 | 1650 | $_ =~ s/^$dir//; | 1919 | $_ =~ s/^$dir//; |
3343 | 1651 | $value .= " $_\n"; | 1920 | $value .= " $_\n"; |
3344 | 1652 | } | 1921 | } |
3345 | 1653 | else { | 1922 | else { |
3346 | 1654 | $value = $_; | 1923 | $value = $_; |
3347 | 1655 | $value =~ s/^$dir//; | 1924 | $value =~ s/^$dir//; |
3348 | 1656 | $value = " $value\n"; | 1925 | $value = " $value\n"; |
3349 | 1657 | } | 1926 | } |
3350 | 1658 | $mods .= $value; | 1927 | $mods .= $value; |
3351 | 1659 | } | 1928 | } |
3352 | 1660 | open (my $fh, '>', "$data_dir/$filename"); | 1929 | open(my $fh, '>', "$data_dir/$filename"); |
3353 | 1661 | print $fh $mods; | 1930 | print $fh $mods; |
3354 | 1662 | close $fh; | 1931 | close $fh; |
3355 | 1663 | } | 1932 | } |
3356 | 1664 | sub system_data { | 1933 | sub system_data { |
3457 | 1665 | print "Collecting system data...\n"; | 1934 | print "Collecting system data...\n"; |
3458 | 1666 | my %data = ( | 1935 | # has to run here because if null, error, list constructor throws fatal error |
3459 | 1667 | 'cc' => $ENV{'CC'}, | 1936 | my $ksh = qx(ksh -c 'printf \%s "\$KSH_VERSION"' 2>/dev/null); |
3460 | 1668 | # @(#)MIRBSD KSH R56 2018/03/09: ksh and mksh | 1937 | my %data = ( |
3461 | 1669 | 'ksh-version' => system('echo -n $KSH_VERSION'), # shell, not env, variable | 1938 | 'cc' => $ENV{'CC'}, |
3462 | 1670 | 'manpath' => $ENV{'MANPATH'}, | 1939 | # @(#)MIRBSD KSH R56 2018/03/09: ksh and mksh |
3463 | 1671 | 'path' => $ENV{'PATH'}, | 1940 | 'ksh-version' => $ksh, # shell, not env, variable |
3464 | 1672 | 'xdg-config-home' => $ENV{'XDG_CONFIG_HOME'}, | 1941 | 'manpath' => $ENV{'MANPATH'}, |
3465 | 1673 | 'xdg-config-dirs' => $ENV{'XDG_CONFIG_DIRS'}, | 1942 | 'path' => $ENV{'PATH'}, |
3466 | 1674 | 'xdg-data-home' => $ENV{'XDG_DATA_HOME'}, | 1943 | 'xdg-config-home' => $ENV{'XDG_CONFIG_HOME'}, |
3467 | 1675 | 'xdg-data-dirs' => $ENV{'XDG_DATA_DIRS'}, | 1944 | 'xdg-config-dirs' => $ENV{'XDG_CONFIG_DIRS'}, |
3468 | 1676 | ); | 1945 | 'xdg-data-home' => $ENV{'XDG_DATA_HOME'}, |
3469 | 1677 | my @files = main::globber('/usr/bin/gcc*'); | 1946 | 'xdg-data-dirs' => $ENV{'XDG_DATA_DIRS'}, |
3470 | 1678 | if (@files){ | 1947 | ); |
3471 | 1679 | $data{'gcc-versions'} = join "\n",@files; | 1948 | my @files = main::globber('/usr/bin/gcc*'); |
3472 | 1680 | } | 1949 | if (@files){ |
3473 | 1681 | else { | 1950 | $data{'gcc-versions'} = join("\n", @files); |
3474 | 1682 | $data{'gcc-versions'} = undef; | 1951 | } |
3475 | 1683 | } | 1952 | else { |
3476 | 1684 | @files = main::globber('/sys/*'); | 1953 | $data{'gcc-versions'} = undef; |
3477 | 1685 | if (@files){ | 1954 | } |
3478 | 1686 | $data{'sys-tree-ls-1-basic'} = join "\n", @files; | 1955 | @files = main::globber('/sys/*'); |
3479 | 1687 | } | 1956 | if (@files){ |
3480 | 1688 | else { | 1957 | $data{'sys-tree-ls-1-basic'} = join("\n", @files); |
3481 | 1689 | $data{'sys-tree-ls-1-basic'} = undef; | 1958 | } |
3482 | 1690 | } | 1959 | else { |
3483 | 1691 | write_data(\%data,'system'); | 1960 | $data{'sys-tree-ls-1-basic'} = undef; |
3484 | 1692 | # bsd tools http://cb.vu/unixtoolbox.xhtml | 1961 | } |
3485 | 1693 | my @cmds = ( | 1962 | write_data(\%data,'system'); |
3486 | 1694 | # general | 1963 | # bsd tools http://cb.vu/unixtoolbox.xhtml |
3487 | 1695 | ['sysctl', '-b kern.geom.conftxt'], | 1964 | my @cmds = ( |
3488 | 1696 | ['sysctl', '-b kern.geom.confxml'], | 1965 | # general |
3489 | 1697 | ['usbdevs','-v'], | 1966 | ['sysctl', '-a'], |
3490 | 1698 | # freebsd | 1967 | ['sysctl', '-b kern.geom.conftxt'], |
3491 | 1699 | ['pciconf','-l -cv'], | 1968 | ['sysctl', '-b kern.geom.confxml'], |
3492 | 1700 | ['pciconf','-vl'], | 1969 | ['usbdevs','-v'], |
3493 | 1701 | ['pciconf','-l'], | 1970 | # freebsd |
3494 | 1702 | # openbsd | 1971 | ['ofwdump','-a'], # arm / soc |
3495 | 1703 | ['pcidump',''], | 1972 | ['ofwdump','-ar'], # arm / soc |
3496 | 1704 | ['pcidump','-v'], | 1973 | ['pciconf','-l -cv'], |
3497 | 1705 | # netbsd | 1974 | ['pciconf','-vl'], |
3498 | 1706 | ['kldstat',''], | 1975 | ['pciconf','-l'], |
3499 | 1707 | ['pcictl','list'], | 1976 | ['usbconfig','dump_device_desc'], |
3500 | 1708 | ['pcictl','list -ns'], | 1977 | ['usbconfig','list'], # needs root, sigh... why? |
3501 | 1709 | ); | 1978 | # openbsd |
3502 | 1710 | run_commands(\@cmds,'system-bsd'); | 1979 | ['ofctl',''], # arm / soc, need to see data sample of this |
3503 | 1711 | # diskinfo -v <disk> | 1980 | ['pcidump',''], |
3504 | 1712 | # fdisk <disk> | 1981 | ['pcidump','-v'], |
3505 | 1713 | @cmds = ( | 1982 | # netbsd |
3506 | 1714 | ['clang','--version'], | 1983 | ['kldstat',''], |
3507 | 1715 | ['dmidecode',''], | 1984 | ['pcictl','pci0 list'], |
3508 | 1716 | ['dmesg',''], | 1985 | ['pcictl','pci0 list -N'], |
3509 | 1717 | ['gcc','--version'], | 1986 | ['pcictl','pci0 list -n'], |
3510 | 1718 | ['hciconfig','-a'], | 1987 | ); |
3511 | 1719 | ['initctl','list'], | 1988 | run_commands(\@cmds,'system-bsd'); |
3512 | 1720 | ['ipmi-sensors',''], | 1989 | # diskinfo -v <disk> |
3513 | 1721 | ['ipmi-sensors','--output-sensor-thresholds'], | 1990 | # fdisk <disk> |
3514 | 1722 | ['ipmitool','sensor'], | 1991 | @cmds = ( |
3515 | 1723 | ['lscpu',''], | 1992 | ['clang','--version'], |
3516 | 1724 | ['lspci',''], | 1993 | # only for prospective ram feature data collection: requires i2c-tools and module eeprom loaded |
3517 | 1725 | ['lspci','-k'], | 1994 | ['decode-dimms',''], |
3518 | 1726 | ['lspci','-n'], | 1995 | ['dmidecode',''], |
3519 | 1727 | ['lspci','-nn'], | 1996 | ['dmesg',''], |
3520 | 1728 | ['lspci','-nnk'], | 1997 | ['gcc','--version'], |
3521 | 1729 | ['lspci','-nnkv'],# returns ports | 1998 | ['initctl','list'], |
3522 | 1730 | ['lspci','-nnv'], | 1999 | ['ipmi-sensors',''], |
3523 | 1731 | ['lspci','-mm'], | 2000 | ['ipmi-sensors','--output-sensor-thresholds'], |
3524 | 1732 | ['lspci','-mmk'], | 2001 | ['ipmitool','sensor'], |
3525 | 1733 | ['lspci','-mmkv'], | 2002 | ['lscpu',''], |
3526 | 1734 | ['lspci','-mmv'], | 2003 | ['lspci',''], |
3527 | 1735 | ['lspci','-mmnn'], | 2004 | ['lspci','-k'], |
3528 | 1736 | ['lspci','-v'], | 2005 | ['lspci','-n'], |
3529 | 1737 | ['lsusb',''], | 2006 | ['lspci','-nn'], |
3530 | 1738 | ['lsusb','-t'], | 2007 | ['lspci','-nnk'], |
3531 | 1739 | ['lsusb','-v'], | 2008 | ['lspci','-nnkv'],# returns ports |
3532 | 1740 | ['ps','aux'], | 2009 | ['lspci','-nnv'], |
3533 | 1741 | ['ps','-e'], | 2010 | ['lspci','-mm'], |
3534 | 1742 | ['ps','-p 1'], | 2011 | ['lspci','-mmk'], |
3535 | 1743 | ['runlevel',''], | 2012 | ['lspci','-mmkv'], |
3536 | 1744 | ['rc-status','-a'], | 2013 | ['lspci','-mmv'], |
3537 | 1745 | ['rc-status','-l'], | 2014 | ['lspci','-mmnn'], |
3538 | 1746 | ['rc-status','-r'], | 2015 | ['lspci','-v'], |
3539 | 1747 | ['sensors',''], | 2016 | ['lsusb',''], |
3540 | 1748 | # leaving this commented out to remind that some systems do not | 2017 | ['lsusb','-t'], |
3541 | 1749 | # support strings --version, but will just simply hang at that command | 2018 | ['lsusb','-v'], |
3542 | 1750 | # which you can duplicate by simply typing: strings then hitting enter. | 2019 | ['ps','aux'], |
3543 | 1751 | # ['strings','--version'], | 2020 | ['ps','-e'], |
3544 | 1752 | ['strings','present'], | 2021 | ['ps','-p 1'], |
3545 | 1753 | ['sysctl','-a'], | 2022 | ['runlevel',''], |
3546 | 1754 | ['systemctl','list-units'], | 2023 | ['rc-status','-a'], |
3547 | 1755 | ['systemctl','list-units --type=target'], | 2024 | ['rc-status','-l'], |
3548 | 1756 | ['systemd-detect-virt',''], | 2025 | ['rc-status','-r'], |
3549 | 1757 | ['upower','-e'], | 2026 | ['sensors',''], |
3550 | 1758 | ['uptime',''], | 2027 | ['sensors','-j'], |
3551 | 1759 | ['vcgencmd','get_mem arm'], | 2028 | ['sensors','-u'], |
3552 | 1760 | ['vcgencmd','get_mem gpu'], | 2029 | # leaving this commented out to remind that some systems do not |
3553 | 1761 | ); | 2030 | # support strings --version, but will just simply hang at that command |
3554 | 1762 | run_commands(\@cmds,'system'); | 2031 | # which you can duplicate by simply typing: strings then hitting enter. |
3555 | 1763 | @files = main::globber('/dev/bus/usb/*/*'); | 2032 | # ['strings','--version'], |
3556 | 1764 | copy_files(\@files, 'system'); | 2033 | ['strings','present'], |
3557 | 2034 | ['sysctl','-a'], | ||
3558 | 2035 | ['systemctl','list-units'], | ||
3559 | 2036 | ['systemctl','list-units --type=target'], | ||
3560 | 2037 | ['systemd-detect-virt',''], | ||
3561 | 2038 | ['uname','-a'], | ||
3562 | 2039 | ['upower','-e'], | ||
3563 | 2040 | ['uptime',''], | ||
3564 | 2041 | ['vcgencmd','get_mem arm'], | ||
3565 | 2042 | ['vcgencmd','get_mem gpu'], | ||
3566 | 2043 | ); | ||
3567 | 2044 | run_commands(\@cmds,'system'); | ||
3568 | 2045 | @files = main::globber('/dev/bus/usb/*/*'); | ||
3569 | 2046 | copy_files(\@files, 'system'); | ||
3570 | 1765 | } | 2047 | } |
3571 | 1766 | sub system_files { | 2048 | sub system_files { |
3610 | 1767 | print "Collecting system files data...\n"; | 2049 | print "Collecting system files data...\n"; |
3611 | 1768 | my (%data,@files,@files2); | 2050 | my (%data,@files,@files2); |
3612 | 1769 | @files = RepoData::get($data_dir); | 2051 | @files = RepoItem::get($data_dir); |
3613 | 1770 | copy_files(\@files, 'repo'); | 2052 | copy_files(\@files, 'repo'); |
3614 | 1771 | # chdir "/etc"; | 2053 | # chdir "/etc"; |
3615 | 1772 | @files = main::globber('/etc/*[-_]{[rR]elease,[vV]ersion,issue}*'); | 2054 | @files = main::globber('/etc/*[-_]{[rR]elease,[vV]ersion,issue}*'); |
3616 | 1773 | push (@files, '/etc/issue'); | 2055 | push(@files, '/etc/issue'); |
3617 | 1774 | push (@files, '/etc/lsb-release'); | 2056 | push(@files, '/etc/lsb-release'); |
3618 | 1775 | push (@files, '/etc/os-release'); | 2057 | push(@files, '/etc/os-release'); |
3619 | 1776 | copy_files(\@files,'system-distro'); | 2058 | push(@files, '/system/build.prop');# android data file, requires rooted |
3620 | 1777 | @files = main::globber('/etc/upstream[-_]{[rR]elease,[vV]ersion}/*'); | 2059 | push(@files, '/var/log/installer/oem-id'); # ubuntu only for oem installs? |
3621 | 1778 | copy_files(\@files,'system-distro'); | 2060 | copy_files(\@files,'system-distro'); |
3622 | 1779 | @files = main::globber('/etc/calamares/branding/*/branding.desc'); | 2061 | @files = main::globber('/etc/upstream[-_]{[rR]elease,[vV]ersion}/*'); |
3623 | 1780 | copy_files(\@files,'system-distro'); | 2062 | copy_files(\@files,'system-distro'); |
3624 | 1781 | @files = ( | 2063 | @files = main::globber('/etc/calamares/branding/*/branding.desc'); |
3625 | 1782 | '/proc/1/comm', | 2064 | copy_files(\@files,'system-distro'); |
3626 | 1783 | '/proc/cpuinfo', | 2065 | @files = ( |
3627 | 1784 | '/proc/meminfo', | 2066 | '/proc/1/comm', |
3628 | 1785 | '/proc/modules', | 2067 | '/proc/cmdline', |
3629 | 1786 | '/proc/net/arp', | 2068 | '/proc/cpuinfo', |
3630 | 1787 | '/proc/version', | 2069 | '/proc/meminfo', |
3631 | 1788 | ); | 2070 | '/proc/modules', |
3632 | 1789 | @files2=main::globber('/sys/class/power_supply/*/uevent'); | 2071 | '/proc/net/arp', |
3633 | 1790 | if (@files2){ | 2072 | '/proc/version', |
3634 | 1791 | @files = (@files,@files2); | 2073 | ); |
3635 | 1792 | } | 2074 | @files2=main::globber('/sys/class/power_supply/*/uevent'); |
3636 | 1793 | else { | 2075 | if (@files2){ |
3637 | 1794 | push (@files, '/sys-class-power-supply-empty'); | 2076 | push(@files,@files2); |
3638 | 1795 | } | 2077 | } |
3639 | 1796 | copy_files(\@files, 'system'); | 2078 | else { |
3640 | 1797 | @files = ( | 2079 | push(@files, '/sys-class-power-supply-empty'); |
3641 | 1798 | '/etc/make.conf', | 2080 | } |
3642 | 1799 | '/etc/src.conf', | 2081 | copy_files(\@files, 'system'); |
3643 | 1800 | '/var/run/dmesg.boot', | 2082 | @files = ( |
3644 | 1801 | ); | 2083 | '/etc/make.conf', |
3645 | 1802 | copy_files(\@files,'system-bsd'); | 2084 | '/etc/src.conf', |
3646 | 1803 | @files = main::globber('/sys/devices/system/cpu/vulnerabilities/*'); | 2085 | '/var/run/dmesg.boot', |
3647 | 1804 | copy_files(\@files,'security'); | 2086 | ); |
3648 | 2087 | copy_files(\@files,'system-bsd'); | ||
3649 | 2088 | @files = main::globber('/sys/devices/system/cpu/vulnerabilities/*'); | ||
3650 | 2089 | copy_files(\@files,'security'); | ||
3651 | 1805 | } | 2090 | } |
3652 | 1806 | ## SELF EXECUTE FOR LOG/OUTPUT | 2091 | ## SELF EXECUTE FOR LOG/OUTPUT |
3653 | 1807 | sub run_self { | 2092 | sub run_self { |
3664 | 1808 | print "Creating $self_name output file now. This can take a few seconds...\n"; | 2093 | print "Creating $self_name output file now. This can take a few seconds...\n"; |
3665 | 1809 | print "Starting $self_name from: $self_path\n"; | 2094 | print "Starting $self_name from: $self_path\n"; |
3666 | 1810 | my $i = ($option eq 'main-full')? ' -i' : ''; | 2095 | my $i = ($option eq 'main-full')? ' -i' : ''; |
3667 | 1811 | my $z = ($debugger{'z'}) ? ' -z' : ''; | 2096 | my $z = ($debugger{'filter'}) ? ' -z' : ''; |
3668 | 1812 | my $iz = "$i$z"; | 2097 | my $w = ($debugger{'width'}) ? $debugger{'width'} : 120; |
3669 | 1813 | $iz =~ s/[\s\-]//g; | 2098 | my $iz = "$i$z"; |
3670 | 1814 | my $cmd = "$self_path/$self_name -FRfrploudmaxxx$i$z --usb --slots --debug 10 -y 120 > $data_dir/$self_name-FRfrploudmaxxx$iz-usb-slots-y120.txt 2>&1"; | 2099 | $iz =~ s/[\s-]//g; |
3671 | 1815 | system($cmd); | 2100 | my $self_file = "$data_dir/$self_name-FERfJLrploudma$iz-slots-y$w.txt"; |
3672 | 1816 | copy($log_file, "$data_dir") or main::error_handler('copy-failed', "$log_file", "$!"); | 2101 | my $cmd = "$self_path/$self_name -FERfJLrploudma$i$z --slots --debug 10 -y $w > $self_file 2>&1"; |
3673 | 1817 | system("$self_path/$self_name --recommends -y 120 > $data_dir/$self_name-recommends-120.txt 2>&1"); | 2102 | system($cmd); |
3674 | 2103 | copy($log_file, "$data_dir") or main::error_handler('copy-failed', "$log_file", "$!"); | ||
3675 | 2104 | system("$self_path/$self_name --recommends -y 120 > $data_dir/$self_name-recommends-120.txt 2>&1"); | ||
3676 | 1818 | } | 2105 | } |
3677 | 1819 | 2106 | ||
3678 | 1820 | ## UTILITIES COPY/CMD/WRITE | 2107 | ## UTILITIES COPY/CMD/WRITE |
3679 | 1821 | sub copy_files { | 2108 | sub copy_files { |
3708 | 1822 | my ($files_ref,$type,$alt_dir) = @_; | 2109 | my ($files_ref,$type,$alt_dir) = @_; |
3709 | 1823 | my ($absent,$error,$good,$name,$unreadable); | 2110 | my ($absent,$error,$good,$name,$unreadable); |
3710 | 1824 | my $directory = ($alt_dir) ? $alt_dir : $data_dir; | 2111 | my $directory = ($alt_dir) ? $alt_dir : $data_dir; |
3711 | 1825 | my $working = ($type ne 'proc') ? "$type-file-": ''; | 2112 | my $working = ($type ne 'proc') ? "$type-file-": ''; |
3712 | 1826 | foreach (@$files_ref) { | 2113 | foreach (@$files_ref){ |
3713 | 1827 | $name = $_; | 2114 | $name = $_; |
3714 | 1828 | $name =~ s/^\///; | 2115 | $name =~ s/^\///; |
3715 | 1829 | $name =~ s/\//~/g; | 2116 | $name =~ s/\//~/g; |
3716 | 1830 | # print "$name\n" if $type eq 'proc'; | 2117 | # print "$name\n" if $type eq 'proc'; |
3717 | 1831 | $name = "$directory/$working$name"; | 2118 | $name = "$directory/$working$name"; |
3718 | 1832 | $good = $name . '.txt'; | 2119 | $good = $name . '.txt'; |
3719 | 1833 | $absent = $name . '-absent'; | 2120 | $absent = $name . '-absent'; |
3720 | 1834 | $error = $name . '-error'; | 2121 | $error = $name . '-error'; |
3721 | 1835 | $unreadable = $name . '-unreadable'; | 2122 | $unreadable = $name . '-unreadable'; |
3722 | 1836 | # proc have already been tested for readable/exists | 2123 | # proc have already been tested for readable/exists |
3723 | 1837 | if ($type eq 'proc' || -e $_ ) { | 2124 | if ($type eq 'proc' || -e $_){ |
3724 | 1838 | print "F:$_\n" if $type eq 'proc' && $debugger{'proc-print'}; | 2125 | print "F:$_\n" if $type eq 'proc' && $debugger{'proc-print'}; |
3725 | 1839 | if ($type eq 'proc' || -r $_){ | 2126 | if ($type eq 'proc' || -r $_){ |
3726 | 1840 | copy($_,"$good") or main::toucher($error); | 2127 | copy($_,"$good") or main::toucher($error); |
3727 | 1841 | } | 2128 | } |
3728 | 1842 | else { | 2129 | else { |
3729 | 1843 | main::toucher($unreadable); | 2130 | main::toucher($unreadable); |
3730 | 1844 | } | 2131 | } |
3731 | 1845 | } | 2132 | } |
3732 | 1846 | else { | 2133 | else { |
3733 | 1847 | main::toucher($absent); | 2134 | main::toucher($absent); |
3734 | 1848 | } | 2135 | } |
3735 | 1849 | } | 2136 | } |
3736 | 1850 | } | 2137 | } |
3737 | 1851 | sub run_commands { | 2138 | sub run_commands { |
3767 | 1852 | my ($cmds,$type) = @_; | 2139 | my ($cmds,$type) = @_; |
3768 | 1853 | my $holder = ''; | 2140 | my $holder = ''; |
3769 | 1854 | my ($name,$cmd,$args); | 2141 | my ($name,$cmd,$args); |
3770 | 1855 | foreach (@$cmds){ | 2142 | foreach my $rows (@$cmds){ |
3771 | 1856 | my @rows = @$_; | 2143 | if (my $program = main::check_program($rows->[0])){ |
3772 | 1857 | if (my $program = main::check_program($rows[0])){ | 2144 | if ($rows->[1] eq 'present'){ |
3773 | 1858 | if ($rows[1] eq 'present'){ | 2145 | $name = "$data_dir/$type-cmd-$rows->[0]-present"; |
3774 | 1859 | $name = "$data_dir/$type-cmd-$rows[0]-present"; | 2146 | main::toucher($name); |
3775 | 1860 | main::toucher($name); | 2147 | } |
3776 | 1861 | } | 2148 | else { |
3777 | 1862 | else { | 2149 | $args = $rows->[1]; |
3778 | 1863 | $args = $rows[1]; | 2150 | $args =~ s/\s|--|\/|=/-/g; # for: |
3779 | 1864 | $args =~ s/\s|--|\/|=/-/g; # for: | 2151 | $args =~ s/--/-/g;# strip out -- that result from the above |
3780 | 1865 | $args =~ s/--/-/g;# strip out -- that result from the above | 2152 | $args =~ s/^-//g; |
3781 | 1866 | $args =~ s/^-//g; | 2153 | $args = "-$args" if $args; |
3782 | 1867 | $args = "-$args" if $args; | 2154 | $name = "$data_dir/$type-cmd-$rows->[0]$args.txt"; |
3783 | 1868 | $name = "$data_dir/$type-cmd-$rows[0]$args.txt"; | 2155 | $cmd = "$program $rows->[1] >$name 2>&1"; |
3784 | 1869 | $cmd = "$program $rows[1] >$name 2>&1"; | 2156 | system($cmd); |
3785 | 1870 | system($cmd); | 2157 | } |
3786 | 1871 | } | 2158 | } |
3787 | 1872 | } | 2159 | else { |
3788 | 1873 | else { | 2160 | if ($holder ne $rows->[0]){ |
3789 | 1874 | if ($holder ne $rows[0]){ | 2161 | $name = "$data_dir/$type-cmd-$rows->[0]-absent"; |
3790 | 1875 | $name = "$data_dir/$type-cmd-$rows[0]-absent"; | 2162 | main::toucher($name); |
3791 | 1876 | main::toucher($name); | 2163 | $holder = $rows->[0]; |
3792 | 1877 | $holder = $rows[0]; | 2164 | } |
3793 | 1878 | } | 2165 | } |
3794 | 1879 | } | 2166 | } |
3766 | 1880 | } | ||
3795 | 1881 | } | 2167 | } |
3796 | 1882 | sub write_data { | 2168 | sub write_data { |
3819 | 1883 | my ($data_ref, $type) = @_; | 2169 | my ($data_ref, $type) = @_; |
3820 | 1884 | my ($empty,$error,$fh,$good,$name,$undefined,$value); | 2170 | my ($empty,$error,$fh,$good,$name,$undefined,$value); |
3821 | 1885 | foreach (keys %$data_ref) { | 2171 | foreach (keys %$data_ref){ |
3822 | 1886 | $value = $$data_ref{$_}; | 2172 | $value = $data_ref->{$_}; |
3823 | 1887 | $name = "$data_dir/$type-data-$_"; | 2173 | $name = "$data_dir/$type-data-$_"; |
3824 | 1888 | $good = $name . '.txt'; | 2174 | $good = $name . '.txt'; |
3825 | 1889 | $empty = $name . '-empty'; | 2175 | $empty = $name . '-empty'; |
3826 | 1890 | $error = $name . '-error'; | 2176 | $error = $name . '-error'; |
3827 | 1891 | $undefined = $name . '-undefined'; | 2177 | $undefined = $name . '-undefined'; |
3828 | 1892 | if (defined $value) { | 2178 | if (defined $value){ |
3829 | 1893 | if ($value || $value eq '0'){ | 2179 | if ($value || $value eq '0'){ |
3830 | 1894 | open($fh, '>', $good) or main::toucher($error); | 2180 | open($fh, '>', $good) or main::toucher($error); |
3831 | 1895 | print $fh "$value"; | 2181 | print $fh "$value"; |
3832 | 1896 | } | 2182 | } |
3833 | 1897 | else { | 2183 | else { |
3834 | 1898 | main::toucher($empty); | 2184 | main::toucher($empty); |
3835 | 1899 | } | 2185 | } |
3836 | 1900 | } | 2186 | } |
3837 | 1901 | else { | 2187 | else { |
3838 | 1902 | main::toucher($undefined); | 2188 | main::toucher($undefined); |
3839 | 1903 | } | 2189 | } |
3840 | 1904 | } | 2190 | } |
3841 | 1905 | } | 2191 | } |
3842 | 1906 | ## TOOLS FOR DIRECTORY TREE/LS/TRAVERSE; UPLOADER | 2192 | ## TOOLS FOR DIRECTORY TREE/LS/TRAVERSE; UPLOADER |
3843 | 1907 | sub build_tree { | 2193 | sub build_tree { |
3875 | 1908 | my ($which) = @_; | 2194 | my ($which) = @_; |
3876 | 1909 | if ( $which eq 'sys' && main::check_program('tree') ){ | 2195 | if ($which eq 'sys' && main::check_program('tree')){ |
3877 | 1910 | print "Constructing /$which tree data...\n"; | 2196 | print "Constructing /$which tree data...\n"; |
3878 | 1911 | my $dirname = '/sys'; | 2197 | my $dirname = '/sys'; |
3879 | 1912 | my $cmd; | 2198 | my $cmd; |
3880 | 1913 | system("tree -a -L 10 /sys > $data_dir/sys-data-tree-full-10.txt"); | 2199 | system("tree -a -L 10 /sys > $data_dir/sys-data-tree-full-10.txt"); |
3881 | 1914 | opendir my($dh), $dirname or main::error_handler('open-dir',"$dirname", "$!"); | 2200 | opendir(my $dh, $dirname) or main::error_handler('open-dir',"$dirname", "$!"); |
3882 | 1915 | my @files = readdir $dh; | 2201 | my @files = readdir($dh); |
3883 | 1916 | closedir $dh; | 2202 | closedir $dh; |
3884 | 1917 | foreach (@files){ | 2203 | foreach (@files){ |
3885 | 1918 | next if /^\./; | 2204 | next if /^\./; |
3886 | 1919 | $cmd = "tree -a -L 10 $dirname/$_ > $data_dir/sys-data-tree-$_-10.txt"; | 2205 | $cmd = "tree -a -L 10 $dirname/$_ > $data_dir/sys-data-tree-$_-10.txt"; |
3887 | 1920 | #print "$cmd\n"; | 2206 | # print "$cmd\n"; |
3888 | 1921 | system($cmd); | 2207 | system($cmd); |
3889 | 1922 | } | 2208 | } |
3890 | 1923 | } | 2209 | } |
3891 | 1924 | print "Constructing /$which ls data...\n"; | 2210 | print "Constructing /$which ls data...\n"; |
3892 | 1925 | if ($which eq 'sys'){ | 2211 | if ($which eq 'sys'){ |
3893 | 1926 | directory_ls($which,1); | 2212 | directory_ls($which,1); |
3894 | 1927 | directory_ls($which,2); | 2213 | directory_ls($which,2); |
3895 | 1928 | directory_ls($which,3); | 2214 | directory_ls($which,3); |
3896 | 1929 | directory_ls($which,4); | 2215 | directory_ls($which,4); |
3897 | 1930 | } | 2216 | } |
3898 | 1931 | elsif ($which eq 'proc') { | 2217 | elsif ($which eq 'proc'){ |
3899 | 1932 | directory_ls('proc',1); | 2218 | directory_ls('proc',1); |
3900 | 1933 | directory_ls('proc',2,'[a-z]'); | 2219 | directory_ls('proc',2,'[a-z]'); |
3901 | 1934 | # don't want the /proc/self or /proc/thread-self directories, those are | 2220 | # don't want the /proc/self or /proc/thread-self directories, those are |
3902 | 1935 | # too invasive | 2221 | # too invasive |
3903 | 1936 | #directory_ls('proc',3,'[a-z]'); | 2222 | #directory_ls('proc',3,'[a-z]'); |
3904 | 1937 | #directory_ls('proc',4,'[a-z]'); | 2223 | #directory_ls('proc',4,'[a-z]'); |
3905 | 1938 | } | 2224 | } |
3906 | 1939 | } | 2225 | } |
3907 | 1940 | 2226 | ||
3908 | 1941 | # include is basic regex for ls path syntax, like [a-z] | 2227 | # include is basic regex for ls path syntax, like [a-z] |
3909 | 1942 | sub directory_ls { | 2228 | sub directory_ls { |
3957 | 1943 | my ( $dir,$depth,$include) = @_; | 2229 | my ($dir,$depth,$include) = @_; |
3958 | 1944 | $include ||= ''; | 2230 | $include ||= ''; |
3959 | 1945 | my ($exclude) = (''); | 2231 | my ($exclude) = (''); |
3960 | 1946 | # wd do NOT want to see anything in self or thread-self!! | 2232 | # wd do NOT want to see anything in self or thread-self!! |
3961 | 1947 | # $exclude = 'I self -I thread-self' if $dir eq 'proc'; | 2233 | # $exclude = 'I self -I thread-self' if $dir eq 'proc'; |
3962 | 1948 | my $cmd = do { | 2234 | my $cmd = do { |
3963 | 1949 | if ( $depth == 1 ){ "ls -l $exclude /$dir/$include 2>/dev/null" } | 2235 | if ($depth == 1){ "ls -l $exclude /$dir/$include 2>/dev/null" } |
3964 | 1950 | elsif ( $depth == 2 ){ "ls -l $exclude /$dir/$include*/ 2>/dev/null" } | 2236 | elsif ($depth == 2){ "ls -l $exclude /$dir/$include*/ 2>/dev/null" } |
3965 | 1951 | elsif ( $depth == 3 ){ "ls -l $exclude /$dir/$include*/*/ 2>/dev/null" } | 2237 | elsif ($depth == 3){ "ls -l $exclude /$dir/$include*/*/ 2>/dev/null" } |
3966 | 1952 | elsif ( $depth == 4 ){ "ls -l $exclude /$dir/$include*/*/*/ 2>/dev/null" } | 2238 | elsif ($depth == 4){ "ls -l $exclude /$dir/$include*/*/*/ 2>/dev/null" } |
3967 | 1953 | elsif ( $depth == 5 ){ "ls -l $exclude /$dir/$include*/*/*/*/ 2>/dev/null" } | 2239 | elsif ($depth == 5){ "ls -l $exclude /$dir/$include*/*/*/*/ 2>/dev/null" } |
3968 | 1954 | elsif ( $depth == 6 ){ "ls -l $exclude /$dir/$include*/*/*/*/*/ 2>/dev/null" } | 2240 | elsif ($depth == 6){ "ls -l $exclude /$dir/$include*/*/*/*/*/ 2>/dev/null" } |
3969 | 1955 | }; | 2241 | }; |
3970 | 1956 | my @working = (); | 2242 | my @working; |
3971 | 1957 | my $output = ''; | 2243 | my $output = ''; |
3972 | 1958 | my ($type); | 2244 | my ($type); |
3973 | 1959 | my $result = qx($cmd); | 2245 | my $result = qx($cmd); |
3974 | 1960 | open my $ch, '<', \$result or main::error_handler('open-data',"$cmd", "$!"); | 2246 | open(my $ch, '<', \$result) or main::error_handler('open-data',"$cmd", "$!"); |
3975 | 1961 | while ( my $line = <$ch> ){ | 2247 | while (my $line = <$ch>){ |
3976 | 1962 | chomp($line); | 2248 | chomp($line); |
3977 | 1963 | $line =~ s/^\s+|\s+$//g; | 2249 | $line =~ s/^\s+|\s+$//g; |
3978 | 1964 | @working = split /\s+/, $line; | 2250 | @working = split(/\s+/, $line); |
3979 | 1965 | $working[0] ||= ''; | 2251 | $working[0] ||= ''; |
3980 | 1966 | if ( scalar @working > 7 ){ | 2252 | if (scalar @working > 7){ |
3981 | 1967 | if ($working[0] =~ /^d/ ){ | 2253 | if ($working[0] =~ /^d/){ |
3982 | 1968 | $type = "d - "; | 2254 | $type = "d - "; |
3983 | 1969 | } | 2255 | } |
3984 | 1970 | elsif ($working[0] =~ /^l/){ | 2256 | elsif ($working[0] =~ /^l/){ |
3985 | 1971 | $type = "l - "; | 2257 | $type = "l - "; |
3986 | 1972 | } | 2258 | } |
3987 | 1973 | else { | 2259 | else { |
3988 | 1974 | $type = "f - "; | 2260 | $type = "f - "; |
3989 | 1975 | } | 2261 | } |
3990 | 1976 | $working[9] ||= ''; | 2262 | $working[9] ||= ''; |
3991 | 1977 | $working[10] ||= ''; | 2263 | $working[10] ||= ''; |
3992 | 1978 | $output = $output . " $type$working[8] $working[9] $working[10]\n"; | 2264 | $output = $output . " $type$working[8] $working[9] $working[10]\n"; |
3993 | 1979 | } | 2265 | } |
3994 | 1980 | elsif ( $working[0] !~ /^total/ ){ | 2266 | elsif ($working[0] !~ /^total/){ |
3995 | 1981 | $output = $output . $line . "\n"; | 2267 | $output = $output . $line . "\n"; |
3996 | 1982 | } | 2268 | } |
3997 | 1983 | } | 2269 | } |
3998 | 1984 | close $ch; | 2270 | close $ch; |
3999 | 1985 | my $file = "$data_dir/$dir-data-ls-$depth.txt"; | 2271 | my $file = "$data_dir/$dir-data-ls-$depth.txt"; |
4000 | 1986 | open my $fh, '>', $file or main::error_handler('create',"$file", "$!"); | 2272 | open(my $fh, '>', $file) or main::error_handler('create',"$file", "$!"); |
4001 | 1987 | print $fh $output; | 2273 | print $fh $output; |
4002 | 1988 | close $fh; | 2274 | close $fh; |
4003 | 1989 | # print "$output\n"; | 2275 | # print "$output\n"; |
4004 | 1990 | } | 2276 | } |
4005 | 1991 | sub proc_traverse_data { | 2277 | sub proc_traverse_data { |
4024 | 1992 | print "Building /proc file list...\n"; | 2278 | print "Building /proc file list...\n"; |
4025 | 1993 | # get rid pointless error:Can't cd to (/sys/kernel/) debug: Permission denied | 2279 | # get rid pointless error:Can't cd to (/sys/kernel/) debug: Permission denied |
4026 | 1994 | no warnings 'File::Find'; | 2280 | #no warnings 'File::Find'; |
4027 | 1995 | $parse_src = 'proc'; | 2281 | no warnings; |
4028 | 1996 | File::Find::find( \&wanted, "/proc"); | 2282 | $parse_src = 'proc'; |
4029 | 1997 | proc_traverse_processor(); | 2283 | File::Find::find(\&wanted, "/proc"); |
4030 | 1998 | @content = (); | 2284 | process_proc_traverse(); |
4031 | 1999 | } | 2285 | @content = (); |
4032 | 2000 | sub proc_traverse_processor { | 2286 | } |
4033 | 2001 | my ($data,$fh,$result,$row,$sep); | 2287 | sub process_proc_traverse { |
4034 | 2002 | my $proc_dir = "$data_dir/proc"; | 2288 | my ($data,$fh,$result,$row,$sep); |
4035 | 2003 | print "Adding /proc files...\n"; | 2289 | my $proc_dir = "$data_dir/proc"; |
4036 | 2004 | mkdir $proc_dir or main::error_handler('mkdir', "$proc_dir", "$!"); | 2290 | print "Adding /proc files...\n"; |
4037 | 2005 | # @content = sort @content; | 2291 | mkdir $proc_dir or main::error_handler('mkdir', "$proc_dir", "$!"); |
4038 | 2006 | copy_files(\@content,'proc',$proc_dir); | 2292 | # @content = sort @content; |
4039 | 2007 | # foreach (@content){ | 2293 | copy_files(\@content,'proc',$proc_dir); |
4040 | 2008 | # print "$_\n"; | 2294 | # foreach (@content){print "$_\n";} |
4023 | 2009 | # } | ||
4041 | 2010 | } | 2295 | } |
4042 | 2011 | 2296 | ||
4043 | 2012 | sub sys_traverse_data { | 2297 | sub sys_traverse_data { |
4085 | 2013 | print "Building /sys file list...\n"; | 2298 | print "Building /sys file list...\n"; |
4086 | 2014 | # get rid pointless error:Can't cd to (/sys/kernel/) debug: Permission denied | 2299 | # get rid pointless error:Can't cd to (/sys/kernel/) debug: Permission denied |
4087 | 2015 | no warnings 'File::Find'; | 2300 | #no warnings 'File::Find'; |
4088 | 2016 | $parse_src = 'sys'; | 2301 | no warnings; |
4089 | 2017 | File::Find::find( \&wanted, "/sys"); | 2302 | $parse_src = 'sys'; |
4090 | 2018 | sys_traverse_processsor(); | 2303 | File::Find::find(\&wanted, "/sys"); |
4091 | 2019 | @content = (); | 2304 | process_sys_traverse(); |
4092 | 2020 | } | 2305 | @content = (); |
4093 | 2021 | sub sys_traverse_processsor { | 2306 | } |
4094 | 2022 | my ($data,$fh,$result,$row,$sep); | 2307 | sub process_sys_traverse { |
4095 | 2023 | my $filename = "sys-data-parse.txt"; | 2308 | my ($data,$fh,$result,$row,$sep); |
4096 | 2024 | print "Parsing /sys files...\n"; | 2309 | my $filename = "sys-data-parse.txt"; |
4097 | 2025 | # no sorts, we want the order it comes in | 2310 | print "Parsing /sys files...\n"; |
4098 | 2026 | # @content = sort @content; | 2311 | # no sorts, we want the order it comes in |
4099 | 2027 | foreach (@content){ | 2312 | # @content = sort @content; |
4100 | 2028 | $data=''; | 2313 | foreach (@content){ |
4101 | 2029 | $sep=''; | 2314 | $data=''; |
4102 | 2030 | my $b_fh = 1; | 2315 | $sep=''; |
4103 | 2031 | print "F:$_\n" if $debugger{'sys-print'}; | 2316 | my $b_fh = 1; |
4104 | 2032 | open($fh, '<', $_) or $b_fh = 0; | 2317 | print "F:$_\n" if $debugger{'sys-print'}; |
4105 | 2033 | # needed for removing -T test and root | 2318 | open($fh, '<', $_) or $b_fh = 0; |
4106 | 2034 | if ($b_fh){ | 2319 | # needed for removing -T test and root |
4107 | 2035 | while ($row = <$fh>) { | 2320 | if ($b_fh){ |
4108 | 2036 | chomp $row; | 2321 | while ($row = <$fh>){ |
4109 | 2037 | $data .= $sep . '"' . $row . '"'; | 2322 | chomp($row); |
4110 | 2038 | $sep=', '; | 2323 | $data .= $sep . '"' . $row . '"'; |
4111 | 2039 | } | 2324 | $sep=', '; |
4112 | 2040 | } | 2325 | } |
4113 | 2041 | else { | 2326 | } |
4114 | 2042 | $data = '<unreadable>'; | 2327 | else { |
4115 | 2043 | } | 2328 | $data = '<unreadable>'; |
4116 | 2044 | $result .= "$_:[$data]\n"; | 2329 | } |
4117 | 2045 | # print "$_:[$data]\n" | 2330 | $result .= "$_:[$data]\n"; |
4118 | 2046 | } | 2331 | # print "$_:[$data]\n" |
4119 | 2047 | # print scalar @content . "\n"; | 2332 | } |
4120 | 2048 | open ($fh, '>', "$data_dir/$filename"); | 2333 | # print scalar @content . "\n"; |
4121 | 2049 | print $fh $result; | 2334 | open($fh, '>', "$data_dir/$filename"); |
4122 | 2050 | close $fh; | 2335 | print $fh $result; |
4123 | 2051 | # print $fh "$result"; | 2336 | close $fh; |
4124 | 2052 | } | 2337 | # print $fh "$result"; |
4125 | 2053 | 2338 | } | |
4126 | 2339 | # perl compiler complains on start if prune = 1 used only once, so either | ||
4127 | 2340 | # do $File::Find::prune = 1 if !$File::Find::prune; OR use no warnings 'once' | ||
4128 | 2054 | sub wanted { | 2341 | sub wanted { |
4161 | 2055 | return if -d; # not directory | 2342 | # note: we want these directories pruned before the -d test so find |
4162 | 2056 | return unless -e; # Must exist | 2343 | # doesn't try to read files inside of the directories |
4163 | 2057 | return unless -f; # Must be file | 2344 | if ($parse_src eq 'proc'){ |
4164 | 2058 | return unless -r; # Must be readable | 2345 | if ($File::Find::name =~ m!^/proc/[0-9]+! || |
4165 | 2059 | if ($parse_src eq 'sys'){ | 2346 | $File::Find::name =~ m!^/proc/(irq|spl|sys)! || |
4166 | 2060 | # note: a new file in 4.11 /sys can hang this, it is /parameter/ then | 2347 | # these choke on sudo/root: kmsg kcore kpage and we don't want keys or kallsyms |
4167 | 2061 | # a few variables. Since inxi does not need to see that file, we will | 2348 | $File::Find::name =~ m!^/proc/k! || |
4168 | 2062 | # not use it. Also do not need . files or __ starting files | 2349 | $File::Find::name =~ m!^/proc/bus/pci! || |
4169 | 2063 | # print $File::Find::name . "\n"; | 2350 | $File::Find::name =~ m!^/proc/(irq|spl|sys)!){ |
4170 | 2064 | # block maybe: cfgroup\/ | 2351 | $File::Find::prune = 1; |
4171 | 2065 | # picdec\/|, wait_for_fb_sleep/wake is an odroid thing caused hang | 2352 | return; |
4172 | 2066 | return if $File::Find::name =~ /(^\/sys\/power\/wait_for_fb)/; | 2353 | } |
4173 | 2067 | return if $File::Find::name =~ /\/(\.[a-z]|kernel\/|trace\/|parameters\/|debug\/)/; | 2354 | } |
4174 | 2068 | # comment this one out if you experience hangs or if | 2355 | elsif ($parse_src eq 'sys'){ |
4175 | 2069 | # we discover syntax of foreign language characters | 2356 | # note: a new file in 4.11 /sys can hang this, it is /parameter/ then |
4176 | 2070 | # Must be ascii like. This is questionable and might require further | 2357 | # a few variables. Since inxi does not need to see that file, we will |
4177 | 2071 | # investigation, it is removing some characters that we might want | 2358 | # not use it. |
4178 | 2072 | # NOTE: this made a bunch of files on arm systems unreadable so we handle | 2359 | if ($File::Find::name =~ m!/(kernel/|trace/|parameters|debug)!){ |
4179 | 2073 | # the readable tests in copy_files() | 2360 | $File::Find::prune = 1; |
4180 | 2074 | # return unless -T; | 2361 | } |
4181 | 2075 | } | 2362 | } |
4182 | 2076 | elsif ($parse_src eq 'proc') { | 2363 | return if -d; # not directory |
4183 | 2077 | return if $File::Find::name =~ /^\/proc\/[0-9]+\//; | 2364 | return unless -e; # Must exist |
4184 | 2078 | return if $File::Find::name =~ /^\/proc\/bus\/pci\//; | 2365 | return unless -f; # Must be file |
4185 | 2079 | return if $File::Find::name =~ /^\/proc\/(irq|spl|sys)\//; | 2366 | return unless -r; # Must be readable |
4186 | 2080 | # these choke on sudo/root: kmsg kcore kpage and we don't want keys or kallsyms | 2367 | if ($parse_src eq 'sys'){ |
4187 | 2081 | return if $File::Find::name =~ /^\/proc\/k/; | 2368 | # print $File::Find::name . "\n"; |
4188 | 2082 | return if $File::Find::name =~ /(\/mb_groups|debug)$/; | 2369 | # block maybe: cfgroup\/ |
4189 | 2083 | } | 2370 | # picdec\/|, wait_for_fb_sleep/wake is an odroid thing caused hang |
4190 | 2084 | # print $File::Find::name . "\n"; | 2371 | # wakeup_count also fails for android, but works fine on regular systems |
4191 | 2085 | push (@content, $File::Find::name); | 2372 | return if $b_arm && $File::Find::name =~ m!^/sys/power/(wait_for_fb_|wakeup_count$)!; |
4192 | 2086 | return; | 2373 | # do not need . files or __ starting files |
4193 | 2374 | return if $File::Find::name =~ m!/\.[a-z]!; | ||
4194 | 2375 | # pp_num_states: amdgpu driver bug; android: wakeup_count | ||
4195 | 2376 | return if $File::Find::name =~ m!/pp_num_states$!; | ||
4196 | 2377 | # comment this one out if you experience hangs or if | ||
4197 | 2378 | # we discover syntax of foreign language characters | ||
4198 | 2379 | # Must be ascii like. This is questionable and might require further | ||
4199 | 2380 | # investigation, it is removing some characters that we might want | ||
4200 | 2381 | # NOTE: this made a bunch of files on arm systems unreadable so we handle | ||
4201 | 2382 | # the readable tests in copy_files() | ||
4202 | 2383 | # return unless -T; | ||
4203 | 2384 | } | ||
4204 | 2385 | elsif ($parse_src eq 'proc'){ | ||
4205 | 2386 | return if $File::Find::name =~ m!(/mb_groups|debug)$!; | ||
4206 | 2387 | } | ||
4207 | 2388 | # print $File::Find::name . "\n"; | ||
4208 | 2389 | push(@content, $File::Find::name); | ||
4209 | 2390 | return; | ||
4210 | 2087 | } | 2391 | } |
4211 | 2088 | # args: 1 - path to file to be uploaded | 2392 | # args: 1 - path to file to be uploaded |
4212 | 2089 | # args: 2 - optional: alternate ftp upload url | 2393 | # args: 2 - optional: alternate ftp upload url |
4213 | 2090 | # NOTE: must be in format: ftp.site.com/incoming | 2394 | # NOTE: must be in format: ftp.site.com/incoming |
4214 | 2091 | sub upload_file { | 2395 | sub upload_file { |
4256 | 2092 | require Net::FTP; | 2396 | my ($self, $ftp_url) = @_; |
4257 | 2093 | import Net::FTP; | 2397 | my ($ftp, $domain, $host, $user, $pass, $dir, $error); |
4258 | 2094 | my ($self, $ftp_url) = @_; | 2398 | $ftp_url ||= main::get_defaults('ftp-upload'); |
4259 | 2095 | my ($ftp, $domain, $host, $user, $pass, $dir, $error); | 2399 | $ftp_url =~ s/\/$//g; # trim off trailing slash if present |
4260 | 2096 | $ftp_url ||= main::get_defaults('ftp-upload'); | 2400 | my @url = split('/', $ftp_url); |
4261 | 2097 | $ftp_url =~ s/\/$//g; # trim off trailing slash if present | 2401 | my $file_path = "$user_data_dir/$debug_gz"; |
4262 | 2098 | my @url = split(/\//, $ftp_url); | 2402 | $host = $url[0]; |
4263 | 2099 | my $file_path = "$user_data_dir/$debug_gz"; | 2403 | $dir = $url[1]; |
4264 | 2100 | $host = $url[0]; | 2404 | $domain = $host; |
4265 | 2101 | $dir = $url[1]; | 2405 | $domain =~ s/^ftp\.//; |
4266 | 2102 | $domain = $host; | 2406 | $user = "anonymous"; |
4267 | 2103 | $domain =~ s/^ftp\.//; | 2407 | $pass = "anonymous\@$domain"; |
4268 | 2104 | $user = "anonymous"; | 2408 | |
4269 | 2105 | $pass = "anonymous\@$domain"; | 2409 | print $line3; |
4270 | 2106 | 2410 | print "Uploading to: $ftp_url\n"; | |
4271 | 2107 | print $line3; | 2411 | # print "$host $domain $dir $user $pass\n"; |
4272 | 2108 | print "Uploading to: $ftp_url\n"; | 2412 | print "File to be uploaded:\n$file_path\n"; |
4273 | 2109 | # print "$host $domain $dir $user $pass\n"; | 2413 | |
4274 | 2110 | print "File to be uploaded:\n$file_path\n"; | 2414 | if ($host && ($file_path && -e $file_path)){ |
4275 | 2111 | 2415 | # NOTE: important: must explicitly set to passive true/1 | |
4276 | 2112 | if ($host && ( $file_path && -e $file_path ) ){ | 2416 | $ftp = Net::FTP->new($host, Debug => 0, Passive => 1) || main::error_handler('ftp-connect', $ftp->message); |
4277 | 2113 | # NOTE: important: must explicitly set to passive true/1 | 2417 | $ftp->login($user, $pass) || main::error_handler('ftp-login', $ftp->message); |
4278 | 2114 | $ftp = Net::FTP->new($host, Debug => 0, Passive => 1) || main::error_handler('ftp-connect', $ftp->message); | 2418 | $ftp->binary(); |
4279 | 2115 | $ftp->login($user, $pass) || main::error_handler('ftp-login', $ftp->message); | 2419 | $ftp->cwd($dir); |
4280 | 2116 | $ftp->binary(); | 2420 | print "Connected to FTP server.\n"; |
4281 | 2117 | $ftp->cwd($dir); | 2421 | $ftp->put($file_path) || main::error_handler('ftp-upload', $ftp->message); |
4282 | 2118 | print "Connected to FTP server.\n"; | 2422 | $ftp->quit; |
4283 | 2119 | $ftp->put($file_path) || main::error_handler('ftp-upload', $ftp->message); | 2423 | print "Uploaded file successfully!\n"; |
4284 | 2120 | $ftp->quit; | 2424 | print $ftp->message; |
4285 | 2121 | print "Uploaded file successfully!\n"; | 2425 | if ($debugger{'gz'}){ |
4286 | 2122 | print $ftp->message; | 2426 | print "Removing debugger gz file:\n$file_path\n"; |
4287 | 2123 | if ($debugger{'gz'}){ | 2427 | unlink $file_path or main::error_handler('remove',"$file_path", "$!"); |
4288 | 2124 | print "Removing debugger gz file:\n$file_path\n"; | 2428 | print "File removed.\n"; |
4289 | 2125 | unlink $file_path or main::error_handler('remove',"$file_path", "$!"); | 2429 | } |
4290 | 2126 | print "File removed.\n"; | 2430 | print "Debugger data generation and upload completed. Thank you for your help.\n"; |
4291 | 2127 | } | 2431 | } |
4292 | 2128 | print "Debugger data generation and upload completed. Thank you for your help.\n"; | 2432 | else { |
4293 | 2129 | } | 2433 | main::error_handler('ftp-bad-path', "$file_path"); |
4294 | 2130 | else { | 2434 | } |
4254 | 2131 | main::error_handler('ftp-bad-path', "$file_path"); | ||
4255 | 2132 | } | ||
4295 | 2133 | } | 2435 | } |
4296 | 2134 | } | 2436 | } |
4297 | 2437 | |||
4298 | 2135 | # random tests for various issues | 2438 | # random tests for various issues |
4299 | 2136 | sub user_debug_test_1 { | 2439 | sub user_debug_test_1 { |
4311 | 2137 | # open(my $duped, '>&', STDOUT); | 2440 | # open(my $duped, '>&', STDOUT); |
4312 | 2138 | # local *STDOUT = $duped; | 2441 | # local *STDOUT = $duped; |
4313 | 2139 | # my $item = POSIX::strftime("%c", localtime); | 2442 | # my $item = POSIX::strftime("%c", localtime); |
4314 | 2140 | # print "Testing character encoding handling. Perl IO data:\n"; | 2443 | # print "Testing character encoding handling. Perl IO data:\n"; |
4315 | 2141 | # print(join(', ', PerlIO::get_layers(STDOUT)), "\n"); | 2444 | # print(join(', ', PerlIO::get_layers(STDOUT)), "\n"); |
4316 | 2142 | # print "Without binmode: ", $item,"\n"; | 2445 | # print "Without binmode: ", $item,"\n"; |
4317 | 2143 | # binmode STDOUT,":utf8"; | 2446 | # binmode STDOUT,":utf8"; |
4318 | 2144 | # print "With binmode: ", $item,"\n"; | 2447 | # print "With binmode: ", $item,"\n"; |
4319 | 2145 | # print "Perl IO data:\n"; | 2448 | # print "Perl IO data:\n"; |
4320 | 2146 | # print(join(', ', PerlIO::get_layers(STDOUT)), "\n"); | 2449 | # print(join(', ', PerlIO::get_layers(STDOUT)), "\n"); |
4321 | 2147 | # close($duped); | 2450 | # close $duped; |
4322 | 2451 | } | ||
4323 | 2452 | |||
4324 | 2453 | # see docs/optimization.txt | ||
4325 | 2454 | sub ram_use { | ||
4326 | 2455 | my ($name, $ref) = @_; | ||
4327 | 2456 | printf "%-25s %5d %5d\n", $name, size($ref), total_size($ref); | ||
4328 | 2148 | } | 2457 | } |
4329 | 2149 | 2458 | ||
4330 | 2150 | #### ------------------------------------------------------------------- | 2459 | #### ------------------------------------------------------------------- |
4331 | @@ -2152,165 +2461,177 @@ sub user_debug_test_1 { | |||
4332 | 2152 | #### ------------------------------------------------------------------- | 2461 | #### ------------------------------------------------------------------- |
4333 | 2153 | 2462 | ||
4334 | 2154 | sub download_file { | 2463 | sub download_file { |
4383 | 2155 | my ($type, $url, $file) = @_; | 2464 | my ($type, $url, $file,$ua) = @_; |
4384 | 2156 | my ($cmd,$args,$timeout) = ('','',''); | 2465 | my ($cmd,$args,$timeout) = ('','',''); |
4385 | 2157 | my $debug_data = ''; | 2466 | my $debug_data = ''; |
4386 | 2158 | my $result = 1; | 2467 | my $result = 1; |
4387 | 2159 | $dl{'no-ssl-opt'} ||= ''; | 2468 | $ua = ($ua && $dl{'ua'}) ? $dl{'ua'} . $ua : ''; |
4388 | 2160 | $dl{'spider'} ||= ''; | 2469 | $dl{'no-ssl-opt'} ||= ''; |
4389 | 2161 | $file ||= 'N/A'; # to avoid debug error | 2470 | $dl{'spider'} ||= ''; |
4390 | 2162 | if ( ! $dl{'dl'} ){ | 2471 | $file ||= 'N/A'; # to avoid debug error |
4391 | 2163 | return 0; | 2472 | if (!$dl{'dl'}){ |
4392 | 2164 | } | 2473 | return 0; |
4393 | 2165 | if ($dl{'timeout'}){ | 2474 | } |
4394 | 2166 | $timeout = "$dl{'timeout'}$dl_timeout"; | 2475 | if ($dl{'timeout'}){ |
4395 | 2167 | } | 2476 | $timeout = "$dl{'timeout'}$dl_timeout"; |
4396 | 2168 | # print "$dl{'no-ssl-opt'}\n"; | 2477 | } |
4397 | 2169 | # print "$dl{'dl'}\n"; | 2478 | # print "$dl{'no-ssl-opt'}\n"; |
4398 | 2170 | # tiny supports spider sort of | 2479 | # print "$dl{'dl'}\n"; |
4399 | 2171 | ## NOTE: 1 is success, 0 false for Perl | 2480 | # tiny supports spider sort of |
4400 | 2172 | if ($dl{'dl'} eq 'tiny' ){ | 2481 | ## NOTE: 1 is success, 0 false for Perl |
4401 | 2173 | $cmd = "Using tiny: type: $type \nurl: $url \nfile: $file"; | 2482 | if ($dl{'dl'} eq 'tiny'){ |
4402 | 2174 | $result = get_file($type, $url, $file); | 2483 | $cmd = "Using tiny: type: $type \nurl: $url \nfile: $file"; |
4403 | 2175 | $debug_data = ($type ne 'stdout') ? $result : 'Success: stdout data not null.'; | 2484 | $result = get_file($type, $url, $file); |
4404 | 2176 | } | 2485 | $debug_data = ($type ne 'stdout') ? $result : 'Success: stdout data not null.'; |
4405 | 2177 | # But: 0 is success, and 1 is false for these | 2486 | } |
4406 | 2178 | # when strings are returned, they will be taken as true | 2487 | # But: 0 is success, and 1 is false for these |
4407 | 2179 | else { | 2488 | # when strings are returned, they will be taken as true |
4408 | 2180 | if ($type eq 'stdout'){ | 2489 | # urls must be " quoted in case special characters present |
4409 | 2181 | $args = $dl{'stdout'}; | 2490 | else { |
4410 | 2182 | $cmd = "$dl{'dl'} $dl{'no-ssl-opt'} $timeout $args $url $dl{'null'}"; | 2491 | if ($type eq 'stdout'){ |
4411 | 2183 | $result = qx($cmd); | 2492 | $args = $dl{'stdout'}; |
4412 | 2184 | $debug_data = ($result) ? 'Success: stdout data not null.' : 'Download resulted in null data!'; | 2493 | $cmd = "$dl{'dl'} $dl{'no-ssl-opt'} $ua $timeout $args \"$url\" $dl{'null'}"; |
4413 | 2185 | } | 2494 | $result = qx($cmd); |
4414 | 2186 | elsif ($type eq 'file') { | 2495 | $debug_data = ($result) ? 'Success: stdout data not null.' : 'Download resulted in null data!'; |
4415 | 2187 | $args = $dl{'file'}; | 2496 | } |
4416 | 2188 | $cmd = "$dl{'dl'} $dl{'no-ssl-opt'} $timeout $args $file $url $dl{'null'}"; | 2497 | elsif ($type eq 'file'){ |
4417 | 2189 | system($cmd); | 2498 | $args = $dl{'file'}; |
4418 | 2190 | $result = ($?) ? 0 : 1; # reverse these into Perl t/f | 2499 | $cmd = "$dl{'dl'} $dl{'no-ssl-opt'} $ua $timeout $args $file \"$url\" $dl{'null'}"; |
4419 | 2191 | $debug_data = $result; | 2500 | system($cmd); |
4420 | 2192 | } | 2501 | $result = ($?) ? 0 : 1; # reverse these into Perl t/f |
4421 | 2193 | elsif ( $dl{'dl'} eq 'wget' && $type eq 'spider'){ | 2502 | $debug_data = $result; |
4422 | 2194 | $cmd = "$dl{'dl'} $dl{'no-ssl-opt'} $timeout $dl{'spider'} $url"; | 2503 | } |
4423 | 2195 | system($cmd); | 2504 | elsif ($dl{'dl'} eq 'wget' && $type eq 'spider'){ |
4424 | 2196 | $result = ($?) ? 0 : 1; # reverse these into Perl t/f | 2505 | $cmd = "$dl{'dl'} $dl{'no-ssl-opt'} $ua $timeout $dl{'spider'} \"$url\""; |
4425 | 2197 | $debug_data = $result; | 2506 | system($cmd); |
4426 | 2198 | } | 2507 | $result = ($?) ? 0 : 1; # reverse these into Perl t/f |
4427 | 2199 | } | 2508 | $debug_data = $result; |
4428 | 2200 | print "-------\nDownloader Data:\n$cmd\nResult: $debug_data\n" if $test[1]; | 2509 | } |
4429 | 2201 | log_data('data',"$cmd\nResult: $result") if $b_log; | 2510 | } |
4430 | 2202 | return $result; | 2511 | print "-------\nDownloader Data:\n$cmd\nResult: $debug_data\n" if $dbg[1]; |
4431 | 2512 | log_data('data',"$cmd\nResult: $result") if $b_log; | ||
4432 | 2513 | return $result; | ||
4433 | 2203 | } | 2514 | } |
4434 | 2204 | 2515 | ||
4435 | 2205 | sub get_file { | 2516 | sub get_file { |
4476 | 2206 | my ($type, $url, $file) = @_; | 2517 | my ($type, $url, $file) = @_; |
4477 | 2207 | my $response = HTTP::Tiny->new->get($url); | 2518 | my $tiny = HTTP::Tiny->new; |
4478 | 2208 | my $return = 1; | 2519 | # note: default is no verify, so default here actually is to verify unless overridden |
4479 | 2209 | my $debug = 0; | 2520 | $tiny->verify_SSL => 1 if !$dl{'no-ssl-opt'}; |
4480 | 2210 | my $fh; | 2521 | my $response = $tiny->get($url); |
4481 | 2211 | $file ||= 'N/A'; | 2522 | my $return = 1; |
4482 | 2212 | log_data('dump','%{$response}',\%{$response}) if $b_log; | 2523 | my $debug = 0; |
4483 | 2213 | # print Dumper \%{$response}; | 2524 | my $fh; |
4484 | 2214 | if ( ! $response->{success} ){ | 2525 | $file ||= 'N/A'; |
4485 | 2215 | my $content = $response->{content}; | 2526 | log_data('dump','%{$response}',$response) if $b_log; |
4486 | 2216 | $content ||= "N/A\n"; | 2527 | # print Dumper $response; |
4487 | 2217 | my $msg = "Failed to connect to server/file!\n"; | 2528 | if (!$response->{'success'}){ |
4488 | 2218 | $msg .= "Response: ${content}Downloader: HTTP::Tiny URL: $url\nFile: $file"; | 2529 | my $content = $response->{'content'}; |
4489 | 2219 | log_data('data',$msg) if $b_log; | 2530 | $content ||= "N/A\n"; |
4490 | 2220 | print error_defaults('download-error',$msg) if $test[1]; | 2531 | my $msg = "Failed to connect to server/file!\n"; |
4491 | 2221 | $return = 0; | 2532 | $msg .= "Response: ${content}Downloader: HTTP::Tiny URL: $url\nFile: $file"; |
4492 | 2222 | } | 2533 | log_data('data',$msg) if $b_log; |
4493 | 2223 | else { | 2534 | print error_defaults('download-error',$msg) if $dbg[1]; |
4494 | 2224 | if ( $debug ){ | 2535 | $return = 0; |
4495 | 2225 | print "$response->{success}\n"; | 2536 | } |
4496 | 2226 | print "$response->{status} $response->{reason}\n"; | 2537 | else { |
4497 | 2227 | while (my ($key, $value) = each %{$response->{headers}}) { | 2538 | if ($debug){ |
4498 | 2228 | for (ref $value eq "ARRAY" ? @$value : $value) { | 2539 | print "$response->{success}\n"; |
4499 | 2229 | print "$key: $_\n"; | 2540 | print "$response->{status} $response->{reason}\n"; |
4500 | 2230 | } | 2541 | while (my ($key, $value) = each %{$response->{'headers'}}){ |
4501 | 2231 | } | 2542 | for (ref $value eq "ARRAY" ? @$value : $value){ |
4502 | 2232 | } | 2543 | print "$key: $_\n"; |
4503 | 2233 | if ( $type eq "stdout" || $type eq "ua-stdout" ){ | 2544 | } |
4504 | 2234 | $return = $response->{content}; | 2545 | } |
4505 | 2235 | } | 2546 | } |
4506 | 2236 | elsif ($type eq "spider"){ | 2547 | if ($type eq "stdout" || $type eq "ua-stdout"){ |
4507 | 2237 | # do nothing, just use the return value | 2548 | $return = $response->{'content'}; |
4508 | 2238 | } | 2549 | } |
4509 | 2239 | elsif ($type eq "file"){ | 2550 | elsif ($type eq "spider"){ |
4510 | 2240 | open($fh, ">", $file); | 2551 | # do nothing, just use the return value |
4511 | 2241 | print $fh $response->{content}; # or die "can't write to file!\n"; | 2552 | } |
4512 | 2242 | close $fh; | 2553 | elsif ($type eq "file"){ |
4513 | 2243 | } | 2554 | open($fh, ">", $file); |
4514 | 2244 | } | 2555 | print $fh $response->{'content'}; # or die "can't write to file!\n"; |
4515 | 2245 | return $return; | 2556 | close $fh; |
4516 | 2557 | } | ||
4517 | 2558 | } | ||
4518 | 2559 | return $return; | ||
4519 | 2246 | } | 2560 | } |
4520 | 2247 | 2561 | ||
4521 | 2248 | sub set_downloader { | 2562 | sub set_downloader { |
4581 | 2249 | eval $start if $b_log; | 2563 | eval $start if $b_log; |
4582 | 2250 | $dl{'no-ssl'} = ''; | 2564 | my $quiet = ''; |
4583 | 2251 | $dl{'null'} = ''; | 2565 | $dl{'no-ssl'} = ''; |
4584 | 2252 | $dl{'spider'} = ''; | 2566 | $dl{'null'} = ''; |
4585 | 2253 | # we only want to use HTTP::Tiny if it's present in user system. | 2567 | $dl{'spider'} = ''; |
4586 | 2254 | # It is NOT part of core modules. IO::Socket::SSL is also required | 2568 | # we only want to use HTTP::Tiny if it's present in user system. |
4587 | 2255 | # For some https connections so only use tiny as option if both present | 2569 | # It is NOT part of core modules. IO::Socket::SSL is also required |
4588 | 2256 | if ($dl{'tiny'}){ | 2570 | # For some https connections so only use tiny as option if both present |
4589 | 2257 | if (check_module('HTTP::Tiny') && check_module('IO::Socket::SSL')){ | 2571 | if ($dl{'tiny'}){ |
4590 | 2258 | import HTTP::Tiny; | 2572 | if (check_perl_module('HTTP::Tiny') && check_perl_module('IO::Socket::SSL')){ |
4591 | 2259 | import IO::Socket::SSL; | 2573 | HTTP::Tiny->import; |
4592 | 2260 | $dl{'tiny'} = 1; | 2574 | IO::Socket::SSL->import; |
4593 | 2261 | } | 2575 | $dl{'tiny'} = 1; |
4594 | 2262 | else { | 2576 | } |
4595 | 2263 | $dl{'tiny'} = 0; | 2577 | else { |
4596 | 2264 | } | 2578 | $dl{'tiny'} = 0; |
4597 | 2265 | } | 2579 | } |
4598 | 2266 | #print $dl{'tiny'} . "\n"; | 2580 | } |
4599 | 2267 | if ($dl{'tiny'}){ | 2581 | # print $dl{'tiny'} . "\n"; |
4600 | 2268 | $dl{'dl'} = 'tiny'; | 2582 | if ($dl{'tiny'}){ |
4601 | 2269 | $dl{'file'} = ''; | 2583 | $dl{'dl'} = 'tiny'; |
4602 | 2270 | $dl{'stdout'} = ''; | 2584 | $dl{'file'} = ''; |
4603 | 2271 | $dl{'timeout'} = ''; | 2585 | $dl{'stdout'} = ''; |
4604 | 2272 | } | 2586 | $dl{'timeout'} = ''; |
4605 | 2273 | elsif ( $dl{'curl'} && check_program('curl') ){ | 2587 | } |
4606 | 2274 | $dl{'dl'} = 'curl'; | 2588 | elsif ($dl{'curl'} && check_program('curl')){ |
4607 | 2275 | $dl{'file'} = ' -L -s -o '; | 2589 | $quiet = '-s ' if !$dbg[1]; |
4608 | 2276 | $dl{'no-ssl'} = ' --insecure'; | 2590 | $dl{'dl'} = 'curl'; |
4609 | 2277 | $dl{'stdout'} = ' -L -s '; | 2591 | $dl{'file'} = " -L ${quiet}-o "; |
4610 | 2278 | $dl{'timeout'} = ' -y '; | 2592 | $dl{'no-ssl'} = ' --insecure'; |
4611 | 2279 | } | 2593 | $dl{'stdout'} = " -L ${quiet}"; |
4612 | 2280 | elsif ($dl{'wget'} && check_program('wget') ){ | 2594 | $dl{'timeout'} = ' -y '; |
4613 | 2281 | $dl{'dl'} = 'wget'; | 2595 | $dl{'ua'} = ' -A ' . $dl_ua; |
4614 | 2282 | $dl{'file'} = ' -q -O '; | 2596 | } |
4615 | 2283 | $dl{'no-ssl'} = ' --no-check-certificate'; | 2597 | elsif ($dl{'wget'} && check_program('wget')){ |
4616 | 2284 | $dl{'spider'} = ' -q --spider'; | 2598 | $quiet = '-q ' if !$dbg[1]; |
4617 | 2285 | $dl{'stdout'} = ' -q -O -'; | 2599 | $dl{'dl'} = 'wget'; |
4618 | 2286 | $dl{'timeout'} = ' -T '; | 2600 | $dl{'file'} = " ${quiet}-O "; |
4619 | 2287 | } | 2601 | $dl{'no-ssl'} = ' --no-check-certificate'; |
4620 | 2288 | elsif ($dl{'fetch'} && check_program('fetch')){ | 2602 | $dl{'spider'} = " ${quiet}--spider"; |
4621 | 2289 | $dl{'dl'} = 'fetch'; | 2603 | $dl{'stdout'} = " $quiet -O -"; |
4622 | 2290 | $dl{'file'} = ' -q -o '; | 2604 | $dl{'timeout'} = ' -T '; |
4623 | 2291 | $dl{'no-ssl'} = ' --no-verify-peer'; | 2605 | $dl{'ua'} = ' -U ' . $dl_ua; |
4624 | 2292 | $dl{'stdout'} = ' -q -o -'; | 2606 | } |
4625 | 2293 | $dl{'timeout'} = ' -T '; | 2607 | elsif ($dl{'fetch'} && check_program('fetch')){ |
4626 | 2294 | } | 2608 | $quiet = '-q ' if !$dbg[1]; |
4627 | 2295 | elsif ( $bsd_type eq 'openbsd' && check_program('ftp') ){ | 2609 | $dl{'dl'} = 'fetch'; |
4628 | 2296 | $dl{'dl'} = 'ftp'; | 2610 | $dl{'file'} = " ${quiet}-o "; |
4629 | 2297 | $dl{'file'} = ' -o '; | 2611 | $dl{'no-ssl'} = ' --no-verify-peer'; |
4630 | 2298 | $dl{'null'} = ' 2>/dev/null'; | 2612 | $dl{'stdout'} = " ${quiet}-o -"; |
4631 | 2299 | $dl{'stdout'} = ' -o - '; | 2613 | $dl{'timeout'} = ' -T '; |
4632 | 2300 | $dl{'timeout'} = ''; | 2614 | } |
4633 | 2301 | } | 2615 | # at least openbsd/netbsd |
4634 | 2302 | else { | 2616 | elsif ($bsd_type && check_program('ftp')){ |
4635 | 2303 | $dl{'dl'} = ''; | 2617 | $dl{'dl'} = 'ftp'; |
4636 | 2304 | } | 2618 | $dl{'file'} = ' -o '; |
4637 | 2305 | # no-ssl-opt is set to 1 with --no-ssl, so it is true, then assign | 2619 | $dl{'null'} = ' 2>/dev/null'; |
4638 | 2306 | $dl{'no-ssl-opt'} = $dl{'no-ssl'} if $dl{'no-ssl-opt'}; | 2620 | $dl{'stdout'} = ' -o - '; |
4639 | 2307 | eval $end if $b_log; | 2621 | $dl{'timeout'} = ''; |
4640 | 2622 | } | ||
4641 | 2623 | else { | ||
4642 | 2624 | $dl{'dl'} = ''; | ||
4643 | 2625 | } | ||
4644 | 2626 | # no-ssl-opt is set to 1 with --no-ssl, so it is true, then assign | ||
4645 | 2627 | $dl{'no-ssl-opt'} = $dl{'no-ssl'} if $dl{'no-ssl-opt'}; | ||
4646 | 2628 | eval $end if $b_log; | ||
4647 | 2308 | } | 2629 | } |
4648 | 2309 | 2630 | ||
4649 | 2310 | sub set_perl_downloader { | 2631 | sub set_perl_downloader { |
4653 | 2311 | my ($downloader) = @_; | 2632 | my ($downloader) = @_; |
4654 | 2312 | $downloader =~ s/perl/tiny/; | 2633 | $downloader =~ s/perl/tiny/; |
4655 | 2313 | return $downloader; | 2634 | return $downloader; |
4656 | 2314 | } | 2635 | } |
4657 | 2315 | 2636 | ||
4658 | 2316 | #### ------------------------------------------------------------------- | 2637 | #### ------------------------------------------------------------------- |
4659 | @@ -2318,97 +2639,97 @@ sub set_perl_downloader { | |||
4660 | 2318 | #### ------------------------------------------------------------------- | 2639 | #### ------------------------------------------------------------------- |
4661 | 2319 | 2640 | ||
4662 | 2320 | sub error_handler { | 2641 | sub error_handler { |
4745 | 2321 | eval $start if $b_log; | 2642 | eval $start if $b_log; |
4746 | 2322 | my ( $err, $one, $two) = @_; | 2643 | my ($err,$one,$two) = @_; |
4747 | 2323 | my ($b_help,$b_recommends); | 2644 | my ($b_help,$b_recommends); |
4748 | 2324 | my ($b_exit,$errno) = (1,0); | 2645 | my ($b_exit,$errno) = (1,0); |
4749 | 2325 | my $message = do { | 2646 | my $message = do { |
4750 | 2326 | if ( $err eq 'empty' ) { 'empty value' } | 2647 | if ($err eq 'empty'){ 'empty value' } |
4751 | 2327 | ## Basic rules | 2648 | ## Basic rules |
4752 | 2328 | elsif ( $err eq 'not-in-irc' ) { | 2649 | elsif ($err eq 'not-in-irc'){ |
4753 | 2329 | $errno=1; "You can't run option $one in an IRC client!" } | 2650 | $errno=1; "You can't run option $one in an IRC client!" } |
4754 | 2330 | ## Internal/external options | 2651 | ## Internal/external options |
4755 | 2331 | elsif ( $err eq 'bad-arg' ) { | 2652 | elsif ($err eq 'bad-arg'){ |
4756 | 2332 | $errno=10; $b_help=1; "Unsupported value: $two for option: $one" } | 2653 | $errno=10; $b_help=1; "Unsupported value: $two for option: $one" } |
4757 | 2333 | elsif ( $err eq 'bad-arg-int' ) { | 2654 | elsif ($err eq 'bad-arg-int'){ |
4758 | 2334 | $errno=11; "Bad internal argument: $one" } | 2655 | $errno=11; "Bad internal argument: $one" } |
4759 | 2335 | elsif ( $err eq 'distro-block' ) { | 2656 | elsif ($err eq 'distro-block'){ |
4760 | 2336 | $errno=20; "Option: $one has been disabled by the $self_name distribution maintainer." } | 2657 | $errno=20; "Option: $one has been disabled by the $self_name distribution maintainer." } |
4761 | 2337 | elsif ( $err eq 'option-feature-incomplete' ) { | 2658 | elsif ($err eq 'option-feature-incomplete'){ |
4762 | 2338 | $errno=21; "Option: '$one' feature: '$two' has not been implemented yet." } | 2659 | $errno=21; "Option: '$one' feature: '$two' has not been implemented yet." } |
4763 | 2339 | elsif ( $err eq 'unknown-option' ) { | 2660 | elsif ($err eq 'unknown-option'){ |
4764 | 2340 | $errno=22; $b_help=1; "Unsupported option: $one" } | 2661 | $errno=22; $b_help=1; "Unsupported option: $one" } |
4765 | 2341 | ## Data | 2662 | ## Data |
4766 | 2342 | elsif ( $err eq 'open-data' ) { | 2663 | elsif ($err eq 'open-data'){ |
4767 | 2343 | $errno=32; "Error opening data for reading: $one \nError: $two" } | 2664 | $errno=32; "Error opening data for reading: $one \nError: $two" } |
4768 | 2344 | elsif ( $err eq 'download-error' ) { | 2665 | elsif ($err eq 'download-error'){ |
4769 | 2345 | $errno=33; "Error downloading file with $dl{'dl'}: $one \nError: $two" } | 2666 | $errno=33; "Error downloading file with $dl{'dl'}: $one \nError: $two" } |
4770 | 2346 | ## Files: | 2667 | ## Files: |
4771 | 2347 | elsif ( $err eq 'copy-failed' ) { | 2668 | elsif ($err eq 'copy-failed'){ |
4772 | 2348 | $errno=40; "Error copying file: $one \nError: $two" } | 2669 | $errno=40; "Error copying file: $one \nError: $two" } |
4773 | 2349 | elsif ( $err eq 'create' ) { | 2670 | elsif ($err eq 'create'){ |
4774 | 2350 | $errno=41; "Error creating file: $one \nError: $two" } | 2671 | $errno=41; "Error creating file: $one \nError: $two" } |
4775 | 2351 | elsif ( $err eq 'downloader-error' ) { | 2672 | elsif ($err eq 'downloader-error'){ |
4776 | 2352 | $errno=42; "Error downloading file: $one \nfor download source: $two" } | 2673 | $errno=42; "Error downloading file: $one \nfor download source: $two" } |
4777 | 2353 | elsif ( $err eq 'file-corrupt' ) { | 2674 | elsif ($err eq 'file-corrupt'){ |
4778 | 2354 | $errno=43; "Downloaded file is corrupted: $one" } | 2675 | $errno=43; "Downloaded file is corrupted: $one" } |
4779 | 2355 | elsif ( $err eq 'mkdir' ) { | 2676 | elsif ($err eq 'mkdir'){ |
4780 | 2356 | $errno=44; "Error creating directory: $one \nError: $two" } | 2677 | $errno=44; "Error creating directory: $one \nError: $two" } |
4781 | 2357 | elsif ( $err eq 'open' ) { | 2678 | elsif ($err eq 'open'){ |
4782 | 2358 | $errno=45; $b_exit=0; "Error opening file: $one \nError: $two" } | 2679 | $errno=45; $b_exit=0; "Error opening file: $one \nError: $two" } |
4783 | 2359 | elsif ( $err eq 'open-dir' ) { | 2680 | elsif ($err eq 'open-dir'){ |
4784 | 2360 | $errno=46; "Error opening directory: $one \nError: $two" } | 2681 | $errno=46; "Error opening directory: $one \nError: $two" } |
4785 | 2361 | elsif ( $err eq 'output-file-bad' ) { | 2682 | elsif ($err eq 'output-file-bad'){ |
4786 | 2362 | $errno=47; "Value for --output-file must be full path, a writable directory, \nand include file name. Path: $two" } | 2683 | $errno=47; "Value for --output-file must be full path, a writable directory, \nand include file name. Path: $two" } |
4787 | 2363 | elsif ( $err eq 'not-writable' ) { | 2684 | elsif ($err eq 'not-writable'){ |
4788 | 2364 | $errno=48; "The file: $one is not writable!" } | 2685 | $errno=48; "The file: $one is not writable!" } |
4789 | 2365 | elsif ( $err eq 'open-dir-failed' ) { | 2686 | elsif ($err eq 'open-dir-failed'){ |
4790 | 2366 | $errno=49; "The directory: $one failed to open with error: $two" } | 2687 | $errno=49; "The directory: $one failed to open with error: $two" } |
4791 | 2367 | elsif ( $err eq 'remove' ) { | 2688 | elsif ($err eq 'remove'){ |
4792 | 2368 | $errno=50; "Failed to remove file: $one Error: $two" } | 2689 | $errno=50; "Failed to remove file: $one Error: $two" } |
4793 | 2369 | elsif ( $err eq 'rename' ) { | 2690 | elsif ($err eq 'rename'){ |
4794 | 2370 | $errno=51; "There was an error moving files: $one\nError: $two" } | 2691 | $errno=51; "There was an error moving files: $one\nError: $two" } |
4795 | 2371 | elsif ( $err eq 'write' ) { | 2692 | elsif ($err eq 'write'){ |
4796 | 2372 | $errno=52; "Failed writing file: $one - Error: $two!" } | 2693 | $errno=52; "Failed writing file: $one - Error: $two!" } |
4797 | 2373 | ## Downloaders | 2694 | ## Downloaders |
4798 | 2374 | elsif ( $err eq 'missing-downloader' ) { | 2695 | elsif ($err eq 'missing-downloader'){ |
4799 | 2375 | $errno=60; "Downloader program $two could not be located on your system." } | 2696 | $errno=60; "Downloader program $two could not be located on your system." } |
4800 | 2376 | elsif ( $err eq 'missing-perl-downloader' ) { | 2697 | elsif ($err eq 'missing-perl-downloader'){ |
4801 | 2377 | $errno=61; $b_recommends=1; "Perl downloader missing required module." } | 2698 | $errno=61; $b_recommends=1; "Perl downloader missing required module." } |
4802 | 2378 | ## FTP | 2699 | ## FTP |
4803 | 2379 | elsif ( $err eq 'ftp-bad-path' ) { | 2700 | elsif ($err eq 'ftp-bad-path'){ |
4804 | 2380 | $errno=70; "Unable to locate for FTP upload file:\n$one" } | 2701 | $errno=70; "Unable to locate for FTP upload file:\n$one" } |
4805 | 2381 | elsif ( $err eq 'ftp-connect' ) { | 2702 | elsif ($err eq 'ftp-connect'){ |
4806 | 2382 | $errno=71; "There was an error with connection to ftp server: $one" } | 2703 | $errno=71; "There was an error with connection to ftp server: $one" } |
4807 | 2383 | elsif ( $err eq 'ftp-login' ) { | 2704 | elsif ($err eq 'ftp-login'){ |
4808 | 2384 | $errno=72; "There was an error with login to ftp server: $one" } | 2705 | $errno=72; "There was an error with login to ftp server: $one" } |
4809 | 2385 | elsif ( $err eq 'ftp-upload' ) { | 2706 | elsif ($err eq 'ftp-upload'){ |
4810 | 2386 | $errno=73; "There was an error with upload to ftp server: $one" } | 2707 | $errno=73; "There was an error with upload to ftp server: $one" } |
4811 | 2387 | ## Modules | 2708 | ## Modules |
4812 | 2388 | elsif ( $err eq 'required-module' ) { | 2709 | elsif ($err eq 'required-module'){ |
4813 | 2389 | $errno=80; $b_recommends=1; "The required $one Perl module is not installed:\n$two" } | 2710 | $errno=80; $b_recommends=1; "The required $one Perl module is not installed:\n$two" } |
4814 | 2390 | ## DEFAULT | 2711 | ## DEFAULT |
4815 | 2391 | else { | 2712 | else { |
4816 | 2392 | $errno=255; "Error handler ERROR!! Unsupported options: $err!"} | 2713 | $errno=255; "Error handler ERROR!! Unsupported options: $err!"} |
4817 | 2393 | }; | 2714 | }; |
4818 | 2394 | print_line("Error $errno: $message\n"); | 2715 | print_line("Error $errno: $message\n"); |
4819 | 2395 | if ($b_help){ | 2716 | if ($b_help){ |
4820 | 2396 | print_line("Check -h for correct parameters.\n"); | 2717 | print_line("Check -h for correct parameters.\n"); |
4821 | 2397 | } | 2718 | } |
4822 | 2398 | if ($b_recommends){ | 2719 | if ($b_recommends){ |
4823 | 2399 | print_line("See --recommends for more information.\n"); | 2720 | print_line("See --recommends for more information.\n"); |
4824 | 2400 | } | 2721 | } |
4825 | 2401 | eval $end if $b_log; | 2722 | eval $end if $b_log; |
4826 | 2402 | exit $errno if $b_exit && !$debugger{'no-exit'}; | 2723 | exit $errno if $b_exit && !$debugger{'no-exit'}; |
4827 | 2403 | } | 2724 | } |
4828 | 2404 | 2725 | ||
4829 | 2405 | sub error_defaults { | 2726 | sub error_defaults { |
4836 | 2406 | my ($type,$one) = @_; | 2727 | my ($type,$one) = @_; |
4837 | 2407 | $one ||= ''; | 2728 | $one ||= ''; |
4838 | 2408 | my %errors = ( | 2729 | my %errors = ( |
4839 | 2409 | 'download-error' => "Download Failure:\n$one\n", | 2730 | 'download-error' => "Download Failure:\n$one\n", |
4840 | 2410 | ); | 2731 | ); |
4841 | 2411 | return $errors{$type}; | 2732 | return $errors{$type}; |
4842 | 2412 | } | 2733 | } |
4843 | 2413 | 2734 | ||
4844 | 2414 | #### ------------------------------------------------------------------- | 2735 | #### ------------------------------------------------------------------- |
4845 | @@ -2418,615 +2739,756 @@ sub error_defaults { | |||
4846 | 2418 | ## CheckRecommends | 2739 | ## CheckRecommends |
4847 | 2419 | { | 2740 | { |
4848 | 2420 | package CheckRecommends; | 2741 | package CheckRecommends; |
4849 | 2742 | my (@modules); | ||
4850 | 2421 | sub run { | 2743 | sub run { |
4882 | 2422 | main::error_handler('not-in-irc', 'recommends') if $b_irc; | 2744 | main::error_handler('not-in-irc', 'recommends') if $b_irc; |
4883 | 2423 | my (@data,@rows); | 2745 | my (@data,@rows); |
4884 | 2424 | my $line = make_line(); | 2746 | my $line = make_line(); |
4885 | 2425 | my $pm = get_pm(); | 2747 | my $pm = get_pm(); |
4886 | 2426 | @data = basic_data($line); | 2748 | @data = basic_data($line,$pm); |
4887 | 2427 | push @rows,@data; | 2749 | push(@rows, @data); |
4888 | 2428 | if (!$bsd_type){ | 2750 | if (!$bsd_type){ |
4889 | 2429 | @data = check_items('required system directories',$line,$pm); | 2751 | @data = check_items('required system directories',$line,$pm); |
4890 | 2430 | push @rows,@data; | 2752 | push(@rows, @data); |
4891 | 2431 | } | 2753 | } |
4892 | 2432 | @data = check_items('recommended system programs',$line,$pm); | 2754 | @data = check_items('recommended system programs',$line,$pm); |
4893 | 2433 | push @rows,@data; | 2755 | push(@rows, @data); |
4894 | 2434 | @data = check_items('recommended display information programs',$line,$pm); | 2756 | @data = check_items('recommended display information programs',$line,$pm); |
4895 | 2435 | push @rows,@data; | 2757 | push(@rows, @data); |
4896 | 2436 | @data = check_items('recommended downloader programs',$line,$pm); | 2758 | @data = check_items('recommended downloader programs',$line,$pm); |
4897 | 2437 | push @rows,@data; | 2759 | push(@rows, @data); |
4898 | 2438 | @data = check_items('recommended Perl modules',$line,$pm); | 2760 | if (!$bsd_type){ |
4899 | 2439 | push @rows,@data; | 2761 | @data = check_items('recommended kernel modules',$line,$pm); |
4900 | 2440 | @data = check_items('recommended directories',$line,''); | 2762 | push(@rows, @data); |
4901 | 2441 | push @rows,@data; | 2763 | } |
4902 | 2442 | @data = check_items('recommended files',$line,''); | 2764 | @data = check_items('recommended Perl modules',$line,$pm); |
4903 | 2443 | push @rows,@data; | 2765 | push(@rows, @data); |
4904 | 2444 | @data = ( | 2766 | @data = check_items('recommended directories',$line,''); |
4905 | 2445 | ['0', '', '', "$line"], | 2767 | push(@rows, @data); |
4906 | 2446 | ['0', '', '', "Ok, all done with the checks. Have a nice day."], | 2768 | @data = check_items('recommended files',$line,''); |
4907 | 2447 | ['0', '', '', " "], | 2769 | push(@rows, @data); |
4908 | 2448 | ); | 2770 | @data = ( |
4909 | 2449 | push @rows,@data; | 2771 | ['0', '', '', "$line"], |
4910 | 2450 | #print Data::Dumper::Dumper \@rows; | 2772 | ['0', '', '', "Ok, all done with the checks. Have a nice day."], |
4911 | 2451 | main::print_basic(@rows); | 2773 | ['0', '', '', " "], |
4912 | 2452 | exit 0; # shell true | 2774 | ); |
4913 | 2775 | push(@rows, @data); | ||
4914 | 2776 | # print Data::Dumper::Dumper \@rows; | ||
4915 | 2777 | main::print_basic(\@rows); | ||
4916 | 2778 | exit 0; # shell true | ||
4917 | 2453 | } | 2779 | } |
4918 | 2454 | 2780 | ||
4919 | 2455 | sub basic_data { | 2781 | sub basic_data { |
4946 | 2456 | my ($line) = @_; | 2782 | my ($line,$pm_local) = @_; |
4947 | 2457 | my (@data,@rows); | 2783 | my (@data,@rows); |
4948 | 2458 | my $client = $client{'name-print'}; | 2784 | my $client = $client{'name-print'}; |
4949 | 2459 | $client .= ' ' . $client{'version'} if $client{'version'}; | 2785 | $pm_local ||= 'N/A'; |
4950 | 2460 | my $default_shell = 'N/A'; | 2786 | $client .= ' ' . $client{'version'} if $client{'version'}; |
4951 | 2461 | if ($ENV{'SHELL'}){ | 2787 | my $default_shell = 'N/A'; |
4952 | 2462 | $default_shell = $ENV{'SHELL'}; | 2788 | if ($ENV{'SHELL'}){ |
4953 | 2463 | $default_shell =~ s/.*\///; | 2789 | $default_shell = $ENV{'SHELL'}; |
4954 | 2464 | } | 2790 | $default_shell =~ s/.*\///; |
4955 | 2465 | my $sh = main::check_program('sh'); | 2791 | } |
4956 | 2466 | my $sh_real = Cwd::abs_path($sh); | 2792 | my $sh = main::check_program('sh'); |
4957 | 2467 | @rows = ( | 2793 | my $sh_real = Cwd::abs_path($sh); |
4958 | 2468 | ['0', '', '', "$self_name will now begin checking for the programs it needs | 2794 | @rows = ( |
4959 | 2469 | to operate."], | 2795 | ['0', '', '', "$self_name will now begin checking for the programs it needs |
4960 | 2470 | ['0', '', '', "" ], | 2796 | to operate."], |
4961 | 2471 | ['0', '', '', "Check $self_name --help or the man page (man $self_name) | 2797 | ['0', '', '', "" ], |
4962 | 2472 | to see what options are available." ], | 2798 | ['0', '', '', "Check $self_name --help or the man page (man $self_name) |
4963 | 2473 | ['0', '', '', "$line" ], | 2799 | to see what options are available." ], |
4964 | 2474 | ['0', '', '', "Test: core tools:" ], | 2800 | ['0', '', '', "$line" ], |
4965 | 2475 | ['0', '', '', "" ], | 2801 | ['0', '', '', "Test: core tools:" ], |
4966 | 2476 | ['0', '', '', "Perl version: ^$]" ], | 2802 | ['0', '', '', "" ], |
4967 | 2477 | ['0', '', '', "Current shell: " . $client ], | 2803 | ['0', '', '', "Perl version: ^$]" ], |
4968 | 2478 | ['0', '', '', "Default shell: " . $default_shell ], | 2804 | ['0', '', '', "Current shell: " . $client ], |
4969 | 2479 | ['0', '', '', "sh links to: $sh_real" ], | 2805 | ['0', '', '', "Default shell: " . $default_shell ], |
4970 | 2480 | ); | 2806 | ['0', '', '', "sh links to: $sh_real" ], |
4971 | 2481 | return @rows; | 2807 | ['0', '', '', "Package manager: $pm_local" ], |
4972 | 2808 | ); | ||
4973 | 2809 | return @rows; | ||
4974 | 2482 | } | 2810 | } |
4975 | 2483 | sub check_items { | 2811 | sub check_items { |
4976 | 2484 | my ($type,$line,$pm) = @_; | ||
4977 | 2485 | my (@data,%info,@missing,$row,@rows,$result,@unreadable); | ||
4978 | 2486 | my ($b_dir,$b_file,$b_module,$b_program,$item); | ||
4979 | 2487 | my ($about,$extra,$extra2,$extra3,$extra4,$info_os,$install) = ('','','','','','info',''); | ||
4980 | 2488 | if ($type eq 'required system directories'){ | ||
4981 | 2489 | @data = qw(/proc /sys); | ||
4982 | 2490 | $b_dir = 1; | ||
4983 | 2491 | $item = 'Directory'; | ||
4984 | 2492 | } | ||
4985 | 2493 | elsif ($type eq 'recommended system programs'){ | ||
4986 | 2494 | if ($bsd_type){ | ||
4987 | 2495 | @data = qw(camcontrol dig dmidecode fdisk file glabel gpart ifconfig ipmi-sensors | ||
4988 | 2496 | ipmitool lsusb sudo smartctl sysctl tree upower uptime usbdevs); | ||
4989 | 2497 | $info_os = 'info-bsd'; | ||
4990 | 2498 | } | ||
4991 | 2499 | else { | ||
4992 | 2500 | @data = qw(blockdev dig dmidecode fdisk file hddtemp ifconfig ip ipmitool | ||
4993 | 2501 | ipmi-sensors lsblk lsusb modinfo runlevel sensors strings sudo tree upower uptime); | ||
4994 | 2502 | } | ||
4995 | 2503 | $b_program = 1; | ||
4996 | 2504 | $item = 'Program'; | ||
4997 | 2505 | $extra2 = "Note: IPMI sensors are generally only found on servers. To access | ||
4998 | 2506 | that data, you only need one of the ipmi items."; | ||
4999 | 2507 | } | ||
5000 | 2508 | elsif ($type eq 'recommended display information programs'){ |
The diff has been truncated for viewing.
+1