Almost done!

This commit is contained in:
VetheonGames 2023-09-22 14:10:28 -06:00
parent 2f72d0a133
commit 96638a1e7d
21 changed files with 229 additions and 19 deletions

0
Gemfile Normal file → Executable file
View File

4
Gemfile.lock Normal file → Executable file
View File

@ -1,12 +1,14 @@
GEM
remote: https://rubygems.org/
specs:
byebug (11.1.3)
curb (1.0.5)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.15.5)
pastel (0.8.0)
tty-color (~> 0.5)
rdebug (0.1)
rexml (3.2.6)
speedtest_net (0.9.2)
curb (>= 0.9, < 2.0)
@ -30,6 +32,8 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
byebug (~> 11.1)
rdebug (~> 0.1)
speedtest_net (~> 0.9.2)
tty-prompt (~> 0.23.1)

0
LICENSE Normal file → Executable file
View File

36
README.md Normal file → Executable file
View File

@ -1,3 +1,35 @@
# arch-info
# System Information Gatherer
A Ruby program for giving info about your Arch Linux system!
## Overview
This project is a Ruby-based system information gatherer designed to collect various types of system metrics and details. It is built to run on Linux systems and aims to provide a comprehensive view of the system's hardware and software configurations.
## Features
- Gather CPU Information
- Collect Disk Information
- Retrieve RAM Details
- Fetch Network Information
- And more...
## Requirements
- Ruby >= 3.0
- Linux-based Operating System
- Sudo permissions for certain metrics
## Installation
### Coming Soon
## Usage
### Coming Soon
## Contributing
Contributions are NOT welcome! Pull Requests will not be merged!
## License
This project is licensed under the PixelRidge-BEGPULSE License. See the `LICENSE` file for details.

10
bin/runtime_log.log Normal file
View File

@ -0,0 +1,10 @@
Starting system info gathering... \n
Gathering CPU info \n
Gathering RAM info \n
Gathering Disk info \n
Gathering GPU info \n
Gathering Kernel info \n
Gathering Network info \n
Gathering NIC info \n
Gathering OS info \n
Gathering Uptime info \n

36
bin/system_info.log Normal file
View File

@ -0,0 +1,36 @@
{
"cpu": {
"model": "Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz",
"speed": "3.36 GHz",
"cores": 4,
"threads": 4
},
"ram": {
"total_ram": 23,
"used_ram": 4,
"ram_type": "None",
"ram_speed": "2133 MT/s"
},
"disks": [
{
"model": "SAMSUNG MZ7PD256",
"type": "SSD",
"transport": "ata"
},
{
"model": "ST2000DM006-2DM1",
"type": "HDD",
"transport": "ata"
},
{
"model": "Timetec 30TT253X",
"type": "SSD",
"transport": "ata"
}
],
"gpu": {
"model": "NVIDIA Corporation GP106 [GeForce GTX 1060 6GB] (rev a1)",
"opengl_driver_version": "4.6.0 NVIDIA 535.104.05",
"vulkan_driver_version": "1.3.264"
}
}

6
bin/systeminfo Normal file → Executable file
View File

@ -1,14 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../lib/config_handler'
require_relative '../lib/first_run'
require_relative '../lib/commands'
# Check for config file and create if not exists
config_path = './config/systeminfo_config.yml'
ConfigHandler.ensure_config_exists(config_path)
config_path = '../config/systeminfo_config.yml'
# Load config
FirstRun.setup(config_path) unless ConfigHandler.config_valid?(config_path)
config = ConfigHandler.load_config(config_path)
# Handle command-line arguments

View File

@ -0,0 +1,26 @@
---
cpu: true
ram: true
gpu: true
nic_model: true
network_speed: true
os_name: true
kernel_name_version: true
system_uptime: true
disks: true
display_resolution: true
theme: true
desktop_environment: true
window_manager: true
terminal: true
shell: true
hostname: true
board_model: true
chipset: true
amount_of_monitors: true
sound_drivers: true
sound_card: true
display_technology: true
color_bit_depth: true
package_managers: true
file_systems: true

26
lib/commands.rb Normal file → Executable file
View File

@ -7,8 +7,8 @@ require_relative 'network_info'
require_relative 'nic_info'
require_relative 'os_info'
require_relative 'uptime_info'
require_relative 'config_handler' # Add this line to require the ConfigHandler class
# ... other requires
require_relative 'display_handler' # Add this line to require the DisplayHandler class
require_relative 'config_handler' # Add this line to require the ConfigHandler class
module Commands
def self.handle(args, config)
@ -27,9 +27,25 @@ module Commands
system_info = {}
# Run the system info display
system_info[:cpu] = CpuInfo.new.gather_info if config['cpu']
system_info[:ram] = RamInfo.new.gather_info if config['ram']
# ... other info gathering
File.open('runtime_log.log', 'w') { |f| f.puts('Starting system info gathering... \n') }
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering CPU info \n') }
system_info[:cpu] = CpuInfo.gather_info if config['cpu']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering RAM info \n') }
system_info[:ram] = RamInfo.gather_info if config['ram']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Disk info \n') }
system_info[:disks] = DiskInfo.gather_info if config['disks']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering GPU info \n') }
system_info[:gpu] = GpuInfo.gather_info if config['gpu']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Kernel info \n') }
system_info[:kernel] = KernelInfo.gather_info if config['kernel']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Network info \n') }
system_info[:network] = NetworkInfo.gather_info if config['network']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering NIC info \n') }
system_info[:nic] = NicInfo.gather_info if config['nic']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering OS info \n') }
system_info[:os] = OsInfo.gather_info if config['os']
File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Uptime info \n') }
system_info[:uptime] = UptimeInfo.gather_info if config['uptime']
# Pass the collected data to a display handler
DisplayHandler.display(system_info)

0
lib/config_handler.rb Normal file → Executable file
View File

2
lib/cpu_info.rb Normal file → Executable file
View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
class CpuInfo
def gather_info
def self.gather_info
cpu_info = {}
cores = 0
threads = 0

25
lib/disk_info.rb Normal file → Executable file
View File

@ -1,4 +1,4 @@
require 'json'
# frozen_string_literal: true
class DiskInfo
def self.gather_info
@ -7,13 +7,28 @@ class DiskInfo
# Get additional disk details using `lsblk` command
lsblk_output = `lsblk -J`.strip
lsblk_json = JSON.parse(lsblk_output)
lsblk_json['blockdevices'].each do |device|
next unless device['type'] == 'disk' # We only want disk devices
next unless device['type'] == 'disk' # We only want disk devices
# Skip swap partitions
next if device['mountpoints']&.include?('[SWAP]')
# Determine if the disk is SSD or HDD
rotational_info = File.read("/sys/block/#{device['name']}/queue/rotational").strip
type = rotational_info == '1' ? 'HDD' : 'SSD'
# Get transport type using udevadm
transport = `udevadm info --query=property --name=#{device['name']} | grep ID_BUS | cut -d= -f2`.strip
# Get disk model from /sys filesystem
model_path = "/sys/block/#{device['name']}/device/model"
model = File.exist?(model_path) ? File.read(model_path).strip : 'Unknown'
disk = {
model: device['model'],
type: device['rota'] == '1' ? 'HDD' : 'SSD',
transport: device['tran']
model:,
type:,
transport: transport || 'Unknown'
}
disk_info << disk
end

64
lib/display_handler.rb Executable file
View File

