2011-12-07 22:59:34 +00:00
|
|
|
Puppet::Type.type(:download_and_unpack).provide(:action) do
|
|
|
|
desc "Download an unpack a remote repository"
|
|
|
|
|
|
|
|
def create
|
2012-05-04 20:49:17 +00:00
|
|
|
system %{bash -c 'mkdir -p #{@resource[:src_path]} ; cd #{@resource[:src_path]} ; (curl -L #{@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
|
2011-12-07 22:59:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2012-05-04 17:54:50 +00:00
|
|
|
FileUtils.rm_rf target_dir
|
2011-12-07 22:59:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exists?
|
2012-07-18 22:02:21 +00:00
|
|
|
return unless? if unless? != nil
|
2012-05-07 18:30:35 +00:00
|
|
|
|
|
|
|
File.directory?(File.join(@resource[:src_path], target_dir))
|
2011-12-07 22:59:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2012-05-07 14:53:50 +00:00
|
|
|
def unless?
|
2012-05-09 16:56:25 +00:00
|
|
|
return nil if !@resource[:unless] || @resource[:unless].empty?
|
2012-05-07 14:53:50 +00:00
|
|
|
|
|
|
|
system %{bash -c '#{@resource[:unless]}'}
|
|
|
|
|
|
|
|
$?.exitstatus == 0
|
|
|
|
end
|
|
|
|
|
2011-12-07 22:59:34 +00:00
|
|
|
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
|
|
|
|
|
2011-12-07 22:59:34 +00:00
|
|
|
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
|
|
|
|
|
2011-12-07 22:59:34 +00:00
|
|
|
def tar_command
|
|
|
|
case @resource[:url]
|
|
|
|
when /\.gz/
|
|
|
|
"zxvf"
|
|
|
|
when /\.bz2/
|
|
|
|
"jxvf"
|
|
|
|
else
|
|
|
|
raise StandardError.new("Unknown format: #{@resource[:src_path]}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|