creating raw images for QEMU
This commit is contained in:
parent
3b9e0a1f33
commit
49cc960703
13 changed files with 164 additions and 17 deletions
55
lib/system/architecture.rb
Normal file
55
lib/system/architecture.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
module System
|
||||
def self.normalize_architecture_string(s)
|
||||
str = s.to_s.strip.downcase
|
||||
exact = {
|
||||
"x86_64" => :x86_64, "amd64" => :x86_64,
|
||||
"i386" => :x86_32, "i486" => :x86_32, "i586" => :x86_32, "i686" => :x86_32,
|
||||
|
||||
"arm64" => :arm64, "aarch64" => :arm64,
|
||||
"armhf" => :armv7, "armel" => :armv5, "armv7l" => :armv7, "armv6l" => :armv6, "armv5tel" => :armv5,
|
||||
|
||||
"riscv64" => :riscv64,
|
||||
|
||||
"ppc64el" => :ppc64le, "ppc64le" => :ppc64le,
|
||||
"ppc64" => :ppc64, "powerpc64" => :ppc64,
|
||||
"ppc" => :ppc32, "powerpc" => :ppc32,
|
||||
|
||||
"s390x" => :s390x,
|
||||
|
||||
"mips64el" => :mips64el, "mips64" => :mips64,
|
||||
"mipsel" => :mipsel, "mips" => :mips,
|
||||
|
||||
"loong64" => :loongarch64, "loongarch64" => :loongarch64,
|
||||
|
||||
"sparc64" => :sparc64,
|
||||
|
||||
"alpha" => :alpha,
|
||||
"hppa" => :hppa,
|
||||
"ia64" => :ia64,
|
||||
}
|
||||
return exact[str] if exact.key?(str)
|
||||
|
||||
return :x86_64 if str.include?("x64") || str.include?("amd64")
|
||||
return :x86_32 if str =~ /\Ai[3-6]86\z/ || str.include?("x86")
|
||||
return :arm64 if str.include?("aarch64") || str.include?("arm64")
|
||||
return :armv7 if str.include?("armv7")
|
||||
return :armv6 if str.include?("armv6")
|
||||
return :armv5 if str.include?("armv5")
|
||||
return :riscv64 if str.include?("riscv64")
|
||||
return :ppc64le if str.include?("ppc64el") || str.include?("ppc64le")
|
||||
return :ppc64 if str.include?("ppc64")
|
||||
return :ppc32 if str.include?("ppc") || str.include?("powerpc")
|
||||
return :s390x if str.include?("s390x")
|
||||
return :mips64el if str.include?("mips64el")
|
||||
return :mips64 if str.include?("mips64")
|
||||
return :mipsel if str.include?("mipsel")
|
||||
return :mips if str.start_with?("mips")
|
||||
return :loongarch64 if str.include?("loong") || str.include?("loongarch")
|
||||
return :sparc64 if str.include?("sparc64")
|
||||
return :alpha if str.include?("alpha")
|
||||
return :hppa if str.include?("hppa")
|
||||
return :ia64 if str.include?("ia64")
|
||||
|
||||
:unknown
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
require 'open3'
|
||||
require_relative "utils"
|
||||
|
||||
module DebianSystem
|
||||
def os_name
|
||||
|
|
@ -10,6 +11,10 @@ module DebianSystem
|
|||
stdout.strip.to_i
|
||||
end
|
||||
|
||||
def arch
|
||||
sh("dpkg --print-architecture")
|
||||
end
|
||||
|
||||
def install(packages)
|
||||
missing_packages = packages.reject { |pkg| package_installed?(pkg) }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
require 'open3'
|
||||
require_relative "utils"
|
||||
|
||||
module MacOSSystem
|
||||
def os_name
|
||||
"macOS"
|
||||
end
|
||||
|
||||
def arch
|
||||
sh("sysctl -n hw.machine")
|
||||
end
|
||||
|
||||
def cpus
|
||||
stdout, stderr, status = Open3.capture3("sysctl -n hw.ncpu")
|
||||
stdout.strip.to_i
|
||||
|
|
|
|||
6
lib/system/utils.rb
Normal file
6
lib/system/utils.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def sh(cmd)
|
||||
out = `#{cmd} 2>/dev/null`.to_s.strip
|
||||
out.empty? ? "" : out
|
||||
rescue
|
||||
""
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue