Class: Roebe::SystemChecker
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/system_checker.rb
Overview
Constant Summary
collapse
- DEFAULT_PADDING =
#
Determine the default padding first.
#
DP = ' '
- SP =
The default padding to use. Use this consistently.
:superpadding
- GENERIC_PADDING_TO_USE =
special padding. every line will be padded.
N+DP
- ARROW =
newline, and default padding.
DP+'=> '
- SHOW_KERNEL_MODULES =
false
- COLOUR_CLINER =
'lightgreen'
'redb'
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
Class Method Summary
collapse
-
.[](i = '') ⇒ Object
# === [] ========================================================================= #.
Instance Method Summary
collapse
-
#cliner ⇒ Object
# === cliner ========================================================================= #.
-
#display(content = '', padding_to_use = '', use_newline = true, colour_to_use = 'teal') ⇒ Object
(also: #d)
# === display (display tag).
-
#fetch_and_report_user_name ⇒ Object
# === fetch_and_report_user_name ========================================================================= #.
-
#fetch_bios_information ⇒ Object
-
#fetch_boot_commandline ⇒ Object
# === fetch_boot_commandline ========================================================================= #.
-
#fetch_compile_information ⇒ Object
-
#fetch_cpu_info ⇒ Object
# === fetch_cpu_info.
-
#fetch_hdd_information ⇒ Object
-
#fetch_host_name ⇒ Object
# === fetch_host_name ========================================================================= #.
-
#fetch_host_operating_system ⇒ Object
(also: #determine_the_host_platform)
# === fetch_host_operating_system.
-
#fetch_info_about_mounted_filesystems ⇒ Object
# === fetch_info_about_mounted_filesystems ========================================================================= #.
-
#fetch_ip_information ⇒ Object
-
#fetch_kernel_modules ⇒ Object
# === fetch_kernel_modules ========================================================================= #.
-
#fetch_kernel_version ⇒ Object
# === fetch_kernel_version.
-
#fetch_memory_info ⇒ Object
# === fetch_memory_info (ram tag).
-
#fetch_pci_information ⇒ Object
-
#fetch_terminal_settings ⇒ Object
# === fetch_terminal_settings ========================================================================= #.
-
#fetch_usb_information ⇒ Object
-
#fetch_user_name ⇒ Object
# === fetch_user_name.
-
#filtered_cmesystem(content, use_cliner = false, padding = '', use_newline = true) ⇒ Object
# === filtered_cmesystem.
-
#header(i, colour_to_use = COLOUR_CLINER, use_leading_hash_mark = true) ⇒ Object
-
#initialize(i = nil, run_already = true) ⇒ SystemChecker
constructor
# === initialize.
-
#input? ⇒ Boolean
-
#prepare_environment_information ⇒ Object
-
#program_exists?(this_program) ⇒ Boolean
# === program_exists?.
-
#read_file(this_file) ⇒ Object
# === read_file ========================================================================= #.
-
#report_user_name ⇒ Object
# === report_user_name ========================================================================= #.
-
#report_vendor ⇒ Object
# === report_vendor ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#result? ⇒ Boolean
# === result? ========================================================================= #.
-
#return_path ⇒ Object
# === return_path.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_input(i = '') ⇒ Object
-
#verbose_english(n_hdds, absolute_position = false) ⇒ Object
# === verbose_english.
-
#yellow ⇒ Object
# === yellow ========================================================================= #.
Methods inherited from Base
#append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into
#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments
Constructor Details
#initialize(i = nil, run_already = true) ⇒ SystemChecker
#
initialize
are available.
#
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/roebe/classes/system_checker.rb', line 60
def initialize(
i = nil,
run_already = true
)
reset
set_input(i)
cliner
'Checking your complete system next.',COLOUR_IMPORTANT_HEADER
cliner
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
473
474
475
|
# File 'lib/roebe/classes/system_checker.rb', line 473
def self.[](i = '')
self.new(i)
end
|
Instance Method Details
102
103
104
|
# File 'lib/roebe/classes/system_checker.rb', line 102
def cliner
e '=' * 80
end
|
#display(content = '', padding_to_use = '', use_newline = true, colour_to_use = 'teal') ⇒ Object
Also known as:
d
#
display (display tag)
Use this to “display” information to your user in a fancy fashion.
Right now we support:
- padding
- Use newline or not.
- colour_to_use
This method will NOT include cliner!
#
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/roebe/classes/system_checker.rb', line 247
def display(
content = '',
padding_to_use = '',
use_newline = true,
colour_to_use = 'teal'
)
if padding_to_use.is_a? Float padding_to_use = ' ' * padding_to_use.to_i
end
content = content.to_s
_ = padding_to_use+content
if content.start_with? '#'
_ = '#'+padding_to_use[0..-2]+content[1..-1]
end
e _
end
|
#fetch_and_report_user_name ⇒ Object
#
fetch_and_report_user_name
#
218
219
220
221
|
# File 'lib/roebe/classes/system_checker.rb', line 218
def fetch_and_report_user_name
fetch_user_name
report_user_name
end
|
#
This requires one to have dmidecode. We will only fetch relevant info though.
#
345
346
347
348
349
350
351
352
353
354
355
356
|
# File 'lib/roebe/classes/system_checker.rb', line 345
def fetch_bios_information
if program_exists? 'dmidecode'
@result = `dmidecode`.chomp
@result.split(N).each {|line|
@bios_vendor = line.split(':').last.strip if line.include? 'Vendor:'
@bios_release_date = line.split(':').last.strip if line.include? 'Release Date:'
}
else
ewarn ARROW+'dmidecode could not be found. Make sure '\
'that you have installed it.'+N
end
end
|
#fetch_boot_commandline ⇒ Object
#
fetch_boot_commandline
#
417
418
419
420
|
# File 'lib/roebe/classes/system_checker.rb', line 417
def fetch_boot_commandline
d 'Computer was booted with these paramaters:'
filtered_cmesystem 'cat /proc/cmdline',false,DP
end
|
#
This method will tap into class EnvironmentInformation.
#
493
494
495
496
497
498
499
|
# File 'lib/roebe/classes/system_checker.rb', line 493
def fetch_compile_information
e
cliner
'Displaying Compile Information now:'
cliner
@environment_information.feedback end
|
#fetch_cpu_info ⇒ Object
#
fetch_cpu_info
n_cores denotes how many CPU cores we have found.
#
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
# File 'lib/roebe/classes/system_checker.rb', line 427
def fetch_cpu_info
cliner
'CPU Information:'
cliner
result = `cat /proc/cpuinfo`
_ = '' n_cores = 1
splitted = result.split(N)
begin
n_cores = result.scan(/cpu cores(.+)$/).flatten[0][-1,1].to_i
_ << DP+'You have '+n_cores.to_s+' CPU cores.'+N
rescue; end
counter = 0
splitted.each { |line|
if ! _.include? 'Your model name'
_ << DP+'Your model name seems to be '+
line.split(':').last.strip+'.'+N if line.include? 'model name'
end
if line =~ /^cpu MHz/
if n_cores > 1
counter += 1
_ << DP+'CPU'+counter.to_s+' Mhz: '+line.split(':').last.strip+'.'+N
else
_ << DP+'CPU Mhz: '+line.split(':').last.strip+'.'+N
end
end
}
d _
end
|
#
Gives back info about all the HDD found. The display will be something like:
'You have two Harddiscs'
#
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
# File 'lib/roebe/classes/system_checker.rb', line 527
def fetch_hdd_information
@result = `fdisk -l`
n_hdds = 0
@result.split(N).each {|line|
if line.include? 'Disk' and line.include? 'GB'
n_hdds += 1
split = line.split(':')
@array_hdds << [
split[0].split(' ').last, split[1].split(',').first.strip
]
end
}
n
cliner
d DP+'You have '+verbose_english(n_hdds).to_s+' Harddiscs:'
@array_hdds.each_with_index { |hdd, index|
d DP+' Your '+'%6s' % verbose_english(index+1, true)+' harddisc is'+
' situated at '+sfancy(hdd[0])+' and has '+
yellow+('%8s' % hdd[1])+rev+'.'
}
cliner
e
end
|
#fetch_host_name ⇒ Object
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/roebe/classes/system_checker.rb', line 328
def fetch_host_name
name_of_the_computer = read_file('/etc/hostname')
if name_of_the_computer
d 'The name of this computer is:'
@computer_name = name_of_the_computer
d @computer_name, 2
else
e 'Could not determine the name of the computer.'
end
end
|
#fetch_host_operating_system ⇒ Object
Also known as:
determine_the_host_platform
#
fetch_host_operating_system
Will display i.e. Linux or windows etc..
#
199
200
201
202
203
|
# File 'lib/roebe/classes/system_checker.rb', line 199
def fetch_host_operating_system
@platform = RUBY_PLATFORM.to_s.downcase e N+ARROW+'Operating System: You are on '+orange(@platform)+'.'+N e ARROW+'Your Windows System is: '+`ver` if @platform == 'windows'
end
|
#fetch_info_about_mounted_filesystems ⇒ Object
#
fetch_info_about_mounted_filesystems
#
388
389
390
391
|
# File 'lib/roebe/classes/system_checker.rb', line 388
def fetch_info_about_mounted_filesystems
d 'Information about the filesystem:'
filtered_cmesystem 'df -h', false,SP
end
|
513
514
515
516
517
518
|
# File 'lib/roebe/classes/system_checker.rb', line 513
def fetch_ip_information
cliner
d 'Ip Information:',DP,false
filtered_cmesystem 'hostname -i',false,DP,true
cliner
end
|
#fetch_kernel_modules ⇒ Object
280
281
282
283
284
285
|
# File 'lib/roebe/classes/system_checker.rb', line 280
def fetch_kernel_modules
d 'Fetching available kernel modules:'
cliner
filtered_cmesystem 'lsmod', DP
cliner
end
|
#fetch_kernel_version ⇒ Object
#
fetch_kernel_version
This will fetch the kernel version using uname -a
#
462
463
464
465
466
467
468
|
# File 'lib/roebe/classes/system_checker.rb', line 462
def fetch_kernel_version
cliner
'You are using this kernel:'
cliner
filtered_cmesystem 'uname -a',false,DP
e
end
|
#fetch_memory_info ⇒ Object
#
fetch_memory_info (ram tag)
Memory information about the computer.
#
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/roebe/classes/system_checker.rb', line 299
def fetch_memory_info
result = `free`
cliner
'RAM'
cliner
result.split(N).each { |line|
if line.include? 'Mem:'
@n_ram = line.split(' ')[1]
d ' You have '+@n_ram+' RAM'
end
}
end
|
270
271
272
273
274
275
|
# File 'lib/roebe/classes/system_checker.rb', line 270
def fetch_pci_information
cliner
'Getting information about PCI devices:'
cliner
filtered_cmesystem 'lspci', false,SP
end
|
#fetch_terminal_settings ⇒ Object
#
fetch_terminal_settings
#
396
397
398
399
400
401
|
# File 'lib/roebe/classes/system_checker.rb', line 396
def fetch_terminal_settings
cliner
d 'Your '+orange('terminal settings')+' are:'
filtered_cmesystem('stty -a', false, DP) { :first_line_only }
cliner
end
|
504
505
506
507
508
|
# File 'lib/roebe/classes/system_checker.rb', line 504
def fetch_usb_information
cliner
'Getting information about USB:'
filtered_cmesystem 'lsusb',true,SP
end
|
#fetch_user_name ⇒ Object
#
fetch_user_name
Fetch user name and some more stuff like uid.
#
210
211
212
213
|
# File 'lib/roebe/classes/system_checker.rb', line 210
def fetch_user_name
@user_name = Etc.getlogin
@uid = Etc.getpwnam(@user_name).uid
end
|
#filtered_cmesystem(content, use_cliner = false, padding = '', use_newline = true) ⇒ Object
#
filtered_cmesystem
This method will always output the content given to it. SP as argument to padding is equal to passing it :superpadding Please note, the name “filtered_cmesystem” was chosen because in some situations we want to filter out messages.
#
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/roebe/classes/system_checker.rb', line 114
def filtered_cmesystem(
content,
use_cliner = false,
padding = '',
use_newline = true
)
if block_given?
case yield
when :first_line_only @result = `#{content}`.split(N)[0]
end
else
@result = `#{content}`
end
@result = @result.strip
if padding == :superpadding
@result = DEFAULT_PADDING+@result.gsub(/\n/, GENERIC_PADDING_TO_USE)
padding = '' end
if @result.include? 'Unknown device' warn 'Warning: Unknown Device, maybe PCI Table is not known.'
else if @result.include? 'Advanced Micro Devices, Inc.'
use_this_regex = /(Advanced Micro Devices, Inc\.)/
@result.gsub!(use_this_regex, slateblue('\\1'))
end
if use_cliner
cliner
e padding+@result, use_newline
cliner
else
e padding+result?
end
end
end
|
#
If we wish to make a header, this is the way to go.
#
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/roebe/classes/system_checker.rb', line 167
def (
i,
colour_to_use = COLOUR_CLINER,
use_leading_hash_mark = true
)
if use_leading_hash_mark
i.prepend '#'
end
display(i, DP, false, colour_to_use)
end
|
190
191
192
|
# File 'lib/roebe/classes/system_checker.rb', line 190
def input?
@input
end
|
406
407
408
409
410
411
412
|
# File 'lib/roebe/classes/system_checker.rb', line 406
def prepare_environment_information
@environment_information = EnvironmentInformation.new(:dont_run_yet) unless @use_colours
@environment_information.disable_colours
end
end
|
#program_exists?(this_program) ⇒ Boolean
#
program_exists?
Use this method to find out if a program exists or is installed, or available, on our given host. (found?, program exists tag, is_installed?) For this to work we search through the allowed $PATH listings. (Master copy in diamond_shell.rb
Usage Example:
program_exists? 'gimp'
#
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
# File 'lib/roebe/classes/system_checker.rb', line 369
def program_exists?(this_program)
this_program = this_program.dup does_program_exist = false array_available_paths = return_path
if array_available_paths.is_a? Array
array_available_paths.map!(&:strip)
else array_available_paths = array_available_paths.split(' ')
end
array_available_paths.each { |path|
does_program_exist = true if File.exist? path+'/'+this_program
}
return does_program_exist
end
|
#read_file(this_file) ⇒ Object
316
317
318
319
320
321
322
323
|
# File 'lib/roebe/classes/system_checker.rb', line 316
def read_file(this_file)
if File.exist? this_file
File.new(this_file).readlines.to_s
else
ewarn 'File '+sfile(this_file)+swarn(' does not exist, thus '\
'can not read it.')
end
end
|
#report_user_name ⇒ Object
226
227
228
229
230
231
232
|
# File 'lib/roebe/classes/system_checker.rb', line 226
def report_user_name
d 'Your user name is:'
d @user_name, 2
d 'Your user id is:'
d @uid.to_s, 2
d 'This means you are the privileged SuperUser.' if @uid == 0
end
|
#report_vendor ⇒ Object
587
588
589
|
# File 'lib/roebe/classes/system_checker.rb', line 587
def report_vendor
e sfancy(@bios_vendor)
end
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/roebe/classes/system_checker.rb', line 75
def reset
super()
infer_the_namespace
@use_colours = true
@max_ram = nil
@array_hdds = [] @array_available_harddiscs = []
@bios_vendor = nil
prepare_environment_information
end
|
#result? ⇒ Boolean
158
159
160
|
# File 'lib/roebe/classes/system_checker.rb', line 158
def result?
@result
end
|
#return_path ⇒ Object
#
return_path
This method will return the path of your system.
#
482
483
484
485
486
|
# File 'lib/roebe/classes/system_checker.rb', line 482
def return_path
_ = "#{ENV['LINUX']}/YAML/path_variable.yml"
data = YAML.load_file(_) if File.exist? _
return data
end
|
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
# File 'lib/roebe/classes/system_checker.rb', line 594
def run
prepare_environment_information
fetch_host_operating_system
case @platform
when /linux/
fetch_pci_information
fetch_bios_information
report_vendor
fetch_host_name
fetch_terminal_settings
fetch_and_report_user_name
fetch_kernel_modules
fetch_compile_information
fetch_ip_information
fetch_usb_information
fetch_kernel_version
fetch_cpu_info
fetch_hdd_information
fetch_boot_commandline
fetch_memory_info
fetch_hdd_information
fetch_kernel_version
fetch_bios_information fetch_cpu_info
fetch_memory_info
fetch_ip_information
fetch_compile_information
end
end
|
181
182
183
184
185
|
# File 'lib/roebe/classes/system_checker.rb', line 181
def set_input(i = '')
i = i.first if i.is_a? Array
i = i.to_s.dup
@input = i
end
|
#verbose_english(n_hdds, absolute_position = false) ⇒ Object
#
verbose_english
Simple method that converts ‘1’ into ‘one’.
#
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
|
# File 'lib/roebe/classes/system_checker.rb', line 556
def verbose_english(n_hdds, absolute_position = false)
if absolute_position
case n_hdds.to_i
when 1 then 'first'
when 2 then 'second'
when 3 then 'third'
when 4 then 'fourth'
when 5 then 'fifth'
when 6 then 'sixth'
when 7 then 'seventh'
when 8 then 'eight'
when 9 then 'ninth'
end
else
case n_hdds.to_i
when 1 then 'one'
when 2 then 'two'
when 3 then 'three'
when 4 then 'four'
when 5 then 'five'
when 6 then 'six'
when 7 then 'seven'
when 8 then 'eight'
when 9 then 'nine'
end
end
end
|
290
291
292
|
# File 'lib/roebe/classes/system_checker.rb', line 290
def yellow
Colours::YELLOW
end
|