Skip to content

Commit

Permalink
Move packages to install to node attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
zuazo committed Oct 2, 2015
1 parent 336c270 commit 17af639
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 38 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ Attributes
| `node['owncloud']['mysql']['server_root_password']` | *calculated* | MySQL root password to access a database instance.
| `node['owncloud']['encrypt_attributes']` | `false` | Whether to encrypt ownCloud attributes containing credential secrets.

## Platform Support Related Attributes

Some cookbook attributes are used internally to support the different platforms. Surely you want to change them if you want to support new platforms or want to improve the support of some platforms already supported.

| Attribute | Default | Description |
|:-----------------------------------------|:--------------|:----------------------------------|
| `node['owncloud']['packages']['core']` | *calculated* | ownCloud core package names as array.
| `node['owncloud']['packages']['sqlite']` | *calculated* | ownCloud package names array for SQLite.
| `node['owncloud']['packages']['mysql']` | *calculated* | ownCloud package names array for MySQL.
| `node['owncloud']['packages']['pgsql']` | *calculated* | ownCloud package names array for PostgreSQL.

Recipes
=======

Expand Down
56 changes: 56 additions & 0 deletions attributes/packages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# encoding: UTF-8
#
# Cookbook Name:: owncloud
# Attributes:: packages
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
# Copyright:: Copyright (c) 2015 Xabier de Zuazo
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

case node['platform_family']
when 'debian'
default['owncloud']['packages']['core'] =
%w(php5-gd php5-intl php5-curl php5-json smbclient)
default['owncloud']['packages']['sqlite'] = %w(php5-sqlite)
default['owncloud']['packages']['mysql'] = %w(php5-mysql)
default['owncloud']['packages']['pgsql'] = %w(php5-pgsql)
when 'rhel'
if node['platform'] != 'amazon' && node['platform_version'].to_f < 6
default['owncloud']['packages']['core'] =
%w(php53-gd php53-mbstring php53-xml php53-intl samba-client)
default['owncloud']['packages']['sqlite'] = %w(php53-pdo)
default['owncloud']['packages']['mysql'] = %w(php53-mysql)
default['owncloud']['packages']['pgsql'] = %w(php53-pgsql)
else
default['owncloud']['packages']['core'] =
%w(php-gd php-mbstring php-xml php-intl samba-client)
default['owncloud']['packages']['sqlite'] = %w(php-pdo)
default['owncloud']['packages']['mysql'] = %w(php-mysql)
default['owncloud']['packages']['pgsql'] = %w(php-pgsql)
end
when 'fedora'
default['owncloud']['packages']['core'] =
%w(php-gd php-mbstring php-xml php-intl samba-client)
default['owncloud']['packages']['sqlite'] = %w(php-pdo)
default['owncloud']['packages']['mysql'] = %w(php-mysql)
default['owncloud']['packages']['pgsql'] = %w(php-pgsql)
else
Chef::Log.warn('Unsupported platform, trying to guess packages.')
default['owncloud']['packages']['core'] =
%w(php-gd php-mbstring php-xml php-intl samba-client)
default['owncloud']['packages']['sqlite'] = %w(php-pdo)
default['owncloud']['packages']['mysql'] = %w(php-mysql)
default['owncloud']['packages']['pgsql'] = %w(php-pgsql)
end
32 changes: 32 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,35 @@
type: 'string',
choice: %w(true false),
default: 'false'

grouping 'owncloud/packages',
title: 'owncloud packages',
description: 'ownCloud packages'

attribute 'owncloud/packages/core',
display_name: 'owncloud packages core',
description: 'ownCloud core package names as array.',
type: 'array',
required: 'optional',
calculated: true

attribute 'owncloud/packages/sqlite',
display_name: 'owncloud packages sqlite',
description: 'ownCloud package names array for SQLite.',
type: 'array',
required: 'optional',
calculated: true

attribute 'owncloud/packages/mysql',
display_name: 'owncloud packages mysql',
description: 'ownCloud package names array for MySQL.',
type: 'array',
required: 'optional',
calculated: true

attribute 'owncloud/packages/postgresql',
display_name: 'owncloud packages postgresql',
description: 'ownCloud package names array for PostgreSQL.',
type: 'array',
required: 'optional',
calculated: true
49 changes: 11 additions & 38 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,12 @@
# limitations under the License.
#

#==============================================================================
# Calculate dependencies for different distros
#==============================================================================

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

case node['platform_family']
when 'debian'
# Sync apt package index
include_recipe 'apt'

php_pkgs = %w(php5-gd php5-intl php5-curl php5-json smbclient)
php_pkgs << 'php5-sqlite' if dbtype == 'sqlite'
php_pkgs << 'php5-mysql' if dbtype == 'mysql'
php_pkgs << 'php5-pgsql' if dbtype == 'pgsql'
when 'rhel'
if node['platform'] != 'amazon' && node['platform_version'].to_f < 6
php_pkgs = %w(php53-gd php53-mbstring php53-xml php53-intl samba-client)
php_pkgs << 'php53-pdo' if dbtype == 'sqlite'
php_pkgs << 'php53-mysql' if dbtype == 'mysql'
php_pkgs << 'php53-pgsql' if dbtype == 'pgsql'
else
php_pkgs = %w(php-gd php-mbstring php-xml php-intl samba-client)
php_pkgs << 'php-pdo' if dbtype == 'sqlite'
php_pkgs << 'php-mysql' if dbtype == 'mysql'
php_pkgs << 'php-pgsql' if dbtype == 'pgsql'
end
when 'fedora'
php_pkgs = %w(php-gd php-mbstring php-xml php-intl samba-client)
php_pkgs << 'php-pdo' if dbtype == 'sqlite'
php_pkgs << 'php-mysql' if dbtype == 'mysql'
php_pkgs << 'php-pgsql' if dbtype == 'pgsql'
else
Chef::Log.warn('Unsupported platform, trying to guess packages.')
php_pkgs = %w(php-gd php-mbstring php-xml php-intl samba-client)
php_pkgs << 'php-pdo' if dbtype == 'sqlite'
php_pkgs << 'php-mysql' if dbtype == 'mysql'
php_pkgs << 'php-pgsql' if dbtype == 'pgsql'
end
# Sync apt package index
include_recipe 'apt' if platform_family?('debian')

#==============================================================================
# Initialize autogenerated passwords
Expand Down Expand Up @@ -125,12 +90,20 @@

include_recipe 'php'

php_pkgs.each do |pkg|
node['owncloud']['packages']['core'].each do |pkg|
package pkg do
action :install
end
end

if node['owncloud']['packages'].key?(dbtype)
node['owncloud']['packages'][dbtype].each do |pkg|
package pkg do
action :install
end
end
end

#==============================================================================
# Set up database
#==============================================================================
Expand Down

0 comments on commit 17af639

Please sign in to comment.