Class: PuppetX::Bodeco::Archive
- Inherits:
-
Object
- Object
- PuppetX::Bodeco::Archive
- Defined in:
- lib/puppet_x/bodeco/archive.rb
Instance Method Summary collapse
- #checksum(type) ⇒ Object
- #extract(path = root_dir, opts = {}) ⇒ Object
-
#initialize(file) ⇒ Archive
constructor
A new instance of Archive.
- #root_dir ⇒ Object
Constructor Details
#initialize(file) ⇒ Archive
Returns a new instance of Archive.
8 9 10 11 12 13 14 15 |
# File 'lib/puppet_x/bodeco/archive.rb', line 8 def initialize(file) @file = file @file_path = if Facter.value(:osfamily) == 'windows' '"' + file + '"' else Shellwords.shellescape file end end |
Instance Method Details
#checksum(type) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/puppet_x/bodeco/archive.rb', line 17 def checksum(type) return nil if type == :none digest = Digest.const_get(type.to_s.upcase) digest.file(@file).hexdigest rescue LoadError raise $ERROR_INFO, "invalid checksum type #{type}. #{$ERROR_INFO}", $ERROR_INFO.backtrace end |
#extract(path = root_dir, opts = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet_x/bodeco/archive.rb', line 34 def extract(path = root_dir, opts = {}) opts = { custom_command: nil, options: '', uid: nil, gid: nil }.merge(opts) custom_command = opts.fetch(:custom_command, nil) = opts.fetch(:options) Dir.chdir(path) do cmd = if custom_command && custom_command =~ %r{%s} custom_command % @file_path elsif custom_command "#{custom_command} #{} #{@file_path}" else command() end Puppet.debug("Archive extracting #{@file} in #{path}: #{cmd}") File.chmod(0o644, @file) if opts[:uid] || opts[:gid] Puppet::Util::Execution.execute(cmd, uid: opts[:uid], gid: opts[:gid], failonfail: true, squelch: false, combine: true) end end |
#root_dir ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/puppet_x/bodeco/archive.rb', line 26 def root_dir if Facter.value(:osfamily) == 'windows' 'C:\\' else '/' end end |