environment/bin/vm

86 lines
2.2 KiB
Text
Raw Normal View History

2025-08-11 10:20:07 +02:00
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'virtual-machine'
2025-08-13 10:21:46 +02:00
# Paramteters
# -env: DAT_VM_DATA=~/.cache/vm
2025-08-11 10:20:07 +02:00
# vm setup debian --arch "<host:arch64>" --name "<image_name: debian>"
options = OpenStruct.new
subcommand = ARGV.shift&.to_sym
2025-08-11 14:18:59 +02:00
parameter = ARGV[0] && ARGV[0] !~ /^-/ ? ARGV.shift : nil
2025-08-11 10:20:07 +02:00
OptionParser.new do |opt|
opt.on('--arch ARCH', 'Architecture arm64 or x86_64') do |arch|
options.arch = arch
end
2025-08-11 14:18:59 +02:00
opt.on('--name NAME', 'Virtaul Machine name') do |name|
options.name = name
2025-08-11 10:20:07 +02:00
end
2025-08-17 17:21:38 +02:00
2025-08-26 08:52:28 +02:00
opt.on('--cdrom CDROM', 'Use local cdrom image') do |cdrom|
options.cdrom = cdrom
end
opt.on('--tpm', 'Use tpm') do
options.tpm = true
end
2025-08-17 17:21:38 +02:00
opt.on('--detached') do
options.detached = true
end
2025-08-13 10:21:46 +02:00
# --port (ssh port)
# --attached (do not leave the shell process)
# new from copy
# fetch from the server
2025-08-11 10:20:07 +02:00
end.parse!
case subcommand
when :create
2025-08-13 10:21:46 +02:00
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)
2025-08-11 10:20:07 +02:00
when :setup
2025-08-11 14:18:59 +02:00
options[:distro] = parameter
2025-08-11 10:20:07 +02:00
VirtualMachine.setup(options)
2025-08-13 10:21:46 +02:00
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"
2025-08-13 10:21:46 +02:00
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"
2025-08-13 10:21:46 +02:00
when :status
puts "Print all images and status stopped/daemon(port)/running(port/)"
when :attach
puts "if not paramteres attaches to last used"
2025-08-11 10:20:07 +02:00
else
puts "Error not found #{options.type}"
2025-08-17 10:30:42 +02:00
end