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.
10 11 12 13 14 15 16 17 |
# File 'lib/puppet_x/bodeco/archive.rb', line 10 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
19 20 21 22 23 24 25 26 |
# File 'lib/puppet_x/bodeco/archive.rb', line 19 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/puppet_x/bodeco/archive.rb', line 36 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
28 29 30 31 32 33 34 |
# File 'lib/puppet_x/bodeco/archive.rb', line 28 def root_dir if Facter.value(:osfamily) == 'windows' 'C:\\' else '/' end end |