diff --git a/attributes/default.rb b/attributes/default.rb index aaa5823..f2ee51d 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -16,3 +16,4 @@ default['s3cmd']['encrypt'] = false default['s3cmd']['https'] = false default['s3cmd']['user'] = 'ubuntu' +default['s3cmd']['install_method'] = 'source' diff --git a/recipes/configure.rb b/recipes/configure.rb new file mode 100644 index 0000000..03c4844 --- /dev/null +++ b/recipes/configure.rb @@ -0,0 +1,27 @@ +# +# Cookbook Name:: s3cmd +# Recipe:: configure +# Frederico Araujo (fred.the.master@gmail.com) +# https://github.com/fred/chef-s3cmd +# + +if node['s3cmd']['config_dir'] + home_folder = node['s3cmd']['config_dir'] +else + home_folder = node['etc']['passwd'][node['s3cmd']['user']]['dir'] +end + +template "#{home_folder}/.s3cfg" do + source "s3cfg.erb" + variables( + :access_key => node['s3cmd']['access_key'], + :secret_key => node['s3cmd']['secret_key'], + :gpg_passphrase => node['s3cmd']['gpg_passphrase'], + :bucket_location => node['s3cmd']['bucket_location'], + :https => node['s3cmd']['https'], + :encrypt => node['s3cmd']['encrypt'] + ) + owner node['s3cmd']['user'] + group node['s3cmd']['user'] + mode 0600 +end diff --git a/recipes/default.rb b/recipes/default.rb index 1e480c3..bfcb61e 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -5,44 +5,15 @@ # https://github.com/fred/chef-s3cmd # -package "python" -package "python-setuptools" -package "python-distutils-extra" -package "python-dateutil" - - -remote_file "#{Chef::Config[:file_cache_path]}/master.tar.gz" do - source node['s3cmd']['url'] - mode "0644" -end - -bash "install-s3cmd" do - user "root" - cwd Chef::Config[:file_cache_path] - code <<-EOH - tar xzvf master.tar.gz - cd s3cmd-master - python setup.py install - EOH +# install s3cmd based on your configuration +case node['s3cmd']['install_method'] + when 'source' + include_recipe 's3cmd::install_from_source' + when 'package' + include_recipe 's3cmd::install_from_package' + else + Chef::Application.fatal!("There install method #{node['s3cmd']['install_method']} is not provided; please use one of: 'source', 'package'.") end -if node['s3cmd']['config_dir'] - home_folder = node['s3cmd']['config_dir'] -else - home_folder = node['etc']['passwd'][node['s3cmd']['user']]['dir'] -end - -template "#{home_folder}/.s3cfg" do - source "s3cfg.erb" - variables( - :access_key => node['s3cmd']['access_key'], - :secret_key => node['s3cmd']['secret_key'], - :gpg_passphrase => node['s3cmd']['gpg_passphrase'], - :bucket_location => node['s3cmd']['bucket_location'], - :https => node['s3cmd']['https'], - :encrypt => node['s3cmd']['encrypt'] - ) - owner node['s3cmd']['user'] - group node['s3cmd']['user'] - mode 0600 -end +# configure s3cmd +include_recipe 's3cmd::configure' diff --git a/recipes/install_from_package.rb b/recipes/install_from_package.rb new file mode 100644 index 0000000..5ae0bb9 --- /dev/null +++ b/recipes/install_from_package.rb @@ -0,0 +1,8 @@ +# +# Cookbook Name:: s3cmd +# Recipe:: install_from_package +# Frederico Araujo (fred.the.master@gmail.com) +# https://github.com/fred/chef-s3cmd +# + +package 's3cmd' diff --git a/recipes/install_from_source.rb b/recipes/install_from_source.rb new file mode 100644 index 0000000..d1a482b --- /dev/null +++ b/recipes/install_from_source.rb @@ -0,0 +1,27 @@ +# +# Cookbook Name:: s3cmd +# Recipe:: install_from_source +# Frederico Araujo (fred.the.master@gmail.com) +# https://github.com/fred/chef-s3cmd +# + +package "python" +package "python-setuptools" +package "python-distutils-extra" +package "python-dateutil" + + +remote_file "#{Chef::Config[:file_cache_path]}/master.tar.gz" do + source node['s3cmd']['url'] + mode "0644" +end + +bash "install-s3cmd" do + user "root" + cwd Chef::Config[:file_cache_path] + code <<-EOH + tar xzvf master.tar.gz + cd s3cmd-master + python setup.py install + EOH +end