Skip to content

Commit

Permalink
Generate URL dynamically using the version value
Browse files Browse the repository at this point in the history
  • Loading branch information
zuazo committed Sep 19, 2015
1 parent 7fdf123 commit 553307a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

default['owncloud']['version'] = 'latest'
default['owncloud']['download_url'] =
'http://download.owncloud.org/community/'\
"owncloud-#{node['owncloud']['version']}.tar.bz2"
'http://download.owncloud.org/community/owncloud-%{version}.tar.bz2'

default['owncloud']['deploy_from_git'] = false
default['owncloud']['git_repo'] = 'https://github.com/owncloud/core.git'
Expand Down
8 changes: 5 additions & 3 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#==============================================================================

dbtype = node['owncloud']['config']['dbtype']
download_url =
node['owncloud']['download_url'] % { version: node['owncloud']['version'] }

case node['platform_family']
when 'debian'
Expand Down Expand Up @@ -236,14 +238,14 @@
directory node['owncloud']['www_dir']

if node['owncloud']['deploy_from_git'] != true
basename = ::File.basename(node['owncloud']['download_url'])
basename = ::File.basename(download_url)
local_file = ::File.join(Chef::Config[:file_cache_path], basename)

# Prior to Chef 11.6, remote_file does not support conditional get
# so we do a HEAD http_request to mimic it
http_request 'HEAD owncloud' do
message ''
url node['owncloud']['download_url']
url download_url
if Gem::Version.new(Chef::VERSION) < Gem::Version.new('11.6.0')
action :head
else
Expand All @@ -256,7 +258,7 @@
end

remote_file 'download owncloud' do
source node['owncloud']['download_url']
source download_url
path local_file
if Gem::Version.new(Chef::VERSION) < Gem::Version.new('11.6.0')
action :nothing
Expand Down
3 changes: 0 additions & 3 deletions test/cookbooks/owncloud_test/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# Until sendmail fixed: https://github.com/owncloud/core/issues/19110
default['owncloud']['version'] = '8.0.8'
default['owncloud']['download_url'] =
'http://download.owncloud.org/community/'\
"owncloud-#{node['owncloud']['version']}.tar.bz2"
3 changes: 3 additions & 0 deletions test/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@

it 'downloads owncloud' do
expect(chef_run).to create_remote_file('download owncloud')
.with_source(
'http://download.owncloud.org/community/owncloud-latest.tar.bz2'
)
.with_path(local_file)
end
end # context with Chef 11.6
Expand Down

0 comments on commit 553307a

Please sign in to comment.