dup: Added --regenerate to print all command necessary to regenerate a container from scratch.

This commit is contained in:
Fabian Schlenz 2021-11-02 14:13:09 +01:00
parent 3879c20814
commit 45c5612efb

19
dup.rb
View File

@ -155,6 +155,15 @@ def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false, ignore_dry_run
return returnvalue
end
def collect_commands(&block)
$commands = []
def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false, ignore_dry_run: false); $commands<<cmd; return 0; end
yield
return $commands
end
def esc(obj, escape=true)
return obj unless escape
return obj.to_s.shellescape
@ -218,8 +227,7 @@ end
def action_regenerate(container)
container.each do |c|
data = c.regenerate
puts data.to_yaml
puts
p collect_commands{ c.run }
end
end
@ -324,7 +332,7 @@ class Container
end
end
return cmd
return cmd.compact.join(" ")
end
def build
@ -403,7 +411,7 @@ class Container
verbose "Creating container..."
cmd = build_run_command
run_cmd(cmd.compact.join(" ") + " >/dev/null")
run_cmd(cmd + " >/dev/null")
self.connect_to_networks
@ -440,6 +448,7 @@ class Container
data[name] = result
end
@data = data
return data
end
end
@ -506,6 +515,7 @@ opts.each do |opt, arg|
$net_host = true
when '--regenerate'
action = :regenerate
needs_container = false
when '--verbose'
$verbose = true
when '--all'
@ -533,6 +543,7 @@ elsif action == :update
action_update(base_dir)
elsif action == :regenerate
action_regenerate(container)
container.each {|c| puts c.build_run_command}
elsif action == :_completion
action_completion($base_dir, completion_str)
end