2025-08-11 14:18:59 +02:00
|
|
|
require_relative('system/architecture')
|
2025-08-01 12:52:57 +02:00
|
|
|
|
|
|
|
|
module System
|
2025-08-11 14:18:59 +02:00
|
|
|
|
2025-08-01 12:52:57 +02:00
|
|
|
def self.detect_os
|
|
|
|
|
case RUBY_PLATFORM
|
|
|
|
|
when /darwin/
|
|
|
|
|
:macos
|
|
|
|
|
when /linux/
|
|
|
|
|
if File.exist?('/etc/debian_version')
|
|
|
|
|
:debian
|
|
|
|
|
else
|
|
|
|
|
:linux_other
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
:unknown
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
OS = detect_os
|
|
|
|
|
|
|
|
|
|
case OS
|
|
|
|
|
|
|
|
|
|
when :macos
|
|
|
|
|
require_relative './system/macos'
|
|
|
|
|
extend MacOSSystem
|
|
|
|
|
when :debian
|
|
|
|
|
require_relative './system/debian'
|
|
|
|
|
extend DebianSystem
|
|
|
|
|
else
|
|
|
|
|
raise "Operating system not supported"
|
|
|
|
|
end
|
|
|
|
|
|
2025-08-11 14:18:59 +02:00
|
|
|
ARCH = normalize_architecture_string(arch)
|
|
|
|
|
|
2025-08-01 12:52:57 +02:00
|
|
|
def self.os_info
|
|
|
|
|
puts os_name
|
|
|
|
|
end
|
2025-08-11 14:18:59 +02:00
|
|
|
|
2025-08-26 17:50:38 +02:00
|
|
|
def self.qemu_paths
|
|
|
|
|
{
|
|
|
|
|
code_fd: qemu_code_fd_path,
|
|
|
|
|
vars_fd: qemu_vars_fd_path
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2025-08-11 14:18:59 +02:00
|
|
|
def self.arch_to_symbol(arch)
|
|
|
|
|
normalize_architecture_string(arch)
|
|
|
|
|
end
|
2025-08-28 17:48:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def self.exec_ssh(port)
|
|
|
|
|
require "socket"
|
|
|
|
|
|
|
|
|
|
host = "localhost"
|
|
|
|
|
cmd = "ssh -p #{port} user@#{host}"
|
|
|
|
|
|
|
|
|
|
# Wait until the port is open
|
|
|
|
|
puts "Waiting for #{host}:#{port}..."
|
|
|
|
|
until begin
|
|
|
|
|
TCPSocket.new(host, port).close
|
|
|
|
|
true
|
|
|
|
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
sleep 0.1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
puts "Port open! Executing: #{cmd}"
|
|
|
|
|
exec cmd
|
|
|
|
|
end
|
2025-08-01 12:52:57 +02:00
|
|
|
end
|