environment/bin/vm
2025-08-28 17:48:34 +02:00

90 lines
2.3 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'virtual-machine'
# Paramteters
# -env: DAT_VM_DATA=~/.cache/vm
# vm setup debian --arch "<host:arch64>" --name "<image_name: debian>"
options = OpenStruct.new
subcommand = ARGV.shift&.to_sym
parameter = ARGV[0] && ARGV[0] !~ /^-/ ? ARGV.shift : nil
OptionParser.new do |opt|
opt.on('--arch ARCH', 'Architecture arm64 or x86_64') do |arch|
options.arch = arch
end
opt.on('--name NAME', 'Virtaul Machine name') do |name|
options.name = name
end
opt.on('--cdrom CDROM', 'Use local cdrom image') do |cdrom|
options.cdrom = cdrom
end
opt.on('--tpm', 'Use tpm') do
options.tpm = true
end
opt.on('--shell', 'QEMU process must be detached to exec ssh') do
options.shell = true
options.detached = true
end
opt.on('--detached') do
options.detached = true
end
# --port (ssh port)
# --attached (do not leave the shell process)
# new from copy
# fetch from the server
end.parse!
case subcommand
when :create
puts "vm create debian-copy --name debian"
puts "Creating image base on existing one...."
when :run
# same as setup but fetches image not
puts "Run the image or fetch and run...."
options[:distro] = parameter
VirtualMachine.run(options)
when :setup
options[:distro] = parameter
VirtualMachine.setup(options)
when :archive
# whole image or files that are not present in the archived
# --type files (zst all files by files)
# by default
#before start if should create index of files that are present on
# the vm, so later we can copy new files or changed
options[:distro] = parameter
VirtualMachine.archive(options)
when :apply
puts "apply chnages from VM to the host os"
when :restore
options[:distro] = parameter
VirtualMachine.restore(options)
#puts "download image from remote or if local copy exists then the local copy"
when :daemon
puts "setup a pprocess so i can attach to it"
# paramaters exatly as run/setup
when :execute
puts "vm execute debian --file example.sh --attach (block terminal till done otherwiese notifi when done)"
puts "if name not provided then use the last accessed"
when :status
puts "Print all images and status stopped/daemon(port)/running(port/)"
when :attach
puts "if not paramteres attaches to last used"
else
puts "Error not found #{options.type}"
end