puppet-standalone-mashup/shared/lib/puppet/provider/download_and_unpack/action.rb

50 lines
1.1 KiB
Ruby
Raw Normal View History

Puppet::Type.type(:download_and_unpack).provide(:action) do
desc "Download an unpack a remote repository"
def create
system %{bash -c 'cd #{@resource[:src_path]} ; (curl #{@resource[:url]} | tar #{tar_command} -)'}
2012-05-02 22:17:23 +00:00
raise StandardError.new("Could not download") if $?.exitstatus != 0
2012-05-04 17:54:50 +00:00
if original_name
system %{bash -c 'cd #{@resource[:src_path]} && mv #{original_name} #{target_dir}'}
end
end
def destroy
2012-05-04 17:54:50 +00:00
FileUtils.rm_rf target_dir
end
def exists?
2012-05-04 17:54:50 +00:00
File.directory?(File.join(@resource[:src_path], target_dir))
end
private
def file
File.join(@resource[:src_path], File.basename(@resource[:url]))
end
2012-05-04 17:54:50 +00:00
def target_dir
"#{@resource[:name]}-#{@resource[:version]}"
end
def dir
file.gsub(%r{\.tar\.(gz|bz2)$}, '')
end
2012-05-04 17:54:50 +00:00
def original_name
(@resource[:original_name] || '').empty? ? nil : @resource[:original_name]
end
def tar_command
case @resource[:url]
when /\.gz/
"zxvf"
when /\.bz2/
"jxvf"
else
raise StandardError.new("Unknown format: #{@resource[:src_path]}")
end
end
end