@ -0,0 +1,64 @@
# frozen_string_literal: true
require 'tty-prompt'
require 'json'
class DisplayHandler
def self.display(system_info)
# Log the entire system_info to a log file
File.open('system_info.log', 'w') do |f|
f.puts(JSON.pretty_generate(system_info))
end
prompt = TTY::Prompt.new
choices = [
{ name: 'OS Info', value: :os },
{ name: 'Hardware Info', value: :hardware },
{ name: 'Network Info', value: :network },
{ name: 'Exit', value: :exit }
]
loop do
user_choice = prompt.select('Choose an option:', choices)
case user_choice
when :os
display_os_info(system_info.slice(:kernel, :os, :uptime))
when :hardware
display_hardware_info(system_info.slice(:cpu, :ram, :disk, :gpu))
when :network
display_network_info(system_info.slice(:network, :nic))
when :exit
break
end
end
end
def self.display_os_info(os_info)
# Display OS information
puts "\nOS Information:"
puts '---------------'
os_info.each do |key, value|
puts "#{key.capitalize}: #{value}"
end
end
def self.display_hardware_info(hardware_info)
# Display Hardware information (CPU, RAM, etc.)
puts "\nHardware Information:"
puts '---------------------'
hardware_info.each do |key, value|
puts "#{key.capitalize}: #{value}"
end
end
def self.display_network_info(network_info)
# Display Network information
puts "\nNetwork Information:"
puts '--------------------'
network_info.each do |key, value|
puts "#{key.capitalize}: #{value}"
end
end
end

2
lib/first_run.rb Normal file → Executable file
View File

@ -39,7 +39,7 @@ class FirstRun
'file_systems' => prompt.yes?('Do you want to display which file systems the drives are using?')
}
File.write(config_path, config.to_yaml)
File.puts(config_path, config.to_yaml)
puts 'Configuration saved!'
end
end

0
lib/gpu_info.rb Normal file → Executable file
View File

1
lib/kernel_info.rb Normal file → Executable file
View File

@ -10,6 +10,7 @@ class KernelInfo
kernel_info[:version] = uname_output if uname_output && !uname_output.empty?
# Return the gathered kernel information
File.open('kernel_info.log', 'w') { |f| f.puts(kernel_info.to_json) }
kernel_info
end
end

5
lib/network_info.rb Normal file → Executable file
View File

@ -5,9 +5,12 @@ require 'speedtest_net'
class NetworkInfo
def self.gather_info
result = SpeedtestNet.run
{
network_info = {
download_speed: result.pretty_download,
upload_speed: result.pretty_upload
}
File.open('./runtime_log.log', 'w') { |f| f.puts(network_info.to_json) }
network_info
end
end

1
lib/nic_info.rb Normal file → Executable file
View File

@ -26,6 +26,7 @@ class NicInfo
nic_info << info
end
File.open('./runtime_log.log', 'w') { |f| f.puts(nic_info.to_json) }
nic_info
rescue JSON::ParserError
[{ model: 'No permission', manufacturer: 'No permission', max_speed: 'No permission' }]

1
lib/os_info.rb Normal file → Executable file
View File

@ -31,6 +31,7 @@ class OsInfo
end
os_info[:sound_driver] = sound_driver
File.open('./runtime_log.log', 'w') { |f| f.puts(os_info.to_json) }
os_info
end
end

2
lib/ram_info.rb Normal file → Executable file
View File

@ -12,7 +12,7 @@ class RamInfo
# Get RAM type and speed
begin
dmi_data = `sudo dmidecode -t memory`.split("\n").select { |line| line =~ /Type:|Speed:/ }
dmi_data = `sudo dmidecode --type 17`.split("\n")
ram_info[:ram_type] = dmi_data.select { |line| line =~ /Type:/ }.first.split(':').last.strip
ram_info[:ram_speed] = dmi_data.select { |line| line =~ /Speed:/ }.first.split(':').last.strip
rescue StandardError

1
lib/uptime_info.rb Normal file → Executable file
View File

@ -23,6 +23,7 @@ class UptimeInfo
uptime_info[:seconds] = seconds if seconds.positive?
# Format the uptime string
File.open('./runtime_log.log', 'w') { |f| f.puts(uptime_info.to_json) }
formatted_uptime = uptime_info.map { |k, v| "#{v} #{k.to_s.capitalize}" }.join(' : ')
{ uptime: formatted_uptime }