change variables to point to option parser, updated readme
This commit is contained in:
@ -1,42 +1,38 @@
|
||||
#!/usr/bin/ruby
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'find'
|
||||
require 'optparse'
|
||||
|
||||
ARGV << '-h' if ARGV.empty?
|
||||
options = {:target_path => nil, :clientbucket_path => nil}
|
||||
parser = OptionParser.new do |opts|
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: clientbucket.rb -t target_path -c clientbucket_path"
|
||||
|
||||
opts.on("-t", "--target_path target_path", "path to file to restore") do |t|
|
||||
opts.on("-t", "--target_path target_path", "path of the file to restore") do |t|
|
||||
options[:target_path] = t
|
||||
end
|
||||
|
||||
opts.on("-c", "--clientbucket_path clientbucket_path", "path to file to restore") do |c|
|
||||
opts.on("-c", "--clientbucket_path clientbucket_path", "where to restore from. Defaults to /var/lib/puppet/clientbucket") do |c|
|
||||
options[:clientbucket_path] = c
|
||||
end
|
||||
end
|
||||
|
||||
parser.parse!
|
||||
|
||||
if options[:target_path] == nil
|
||||
print 'Enter target path: '
|
||||
options[:target_path] = gets.chomp
|
||||
end
|
||||
opts.on_tail("-h", "--help", "Show this message") do
|
||||
puts opts
|
||||
exit
|
||||
end
|
||||
end.parse!
|
||||
|
||||
if options[:clientbucket_path] == nil
|
||||
print 'Enter clientbucket path: '
|
||||
options[:clientbucket_path] = gets.chomp
|
||||
# We are keeping it on old path, as there are installations that have not moved on
|
||||
# to Puppet 4
|
||||
options[:clientbucket_path] = "/var/lib/puppet/clientbucket"
|
||||
end
|
||||
|
||||
target_path = options[:target_path]
|
||||
|
||||
clientbucket_path = options[:clientbucket_path]
|
||||
|
||||
available_files = Array.new
|
||||
|
||||
begin
|
||||
Find.find(clientbucket_path) do |file_path|
|
||||
Find.find(options[:clientbucket_path]) do |file_path|
|
||||
|
||||
# Skip directories and "contents" files
|
||||
next if FileTest.directory?(file_path)
|
||||
@ -45,7 +41,7 @@ begin
|
||||
# See if this file has a path the user was looking for
|
||||
path = File.open(file_path).first
|
||||
path.chomp!
|
||||
if target_path == path
|
||||
if options[:target_path] == path
|
||||
|
||||
# Get the md5 string the file is referred to by
|
||||
file_path =~ /([^\/]+)\/paths$/;
|
||||
@ -64,11 +60,11 @@ begin
|
||||
|
||||
end
|
||||
rescue
|
||||
puts "Unable to open file path #{clientbucket_path}"
|
||||
puts "Unable to open file path #{options[:clientbucket_path]}"
|
||||
end
|
||||
# See if we found any files for the user
|
||||
if available_files.length == 0
|
||||
puts "No files with path #{target_path} exist in the clientbucket"
|
||||
puts "No files with path #{options[:target_path]} exist in the clientbucket"
|
||||
exit 2
|
||||
end
|
||||
|
||||
@ -125,16 +121,16 @@ while true
|
||||
when "v"
|
||||
system("vim #{available_files[number][:contents_path]}")
|
||||
when "d"
|
||||
system("diff #{available_files[number][:contents_path]} #{target_path}")
|
||||
system("diff #{available_files[number][:contents_path]} #{options[:target_path]}")
|
||||
when "u"
|
||||
system("diff -u #{available_files[number][:contents_path]} #{target_path}")
|
||||
system("diff -u #{available_files[number][:contents_path]} #{options[:target_path]}")
|
||||
when "r"
|
||||
print "Restore to (default is to restore to #{target_path}): "
|
||||
print "Restore to (default is to restore to #{options[:target_path]}): "
|
||||
choice = gets.strip
|
||||
choice.chomp!
|
||||
|
||||
# If not specified, use the default
|
||||
restore_path = target_path
|
||||
restore_path = options[:target_path]
|
||||
if choice != ''
|
||||
restore_path = choice
|
||||
end
|
||||
|
Reference in New Issue
Block a user