~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to bin/filebucket

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#   /etc/passwd: 429b225650b912a2ee067b0a4cf1e949
46
46
#   $ filebucket restore /tmp/passwd 429b225650b912a2ee067b0a4cf1e949
47
47
#   $
48
 
 
48
#
49
49
# = Options
50
50
#
51
51
# Note that any configuration parameter that's valid in the configuration file
53
53
# parameter, so you can specify '--ssldir <directory>' as an argument.
54
54
#
55
55
# See the configuration file documentation at
56
 
# http://reductivelabs.com/projects/puppet/reference/configref.html for
 
56
# http://reductivelabs.com/trac/puppet/wiki/ConfigurationReference for
57
57
# the full list of acceptable parameters. A commented list of all
58
58
# configuration options can also be generated by running puppet with
59
59
# '--genconfig'.
94
94
# Copyright (c) 2005 Reductive Labs, LLC
95
95
# Licensed under the GNU Public License
96
96
 
97
 
require 'puppet'
98
 
require 'puppet/network/client'
99
 
require 'getoptlong'
100
 
 
101
 
options = [
102
 
    [ "--bucket",   "-b",                       GetoptLong::REQUIRED_ARGUMENT ],
103
 
    [ "--debug",        "-d",                   GetoptLong::NO_ARGUMENT ],
104
 
    [ "--help",         "-h",                   GetoptLong::NO_ARGUMENT ],
105
 
    [ "--local",        "-l",                   GetoptLong::NO_ARGUMENT ],
106
 
    [ "--remote",       "-r",                   GetoptLong::NO_ARGUMENT ],
107
 
    [ "--verbose",  "-v",                       GetoptLong::NO_ARGUMENT ],
108
 
    [ "--version",  "-V",           GetoptLong::NO_ARGUMENT ]
109
 
]
110
 
 
111
 
# Add all of the config parameters as valid options.
112
 
Puppet.settings.addargs(options)
113
 
 
114
 
result = GetoptLong.new(*options)
115
 
 
116
 
options = {}
117
 
 
118
 
begin
119
 
    result.each { |opt,arg|
120
 
        case opt
121
 
            when "--version"
122
 
                puts "%s" % Puppet.version
123
 
                exit
124
 
            when "--help"
125
 
                if Puppet.features.usage?
126
 
                    RDoc::usage && exit
127
 
                else
128
 
                    puts "No help available unless you have RDoc::usage installed"
129
 
                    exit
130
 
                end
131
 
            when "--bucket"
132
 
                options[:bucket] = arg
133
 
            when "--verbose"
134
 
                options[:verbose] = true
135
 
            when "--debug"
136
 
                options[:debug] = true
137
 
            when "--local"
138
 
                options[:local] = true
139
 
            when "--remote"
140
 
                options[:remote] = true
141
 
            else
142
 
                Puppet.settings.handlearg(opt, arg)
143
 
        end
144
 
    }
145
 
rescue GetoptLong::InvalidOption => detail
146
 
    $stderr.puts "Try '#{$0} --help'"
147
 
    exit(1)
148
 
end
149
 
 
150
 
Puppet::Log.newdestination(:console)
151
 
 
152
 
client = nil
153
 
server = nil
154
 
 
155
 
Puppet.settraps
156
 
 
157
 
if options[:debug]
158
 
    Puppet::Log.level = :debug
159
 
elsif options[:verbose]
160
 
    Puppet::Log.level = :info
161
 
end
162
 
 
163
 
# Now parse the config
164
 
Puppet.parse_config
165
 
 
166
 
if Puppet.settings.print_configs?
167
 
        exit(Puppet.settings.print_configs ? 0 : 1)
168
 
end
169
 
 
170
 
begin
171
 
    if options[:local] or options[:bucket]
172
 
        path = options[:bucket] || Puppet[:bucketdir]
173
 
        client = Puppet::Network::Client.dipper.new(:Path => path)
174
 
    else
175
 
        require 'puppet/network/handler'
176
 
        client = Puppet::Network::Client.dipper.new(:Server => Puppet[:server])
177
 
    end
178
 
rescue => detail
179
 
    $stderr.puts detail
180
 
    if Puppet[:trace]
181
 
        puts detail.backtrace
182
 
    end
183
 
    exit(1)
184
 
end
185
 
 
186
 
mode = ARGV.shift
187
 
case mode
188
 
when "get":
189
 
    md5 = ARGV.shift
190
 
    out = client.getfile(md5)
191
 
    print out
192
 
when "backup":
193
 
    ARGV.each do |file|
194
 
        unless FileTest.exists?(file)
195
 
            $stderr.puts "%s: no such file" % file
196
 
            next
197
 
        end
198
 
        unless FileTest.readable?(file)
199
 
            $stderr.puts "%s: cannot read file" % file
200
 
            next
201
 
        end
202
 
        md5 = client.backup(file)
203
 
        puts "%s: %s" % [file, md5]
204
 
    end
205
 
when "restore":
206
 
    file = ARGV.shift
207
 
    md5 = ARGV.shift
208
 
    client.restore(file, md5)
209
 
else
210
 
    raise "Invalid mode %s" % mode
211
 
end
212
 
 
 
97
require 'puppet/application'
 
98
require 'puppet/application/filebucket'
 
99
 
 
100
# launch the filebucket
 
101
Puppet::Application[:filebucket].run