bin/tpkg in tpkg-1.16.2 vs bin/tpkg in tpkg-1.18.2

- old
+ new

@@ -27,10 +27,11 @@ @deploy_options = {} # options for how to run the deployer @servers = nil @worker_count = 10 @rerun_with_sudo = false @tpkg_options = {} +@init_options = {} def rerun_with_sudo_if_necessary if Process.euid != 0 && @sudo warn "Executing with sudo" exec('sudo', $0, *ARGV) @@ -95,44 +96,65 @@ @action = :verify @action_value = opt end opts.on('--start', '=NAME', 'Start the init script for the specified package', Array) do |opt| @rerun_with_sudo = true - @action = :start_init - @action_value = opt + @action = :execute_init + @init_options[:packages] = opt + @init_options[:cmd] = 'start' end opts.on('--stop', '=NAME', 'Stop the init script for the specified package', Array) do |opt| @rerun_with_sudo = true - @action = :stop_init - @action_value = opt + @action = :execute_init + @init_options[:packages] = opt + @init_options[:cmd] = 'stop' end opts.on('--restart', '=NAME', 'Restart the init script for the specified package', Array) do |opt| @rerun_with_sudo = true - @action = :restart_init - @action_value = opt + @action = :execute_init + @init_options[:packages] = opt + @init_options[:cmd] = 'restart' end opts.on('--reload', '=NAME', 'Reload the init script for the specified package', Array) do |opt| @rerun_with_sudo = true - @action = :reload_init - @action_value = opt + @action = :execute_init + @init_options[:packages] = opt + @init_options[:cmd] = 'reload' end opts.on('--start-all', 'Start the init scripts for all packages') do |opt| @rerun_with_sudo = true - @action = :start_init + @action = :execute_init + @init_options[:cmd] = 'start' end opts.on('--stop-all', 'Stop the init script for all packages') do |opt| @rerun_with_sudo = true - @action = :stop_init + @action = :execute_init + @init_options[:cmd] = 'stop' end opts.on('--restart-all', 'Restart the init script for all packages') do |opt| @rerun_with_sudo = true - @action = :restart_init + @action = :execute_init + @init_options[:cmd] = 'restart' end opts.on('--reload-all', 'Reload the init script for all packages') do |opt| @rerun_with_sudo = true - @action = :reload_init + @action = :execute_init + @init_options[:cmd] = 'reload' end +opts.on('--exec-init', '=NAME', 'Execute init scripts for the specified packages', Array) do |opt| + @rerun_with_sudo = true + @init_options[:packages] = opt + @action = :execute_init +end +opts.on('--init-script', '=NAME', 'What init scripts to execute', Array) do |opt| + @rerun_with_sudo = true + @init_options[:scripts] = opt +end +opts.on('--init-cmd', '=CMD', 'Invoke the specified init script command') do |opt| + @rerun_with_sudo = true + @init_options[:cmd] = opt +end opts.on('--query', '-q', '=NAMES', 'List installed packages', Array) do |opt| # People mistype -qa instead of --qa frequently if opt == ['a'] warn "NOTE: tpkg -qa queries for a pkg named 'a', you probably want --qa for all pkgs" end @@ -176,12 +198,12 @@ opts.on('--dw', '=INTEGER', 'Number of workers for deploying') do |opt| @worker_count = opt.to_i @deploy_params = @deploy_params - ['--dw', @worker_count, "--dw=#{opt}"] end -opts.on('--qX', '=FILENAME', 'Display tpkg.xml of the given package') do |opt| - @action = :query_tpkgxml +opts.on('--qX', '=FILENAME', 'Display tpkg.xml or tpkg.yml of the given package') do |opt| + @action = :query_tpkg_metadata @action_value = opt end opts.on('--qenv', "Display machine's information") do |opt| @action = :query_env end @@ -358,22 +380,16 @@ success = false end end puts "Package verification failed" unless success end -when :start_init +when :execute_init tpkg = instantiate_tpkg(@tpkg_options) - ret_val = tpkg.execute_init(@action_value, "start") -when :stop_init - tpkg = instantiate_tpkg(@tpkg_options) - ret_val = tpkg.execute_init(@action_value, "stop") -when :restart_init - tpkg = instantiate_tpkg(@tpkg_options) - ret_val = tpkg.execute_init(@action_value, "restart") -when :reload_init - tpkg = instantiate_tpkg(@tpkg_options) - ret_val = tpkg.execute_init(@action_value, "reload") + if @init_options[:cmd].nil? + raise "You didn't specify what init command to run" + end + ret_val = tpkg.execute_init(@init_options) when :query_installed tpkg = instantiate_tpkg(@tpkg_options) req = nil matches = [] if @action_value @@ -416,18 +432,24 @@ already_displayed = {} metadatas.each do |metadata| next if already_displayed[metadata[:filename]] already_displayed[metadata[:filename]] = true [:name, :version, :package_version, :operatingsystem, :architecture, :maintainer, :description, :bugreporting].each do |field| + metadata[field] = 'any' if field == :operatingsystem && metadata[field].nil? + metadata[field] = 'any' if field == :architecture && metadata[field].nil? if metadata[field] if metadata[field].kind_of?(Array) puts "#{field}: #{metadata[field].join(',')}" else puts "#{field}: #{metadata[field]}" end end end + if metadata[:dependencies] + puts "This package depends on other packages, use --qd/--qld to view the dependencies." + end + puts "================================================================================" end when :query_list_files tpkg = instantiate_tpkg(@tpkg_options) pkgfiles = nil if File.exist?(@action_value) @@ -496,10 +518,11 @@ packages.each do |name, pkgs| pkgs.each do |pkg| next if pkg[:source] != :currently_installed puts "The following package(s) require #{pkg[:metadata][:filename]}:" dependencies.each do | requiree, deps | + next if deps.nil? deps.each do | dep | if Tpkg::package_meets_requirement?(pkg, dep) puts " #{requiree}" end end @@ -544,15 +567,17 @@ end end end end end -when :query_tpkgxml +when :query_tpkg_metadata tpkg = instantiate_tpkg(@tpkg_options) - if !File.exist?(@action_value) - puts "File #{@action_value} doesn't exist." + if File.exist?(@action_value) + puts Tpkg::extract_tpkg_metadata_file(@action_value) + elsif File.exists?(File.join(tpkg.installed_directory, @action_value)) + puts Tpkg::extract_tpkg_metadata_file(File.join(tpkg.installed_directory, @action_value)) else - puts Tpkg::extract_tpkgxml(@action_value) + puts "File #{@action_value} doesn't exist." end when :query_env puts "Operating System: #{Tpkg::get_os}" puts "Architecture: #{Tpkg::get_arch}" end