blob: 9c3c79bc3b96b86e42ff9612a36b12f0ccc3ab16 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
require 'puppet/application'
class Puppet::Application::Filebucket < Puppet::Application
should_not_parse_config
option("--bucket BUCKET","-b")
option("--debug","-d")
option("--local","-l")
option("--remote","-r")
option("--verbose","-v")
attr :args
def run_command
@args = command_line.args
command = args.shift
return send(command) if %w{get backup restore}.include? command
help
end
def get
md5 = args.shift
out = @client.getfile(md5)
print out
end
def backup
args.each do |file|
unless FileTest.exists?(file)
$stderr.puts "#{file}: no such file"
next
end
unless FileTest.readable?(file)
$stderr.puts "#{file}: cannot read file"
next
end
md5 = @client.backup(file)
puts "#{file}: #{md5}"
end
end
def restore
file = args.shift
md5 = args.shift
@client.restore(file, md5)
end
def setup
Puppet::Log.newdestination(:console)
@client = nil
@server = nil
trap(:INT) do
$stderr.puts "Cancelling"
exit(1)
end
if options[:debug]
Puppet::Log.level = :debug
elsif options[:verbose]
Puppet::Log.level = :info
end
# Now parse the config
Puppet.parse_config
exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
require 'puppet/file_bucket/dipper'
begin
if options[:local] or options[:bucket]
path = options[:bucket] || Puppet[:bucketdir]
@client = Puppet::FileBucket::Dipper.new(:Path => path)
else
@client = Puppet::FileBucket::Dipper.new(:Server => Puppet[:server])
end
rescue => detail
$stderr.puts detail
puts detail.backtrace if Puppet[:trace]
exit(1)
end
end
end
|