-
-
Save sanguis/8fea8779e61721baeb47 to your computer and use it in GitHub Desktop.
# Takes a file and or a url decides if it is a git repo or an archive. # Downloads or clones it. to the destination.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes a file and or a url decides if it is a git repo or an archive. | |
# Downloads or clones it. to the destination. | |
# Do not enter url with trailing slash. | |
def get_files(url, file, destination) | |
case File.extname(file) | |
when '.tar.gz', '.zip' then unpack_archive(url, file, destination) | |
when '.git' | |
git 'destination' do | |
repository "#{url}/#{file}" | |
reference 'master' | |
user node['apache']['user'] | |
action :sync | |
end | |
else fail ArgumentError, "dunno how to handle #{file}" | |
end | |
end | |
def unpack_archive(url, file, destination) | |
remote_file "#{Chef::Config['file_cache_path'] || '/tmp'}/#{file}" do | |
owner 'root' | |
group 'root' | |
mode '0644' | |
source "#{url}/#{file}" | |
not_if File.readable?(file) | |
end | |
extract = case File.extname(file) | |
when '.tar.gz' then "tar-xC #{destination} -f #{file};" | |
when 'zip' then "unzip -d #{destination} -qo #{file};" | |
end | |
bash "Extract #{file}" do | |
cwd ::File.dirname("#{Chef::Config['file_cache_path'] || '/tmp'}/#{file}") | |
code extract | |
not_if { ::File.readable(file) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting the 3 offenses: