diff --git a/Batali b/Batali index b0f08e4..f94661b 100644 --- a/Batali +++ b/Batali @@ -36,7 +36,7 @@ Batali.define do cookbook 'omnibus_updater', '~> 1.0.4' cookbook 'timezone-ii' cookbook 'nodejs', '~> 3.0.0' - cookbook 'ark' + cookbook 'ark', '~> 2.2.1' cookbook 'logrotate' end diff --git a/batali.manifest b/batali.manifest index caada72..386456c 100644 --- a/batali.manifest +++ b/batali.manifest @@ -655,29 +655,6 @@ "version": "3.0.0" } }, - { - "name": "ark", - "dependencies": [ - [ - "build-essential", - ">= 0.0.0" - ], - [ - "windows", - ">= 0.0.0" - ], - [ - "seven_zip", - ">= 0.0.0" - ] - ], - "version": "1.0.1", - "source": { - "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/ark/versions/1.0.1/download", - "version": "1.0.1" - } - }, { "name": "seven_zip", "dependencies": [ @@ -880,6 +857,29 @@ "version": "0.2.0" } }, + { + "name": "ark", + "dependencies": [ + [ + "build-essential", + ">= 0.0.0" + ], + [ + "windows", + ">= 0.0.0" + ], + [ + "seven_zip", + ">= 0.0.0" + ] + ], + "version": "2.2.1", + "source": { + "type": "Batali::Source::Site", + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/ark/versions/2.2.1/download", + "version": "2.2.1" + } + }, { "name": "logrotate", "dependencies": [ diff --git a/cookbooks/ark/CHANGELOG.md b/cookbooks/ark/CHANGELOG.md index 7e5a432..41b3e54 100644 --- a/cookbooks/ark/CHANGELOG.md +++ b/cookbooks/ark/CHANGELOG.md @@ -1,11 +1,75 @@ # ark Cookbook CHANGELOG + This file is used to list changes made in each version of the ark cookbook. +## 2.2.1 (2016-12-16) +- Use Ohai root_group attribute to avoid trying to set the group to root on BSD/macOS. +- Add missing accessor for owner property + +## 2.2.0 (2016-12-14) + +- Add detection of .7z file extensions +- Fix 7zip extraction using strip_components >= 1 to properly extract to the path instead of the user's home_dir +- Always quote the path to the 7zip and xcopy binaries as they may have spaces +- Clarified in the readme that the install_with_make action includes the configure action +- Fix files with very long paths failing to extract on Windows +- Fix default owner of 'root' failing on Windows +- Fix 7-zip extraction with long paths when strip_components is >= 1 +- Add the group attribute parameter to README +- Fix package installation failure on macOS systems +- Use x to extract with 7-zip, not e. Use e only for dump, which strips directories. + +## 2.1.0 (2016-11-15) + +- Move tar/7zip path logic out of attributes and into helpers to prevent failures when 7zip is not installed before the chef run starts +- Improve platform testing in Test Kitchen +- Recognize Windows as a supported platform in the readme +- Introduce a new attribute for overriding the 7-zip location: node['ark']['sevenzip_binary'] + +## 2.0.2 (2016-11-03) + +- Fix suse support and centos < 6 + +## 2.1.0 (2016-11-01) + +- Use multipackage installs to speed up installation +- Avoid installation package dependencies on Windows entirely +- Remove the testing bin stubs + +## 2.0.0 (2016-09-15) + +- Add CentOS 7.2, Fedora 23, and Suse specs +- Add centos 5, debian, and opensuse travis testing +- Add a contributing doc +- Fix cookstyle warnings +- Require Chef 12.1+ + +## [v1.2.0](https://github.com/chef-cookbooks/ark/tree/v1.2.0) (2016-07-03) + +[Full Changelog](https://github.com/chef-cookbooks/ark/compare/v1.1.0...v1.2.0) + +- Create seven_zip unpack command when strip_components is 0 [#155](https://github.com/chef-cookbooks/ark/pull/155) ([terkill](https://github.com/terkill)) +- Get 7zip path from the windows registry. [#153](https://github.com/chef-cookbooks/ark/pull/153) ([buri17](https://github.com/buri17)) +- Use fullpath for xcopy and icacls. [#152](https://github.com/chef-cookbooks/ark/pull/152) ([buri17](https://github.com/buri17)) +- Define custom matcher helper for notification testing, fixes #139 [#144](https://github.com/chef-cookbooks/ark/pull/144) ([szymonpk](https://github.com/szymonpk)) + +## v1.1.0 (2016-05-19) + +- Add support for RHEL 7 +- Fixes to the readme to clarify actions / properties +- Expose the backup property in remote file to the ark resource +- Transfer the cookbook back to Chef +- Resolve all rubocop warnings +- Add maintainers files and Chef contributing docs +- Test on the latest platforms in .kitchen.yml and update Travis to use kitchen-dokken with additional platforms + ## v1.0.1 (2016-02-16) + - Remove a large number of zero byte archives that snuck into the repository - Remove a Chef 10 compatibility check in the custom resource ## v1.0.0 (2016-02-09) + - Added the pkg-config package to the debian platform family - Added tar, xz-lzma-compat, and bzip2 packages to the RHEL and fedora platform families - Updated FreeBSD to install gmake instead of make @@ -24,6 +88,7 @@ This file is used to list changes made in each version of the ark cookbook. - Improved error logging when an unknown extension is encountered - Added support for .tar files - Improved overall testing: + - Removed the kitchen.cloud.yml file and gem dependencies - Added integration testing in Travis with Kitchen-Docker and Travis tests now run using the nightly build of ChefDK - Expanded platforms tested in the .kitchen.yml file @@ -33,106 +98,144 @@ This file is used to list changes made in each version of the ark cookbook. - Removed the original minitests - Added standard Chef .gitignore and chefignore files + - Resolved a large number of rubocop warnings + - Removed old Opscode contributing and testing docs + - Added a cookbook version badge to the readme + - Removed the Toftfile ## v0.9.0 (2014-06-06) + - [COOK-3642] Add Windows support ## v0.8.2 (2014-04-23) + - [COOK-4514] - Support for SLES with the Ark cookbook ## v0.8.0 (2014-04-10) + - [COOK-2771] - Add support for XZ compression ## v0.7.2 (2014-03-28) + - [COOK-4477] - Fix failing test suite - [COOK-4484] - Replace strip_leading_dir attribute with more general strip_components ## v0.7.0 (2014-03-18) + - [COOK-4437] - configure and install_with_make should chown after unpack ## v0.6.0 (2014-02-27) + [COOK-3786] - Unable to install multiple versions of archive without duplication ## v0.5.0 (2014-02-21) + ### Bug + - **[COOK-4288](https://tickets.opscode.com/browse/COOK-4288)** - Cleanup the Kitchen ### Improvement + - **[COOK-4264](https://tickets.opscode.com/browse/COOK-4264)** - Add node['ark']['package_dependencies'] to allow tuning packages. ## v0.4.2 + ### Improvement + - **[COOK-3854](https://tickets.opscode.com/browse/COOK-3854)** - Capability with mac_os_x: '/bin/chown' - No such file or directory - Cleaning up some style for rubucop - Updating test harness ## v0.4.0 + ### Improvement + - **[COOK-3539](https://tickets.opscode.com/browse/COOK-3539)** - Allow dumping of bz2 and gzip files ## v0.3.2 + ### Bug + - **[COOK-3191](https://tickets.opscode.com/browse/COOK-3191)** - Propogate unzip failures - **[COOK-3118](https://tickets.opscode.com/browse/COOK-3118)** - Set cookbook attribute in provider - **[COOK-3055](https://tickets.opscode.com/browse/COOK-3055)** - Use proper scope in helper module - **[COOK-3054](https://tickets.opscode.com/browse/COOK-3054)** - Fix notification resource updating ### Improvement + - **[COOK-3179](https://tickets.opscode.com/browse/COOK-3179)** - README updates and refactor ## v0.3.0 + ### Improvement + - [COOK-3087]: Can't use ark with chef < 11 ### Bug + - [COOK-3064]: `only_if` statements in ark's `install_with_make` and configure actions are not testing for file existence correctly. - [COOK-3067]: ark kitchen test for `cherry_pick` is expecting the binary to be in the same parent folder as in the archive. ## v0.2.4 + ### Bug + - [COOK-3048]: Ark provider contains a `ruby_block` resource without a block attribute - [COOK-3063]: Ark cookbook `cherry_pick` action's unzip command does not close if statement - [COOK-3065]: Ark install action does not symlink binaries correctly ## v0.2.2 + - Update the README to reflect the requirement for Chef 11 to use the ark resource (`use_inline_resources`). - Making this a release so it will also appear on the community site page. ## v0.2.0 + ### Bug + - [COOK-2772]: Ark cookbook has foodcritic failures in provides/default.rb ### Improvement + - [COOK-2520]: Refactor ark providers to use the '`use_inline_resources`' LWRP DSL feature ## v0.1.0 + - [COOK-2335] - ark resource broken on Chef 11 ## v0.0.1 + - [COOK-2026] - Allow `cherry_pick` action to be used for directories as well as files ## v0.0.1 + - [COOK-1593] - README formatting updates for better display on Community Site ## v0.0.1 + ### Bug + - dangling "unless" ### Improvement + - add `setup_py_*` actions - add vagrantfile - add foodcritic test - travis.ci support ## v0.0.10 (May 23, 2012 + ### Bug -- `strip_leading_dir` not working for zip files [https://github.com/bryanwb/chef-ark/issues/19](https://github.com/bryanwb/chef-ark/issues/19) + +- `strip_leading_dir` not working for zip files ### Improvement -- use autogen.sh to generate configure script for configure action [https://github.com/bryanwb/chef-ark/issues/16](https://github.com/bryanwb/chef-ark/issues/16) -- support more file extensions [https://github.com/bryanwb/chef-ark/pull/18](https://github.com/bryanwb/chef-ark/pull/18) + +- use autogen.sh to generate configure script for configure action +- support more file extensions - add extension attribute which allows you to download files which do not have the file extension as part of the URL diff --git a/cookbooks/ark/CONTRIBUTING.md b/cookbooks/ark/CONTRIBUTING.md new file mode 100644 index 0000000..ef2f2b8 --- /dev/null +++ b/cookbooks/ark/CONTRIBUTING.md @@ -0,0 +1,2 @@ +Please refer to +https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD diff --git a/cookbooks/ark/MAINTAINERS.md b/cookbooks/ark/MAINTAINERS.md new file mode 100644 index 0000000..645ed14 --- /dev/null +++ b/cookbooks/ark/MAINTAINERS.md @@ -0,0 +1,15 @@ + + +# Maintainers + +This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. + +Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead. + +# Project Maintainer +* [Tim Smith](https://github.com/tas50) + +# Maintainers +* [Jennifer Davis](https://github.com/sigje) +* [Tim Smith](https://github.com/tas50) +* [Thom May](https://github.com/thommay) diff --git a/cookbooks/ark/README.md b/cookbooks/ark/README.md index 6c4ec8a..ac467c1 100644 --- a/cookbooks/ark/README.md +++ b/cookbooks/ark/README.md @@ -1,7 +1,9 @@ # ark cookbook -[![Build Status](https://travis-ci.org/burtlo/ark.svg?branch=master)](https://travis-ci.org/burtlo/ark) [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark) + +[![Build Status](https://travis-ci.org/chef-cookbooks/ark.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ark) [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark) ## Overview + This cookbook provides `ark`, a resource for managing software archives. It manages the fetch-unpack-configure-build-install process common to installing software from source, or from binary distributions that are not fully fledged OS packages. This cookbook started its life as a modified version of Infochimp's install_from cookbook. It has since been heavily refactored and extended to meet different use cases. @@ -15,8 +17,9 @@ end ``` The provider will: + - fetch it to to `/var/cache/chef/` -- unpack it to the default path (`/usr/local/pig-0.8.0`) +- unpack it to the default path (`/usr/local/pig-0.8.0`) - create a symlink for `:home_dir` (`/usr/local/pig`) pointing to path - add specified binary commands to the environment `PATH` variable @@ -25,40 +28,51 @@ By default, the ark will not run again if the `:path` is not empty. Ark provides At this time ark only handles files available from URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) provider. It does handle local files using the `file://` protocol. ## Requirements + ### Platforms + - Debian/Ubuntu - RHEL/CentOS/Scientific/Oracle - Fedora - FreeBSD - SmartOS - Mac OS X +- openSUSE / SUSE Linux Enterprises +- Windows Should work on common Unix/Linux systems with typical userland utilities like tar, gzip, etc. May require the installation of build tools for compiling from source, but that installation is outside the scope of this cookbook. ### Chef -- Chef 11+ + +- Chef 12.1+ ### Cookbooks + - build-essential - seven_zip - windows ## Attributes + Customize the attributes to suit site specific conventions and defaults. -- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. -- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. -- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. -- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. -- `node['ark']['win_install_dir']` - directory where the files will be put on windows -- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. + +- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. default: `http://apache.mirrors.tds.net` +- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. default: `/usr/local` +- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. default: `/usr/local/bin` +- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. default: `/usr/local` +- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. default: varies based on platform +- `node['ark']['tar']` - allows overriding the default path to the tar binary, which varies based on platform +- `node['ark']['sevenzip_binary']` - allows overriding the default path to the 7zip binary, which is determined based on registry key value ## Resources + - `ark` - does the extract/build/configure dance ### Actions + - `:install`: extracts the file and creates a 'friendly' symbolic link to the extracted directory path - `:configure`: configure ahead of the install action -- `:install_with_make`: extracts the archive to a path, runs `make`, and `make install`. It does _not_ run the configure step at this time +- `:install_with_make`: extracts the archive to a path, runs `configure`, `make`, and `make install`. - `:dump`: strips all directories from the archive and dumps the contained files into a specified path - `:cherry_pick`: extract a specified file from an archive and places in specified path - `:put`: extract the archive to a specified path, does not create any symbolic links @@ -68,34 +82,43 @@ Customize the attributes to suit site specific conventions and defaults. - `:setup_py_install`: runs the command "python setup.py install" in the extracted directory ### :cherry_pick + Extract a specified file from an archive and places in specified path. #### Relevant Attribute Parameters for :cherry_pick + - `path`: directory to place file in. - `creates`: specific file to cherry-pick. ### :dump + Strips all directories from the archive and dumps the contained files into a specified path. NOTE: This currently only works for zip archives #### Attribute Parameters for :dump + - `path`: path to dump files to. - `mode`: file mode for `app_home`, as an integer. + - Example: `0775` - `creates`: if you are appending files to a given directory, ark needs a condition to test whether the file has already been extracted. You can specify with creates, a file whose existence indicates the ark has previously been extracted and does not need to be extracted again. ### :put + Extract the archive to a specified path, does not create any symbolic links. #### Attribute Parameters for :put + - `path`: path to extract to. + - Default: `/usr/local` - `append_env_path`: boolean, if true, append the `./bin` directory of the extracted directory to the global `PATH` variable for all users. ### Attribute Parameters + - `name`: name of the package, defaults to the resource name. - `url`: url for tarball, `.tar.gz`, `.bin` (oracle-specific), `.war`, and `.zip` currently supported. Also supports special syntax - `:name:version:apache_mirror:` that will auto-magically construct download url from the apache mirrors site. @@ -103,35 +126,55 @@ Extract the archive to a specified path, does not create any symbolic links. - `mode`: file mode for `app_home`, is an integer. - `prefix_root`: default `prefix_root`, for use with `:install*` actions. - `prefix_home`: default directory prefix for a friendly symlink to the path. + - Example: `/usr/local/maven` -> `/usr/local/maven-2.2.1` - `prefix_bin`: default directory to place a symlink to a binary command. + - Example: `/opt/bin/mvn` -> `/opt/maven-2.2.1/bin/mvn`, where the `prefix_bin` is `/opt/bin` - `path`: path to extract the ark to. The `:install*` actions overwrite any user-provided values for `:path`. + - Default: `/usr/local/-` for the `:install`, `:install_with_make` actions - `home_dir`: symbolic link to the path `:prefix_root/:name-:version`, does not apply to `:dump`, `:put`, or `:cherry_pick` actions. + - Default: `:prefix_root/:name` - `has_binaries`: array of binary commands to symlink into `/usr/local/bin/`, you must specify the relative path. + - Example: `[ 'bin/java', 'bin/javaws' ]` - `append_env_path`: boolean, similar to `has_binaries` but less granular. If true, append the `./bin` directory of the extracted directory to. the `PATH` environment variable for all users, by placing a file in `/etc/profile.d/`. The commands are symbolically linked into `/usr/bin/*`. This option provides more granularity than the boolean option. + - Example: `mvn`, `java`, `javac`, etc. - `environment`: hash of environment variables to pass to invoked shell commands like `tar`, `unzip`, `configure`, and `make`. + - `strip_components`: number of components in path to strip when extracting archive. With default value of `1`, ark strips the leading directory from an archive, which is the default for both `unzip` and `tar` commands. + - `autoconf_opts`: an array of command line options for use with the GNU `autoconf` script. + - Example: `[ '--include=/opt/local/include', '--force' ]` - `make_opts`: an array of command line options for use with `make`. + - Example: `[ '--warn-undefined-variables', '--load-average=2' ]` - `owner`: owner of extracted directory. + - Default: `root` +- `group`: group of extracted directory. + + - Default: `root` + +- `backup`: The number of backups to be kept in /var/chef/backup (for UNIX- and Linux-based platforms) or C:/chef/backup (for the Microsoft Windows platform). Set to false to prevent backups from being kept. + + - Default: `5` + #### Examples + This example copies `ivy.tar.gz` to `/var/cache/chef/ivy-2.2.0.tar.gz`, unpacks its contents to `/usr/local/ivy-2.2.0/` -- stripping the leading directory, and symlinks `/usr/local/ivy` to `/usr/local/ivy-2.2.0` ```ruby @@ -158,7 +201,7 @@ This example copies `jdk-7u2-linux-x64.tar.gz` to `/var/cache/chef/jdk-7.2.tar.g end ``` -Install Apache Ivy dependency resolution tool in /resource_name in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball: +Install Apache Ivy dependency resolution tool in `/resource_name` in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball: ```ruby ark "ivy" do @@ -168,7 +211,7 @@ Install Apache Ivy dependency resolution tool in /resource_name in this ca end ``` -Install Apache Ivy dependency resolution tool in /home/foobar/ivy, strip any leading directory if one exists: +Install Apache Ivy dependency resolution tool in `/home/foobar/ivy`, strip any leading directory if one exists, don't keep backup copies of `ivy.tar.gz`: ```ruby ark "ivy" do @@ -176,10 +219,11 @@ Install Apache Ivy dependency resolution tool in /home/foobar/ivy, strip any lea url 'http://someurl.example.com/ivy.tar.gz' checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5' action :put + backup false end ``` - Strip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist: +Strip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist: ```ruby ark "my_jars" do @@ -217,17 +261,18 @@ Build and install haproxy and use alternative values for `prefix_root`, `prefix_ end ``` -You can also pass multiple actions to ark and supply the file extension in case the file extension can not be determined by the URL: +You can also supply the file extension in case the file extension can not be determined by the URL: ```ruby ark "test_autogen" do url 'https://github.com/zeromq/libzmq/tarball/master' extension "tar.gz" - action [ :configure, :install_with_make ] + action :install_with_make end ``` -## License and Authors +## License & Authors + - Author: Philip (flip) Kromer - Infochimps, Inc([coders@infochimps.com](mailto:coders@infochimps.com)) - Author: Bryan W. Berry ([bryan.berry@gmail.com](mailto:bryan.berry@gmail.com)) - Author: Denis Barishev ([denis.barishev@gmail.com](mailto:denis.barishev@gmail.com)) @@ -236,7 +281,7 @@ You can also pass multiple actions to ark and supply the file extension in case - Copyright: 2011, Philip (flip) Kromer - Infochimps, Inc - Copyright: 2012, Bryan W. Berry - Copyright: 2012, Denis Barishev -- Copyright: 2013, Chef Software, Inc +- Copyright: 2013-2016, Chef Software, Inc - Copyright: 2014, Bloomberg L.P. ``` diff --git a/cookbooks/ark/attributes/default.rb b/cookbooks/ark/attributes/default.rb index 0d427d6..0f44dbd 100644 --- a/cookbooks/ark/attributes/default.rb +++ b/cookbooks/ark/attributes/default.rb @@ -20,24 +20,28 @@ default['ark']['apache_mirror'] = 'http://apache.mirrors.tds.net' default['ark']['prefix_root'] = '/usr/local' default['ark']['prefix_bin'] = '/usr/local/bin' default['ark']['prefix_home'] = '/usr/local' -default['ark']['tar'] = case node['platform_family'] - when 'windows' - "\"#{ENV['SYSTEMDRIVE']}\\7-zip\\7z.exe\"" - when 'mac_os_x', 'freebsd' - '/usr/bin/tar' - when 'smartos' - '/bin/gtar' - else - '/bin/tar' - end -pkgs = %w(libtool autoconf) unless platform_family?('mac_os_x', 'windows') -pkgs += %w(make) unless platform_family?('mac_os_x', 'windows', 'freebsd') -pkgs += %w(unzip rsync gcc) unless platform_family?('mac_os_x', 'windows') -pkgs += %w(autogen) unless platform_family?('rhel', 'fedora', 'mac_os_x', 'suse', 'windows') +# the default path will be determined based on platform, but can be overridden here +default['ark']['tar'] = nil + +# the default path will be determined from the registry, but you may override here +default['ark']['sevenzip_binary'] = nil + +pkgs = %w(libtool autoconf) unless platform_family?('mac_os_x') +pkgs += %w(make) unless platform_family?('mac_os_x', 'freebsd') +pkgs += %w(unzip rsync gcc) unless platform_family?('mac_os_x') +pkgs += %w(autogen) unless platform_family?('rhel', 'fedora', 'mac_os_x', 'suse') pkgs += %w(gtar) if platform?('freebsd') || platform?('smartos') pkgs += %w(gmake) if platform?('freebsd') -pkgs += %w(xz-lzma-compat bzip2 tar) if platform_family?('rhel', 'fedora') +if platform_family?('rhel', 'suse') + if node['platform_version'].to_i >= 7 + pkgs += %w(xz bzip2 tar) + elsif node['platform_version'].to_i < 7 + pkgs += %w(xz-lzma-compat bzip2 tar) + end +elsif platform_family?('fedora') + pkgs += %w(xz-lzma-compat bzip2 tar) +end pkgs += %w(shtool pkg-config) if platform_family?('debian') default['ark']['package_dependencies'] = pkgs diff --git a/cookbooks/ark/libraries/default.rb b/cookbooks/ark/libraries/default.rb index c1a8e7f..24b09e6 100644 --- a/cookbooks/ark/libraries/default.rb +++ b/cookbooks/ark/libraries/default.rb @@ -43,13 +43,13 @@ module Ark @resource_defaults ||= ::Ark::ResourceDefaults.new(new_resource) end - # rubocop:disable Metrics/AbcSize def set_paths new_resource.extension = defaults.extension new_resource.prefix_bin = defaults.prefix_bin new_resource.prefix_root = defaults.prefix_root new_resource.home_dir = defaults.home_dir new_resource.version = defaults.version + new_resource.owner = defaults.owner # TODO: what happens when the path is already set -- # with the current logic we overwrite it diff --git a/cookbooks/ark/libraries/matchers.rb b/cookbooks/ark/libraries/matchers.rb index 2431a2f..aa8901b 100644 --- a/cookbooks/ark/libraries/matchers.rb +++ b/cookbooks/ark/libraries/matchers.rb @@ -1,5 +1,7 @@ if defined?(ChefSpec) + ChefSpec.define_matcher :ark + def install_ark(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:ark, :install, resource_name) end diff --git a/cookbooks/ark/libraries/resource_defaults.rb b/cookbooks/ark/libraries/resource_defaults.rb index 93574cd..9b5ac76 100644 --- a/cookbooks/ark/libraries/resource_defaults.rb +++ b/cookbooks/ark/libraries/resource_defaults.rb @@ -33,6 +33,10 @@ module Ark end end + def owner + resource.owner || default_owner + end + def windows? node_in_run_context['platform_family'] == 'windows' end @@ -62,13 +66,13 @@ module Ark def generate_extension_from_url(url) # purge any trailing redirect - url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip)(\/.*\/)} + url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip|7z)(\/.*\/)} url.gsub!(Regexp.last_match(2), '') unless Regexp.last_match(2).nil? - # remove tailing query string + # remove trailing query string release_basename = ::File.basename(url.gsub(/\?.*\z/, '')).gsub(/-bin\b/, '') # (\?.*)? accounts for a trailing querystring Chef::Log.debug("DEBUG: release_basename is #{release_basename}") - release_basename =~ /^(.+?)\.(jar|tar\.bz2|tar\.gz|tar\.xz|tbz|tgz|txz|war|zip|tar)(\?.*)?/ + release_basename =~ /^(.+?)\.(jar|tar\.bz2|tar\.gz|tar\.xz|tbz|tgz|txz|war|zip|tar|7z)(\?.*)?/ Chef::Log.debug("DEBUG: file_extension is #{Regexp.last_match(2)}") Regexp.last_match(2) end @@ -86,7 +90,22 @@ module Ark end def default_version - "1" + '1' + end + + def default_owner + if windows? + wmi_property_from_query(:name, "select * from Win32_UserAccount where sid like 'S-1-5-21-%-500' and LocalAccount=True") + else + 'root' + end + end + + def wmi_property_from_query(wmi_property, wmi_query) + @wmi = ::WIN32OLE.connect('winmgmts://') + result = @wmi.ExecQuery(wmi_query) + return nil unless result.each.count > 0 + result.each.next.send(wmi_property) end def file_cache_path diff --git a/cookbooks/ark/libraries/resource_deprecations.rb b/cookbooks/ark/libraries/resource_deprecations.rb index 66ae2a0..9a4fc47 100644 --- a/cookbooks/ark/libraries/resource_deprecations.rb +++ b/cookbooks/ark/libraries/resource_deprecations.rb @@ -27,7 +27,7 @@ module Ark end def strip_leading_dir_feature_message - "strip_leading_dir attribute was deprecated. Use strip_components instead." + 'strip_leading_dir attribute was deprecated. Use strip_components instead.' end end end diff --git a/cookbooks/ark/libraries/sevenzip_command_builder.rb b/cookbooks/ark/libraries/sevenzip_command_builder.rb index ff7a40f..7319a0e 100644 --- a/cookbooks/ark/libraries/sevenzip_command_builder.rb +++ b/cookbooks/ark/libraries/sevenzip_command_builder.rb @@ -9,7 +9,7 @@ module Ark end def cherry_pick - "#{sevenzip_command_builder(resource.path, 'e')} -r #{resource.creates}" + "#{sevenzip_command_builder(resource.path, 'x')} -r #{resource.creates}" end def initialize(resource) @@ -20,30 +20,42 @@ module Ark attr_reader :resource - # rubocop:disable Metrics/AbcSize + def node + resource.run_context.node + end + def sevenzip_command if resource.strip_components <= 0 - sevenzip_command_builder(resource.path, 'x') - return + return sevenzip_command_builder(resource.path, 'x') end - tmpdir = make_temp_directory - cmd = sevenzip_command_builder(tmpdir, 'e') + tmpdir = make_temp_directory.tr('/', '\\') + cmd = sevenzip_command_builder(tmpdir, 'x') - cmd += " && " - currdir = tmpdir.tr('/', '\\') + cmd += ' && ' + currdir = tmpdir 1.upto(resource.strip_components).each do |count| cmd += "for /f %#{count} in ('dir /ad /b \"#{currdir}\"') do " currdir += "\\%#{count}" end - cmd += "xcopy \"#{currdir}\" \"#{resource.home_dir}\" /s /e" + cmd += "(\"#{ENV.fetch('SystemRoot')}\\System32\\robocopy\" \"#{currdir}\" \"#{resource.path}\" /s /e) ^& IF %ERRORLEVEL% LEQ 3 cmd /c exit 0" end - # rubocop:enable Metrics/AbcSize def sevenzip_binary - resource.run_context.node['ark']['tar'] + @tar_binary ||= "\"#{(node['ark']['sevenzip_binary'] || sevenzip_path_from_registry)}\"" + end + + def sevenzip_path_from_registry + begin + basepath = ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').read_s('Path') + + # users like pretty errors + rescue ::Win32::Registry::Error + raise 'Failed to find the path of 7zip binary by searching checking HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path. Make sure to install 7zip before using this resource. If 7zip is installed and you still receive this message you can also specify the 7zip binary path by setting node["ark"]["sevenzip_binary"]' + end + "#{basepath}7z.exe" end def sevenzip_command_builder(dir, command) @@ -54,7 +66,7 @@ module Ark if resource.extension =~ /tar.gz|tgz|tar.bz2|tbz|tar.xz|txz/ " -so | #{sevenzip_binary} x -aoa -si -ttar" else - "" + ' -aoa' # force overwrite, Fixes #164 end end diff --git a/cookbooks/ark/libraries/tar_command_builder.rb b/cookbooks/ark/libraries/tar_command_builder.rb index e9cda0d..291dbb9 100644 --- a/cookbooks/ark/libraries/tar_command_builder.rb +++ b/cookbooks/ark/libraries/tar_command_builder.rb @@ -25,21 +25,28 @@ module Ark end def tar_binary - resource.run_context.node['ark']['tar'] + @tar_binary ||= node['ark']['tar'] || case node['platform_family'] + when 'mac_os_x', 'freebsd' + '/usr/bin/tar' + when 'smartos' + '/bin/gtar' + else + '/bin/tar' + end end def args case resource.extension - when /^(tar)$/ then "xf" - when /^(tar.gz|tgz)$/ then "xzf" - when /^(tar.bz2|tbz)$/ then "xjf" - when /^(tar.xz|txz)$/ then "xJf" + when /^(tar)$/ then 'xf' + when /^(tar.gz|tgz)$/ then 'xzf' + when /^(tar.bz2|tbz)$/ then 'xjf' + when /^(tar.xz|txz)$/ then 'xJf' else raise unsupported_extension end end def strip_args - resource.strip_components > 0 ? " --strip-components=#{resource.strip_components}" : "" + resource.strip_components > 0 ? " --strip-components=#{resource.strip_components}" : '' end def unsupported_extension diff --git a/cookbooks/ark/libraries/unzip_command_builder.rb b/cookbooks/ark/libraries/unzip_command_builder.rb index 1c1f4ef..7605f5c 100644 --- a/cookbooks/ark/libraries/unzip_command_builder.rb +++ b/cookbooks/ark/libraries/unzip_command_builder.rb @@ -12,18 +12,16 @@ module Ark "unzip -j -q -o \"#{resource.release_file}\" -d \"#{resource.path}\"" end - # rubocop:disable Metrics/AbcSize def cherry_pick cmd = "unzip -t #{resource.release_file} \"*/#{resource.creates}\" ; stat=$? ;" - cmd += "if [ $stat -eq 11 ] ; then " + cmd += 'if [ $stat -eq 11 ] ; then ' cmd += "unzip -j -o #{resource.release_file} \"#{resource.creates}\" -d #{resource.path} ;" - cmd += "elif [ $stat -ne 0 ] ; then false ;" - cmd += "else " + cmd += 'elif [ $stat -ne 0 ] ; then false ;' + cmd += 'else ' cmd += "unzip -j -o #{resource.release_file} \"*/#{resource.creates}\" -d #{resource.path} ;" - cmd += "fi" + cmd += 'fi' cmd end - # rubocop:enable Metrics/AbcSize def initialize(resource) @resource = resource diff --git a/cookbooks/ark/libraries/windows_owner.rb b/cookbooks/ark/libraries/windows_owner.rb index e5c3ffd..f548b34 100644 --- a/cookbooks/ark/libraries/windows_owner.rb +++ b/cookbooks/ark/libraries/windows_owner.rb @@ -7,7 +7,7 @@ module Ark attr_reader :resource def command - "icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\"" + "#{ENV.fetch('SystemRoot')}\\System32\\icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\"" end end end diff --git a/cookbooks/ark/metadata.json b/cookbooks/ark/metadata.json index 8857c95..d3ba1cf 100644 --- a/cookbooks/ark/metadata.json +++ b/cookbooks/ark/metadata.json @@ -1 +1 @@ -{"name":"ark","version":"1.0.1","description":"Provides a custom resource for installing runtime artifacts in a predictable fashion","long_description":"# ark cookbook\n[![Build Status](https://travis-ci.org/burtlo/ark.svg?branch=master)](https://travis-ci.org/burtlo/ark) [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark)\n\n## Overview\nThis cookbook provides `ark`, a resource for managing software archives. It manages the fetch-unpack-configure-build-install process common to installing software from source, or from binary distributions that are not fully fledged OS packages.\n\nThis cookbook started its life as a modified version of Infochimp's install_from cookbook. It has since been heavily refactored and extended to meet different use cases.\n\nGiven a simple project archive available at a url:\n\n```ruby\nark 'pig' do\n url 'http://apache.org/pig/pig-0.8.0.tar.gz'\nend\n```\n\nThe provider will:\n- fetch it to to `/var/cache/chef/`\n- unpack it to the default path (`/usr/local/pig-0.8.0`)\n- create a symlink for `:home_dir` (`/usr/local/pig`) pointing to path\n- add specified binary commands to the environment `PATH` variable\n\nBy default, the ark will not run again if the `:path` is not empty. Ark provides many actions to accommodate different use cases, such as `:dump`, `:cherry_pick`, `:put`, and `:install_with_make`.\n\nAt this time ark only handles files available from URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) provider. It does handle local files using the `file://` protocol.\n\n## Requirements\n### Platforms\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Oracle\n- Fedora\n- FreeBSD\n- SmartOS\n- Mac OS X\n\nShould work on common Unix/Linux systems with typical userland utilities like tar, gzip, etc. May require the installation of build tools for compiling from source, but that installation is outside the scope of this cookbook.\n\n### Chef\n- Chef 11+\n\n### Cookbooks\n- build-essential\n- seven_zip\n- windows\n\n## Attributes\nCustomize the attributes to suit site specific conventions and defaults.\n- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default.\n- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource.\n- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource.\n- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource.\n- `node['ark']['win_install_dir']` - directory where the files will be put on windows\n- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark.\n\n## Resources\n- `ark` - does the extract/build/configure dance\n\n### Actions\n- `:install`: extracts the file and creates a 'friendly' symbolic link to the extracted directory path\n- `:configure`: configure ahead of the install action\n- `:install_with_make`: extracts the archive to a path, runs `make`, and `make install`. It does _not_ run the configure step at this time\n- `:dump`: strips all directories from the archive and dumps the contained files into a specified path\n- `:cherry_pick`: extract a specified file from an archive and places in specified path\n- `:put`: extract the archive to a specified path, does not create any symbolic links\n- `:remove`: removes the extracted directory and related symlink #TODO\n- `:setup_py`: runs the command \"python setup.py\" in the extracted directory\n- `:setup_py_build`: runs the command \"python setup.py build\" in the extracted directory\n- `:setup_py_install`: runs the command \"python setup.py install\" in the extracted directory\n\n### :cherry_pick\nExtract a specified file from an archive and places in specified path.\n\n#### Relevant Attribute Parameters for :cherry_pick\n- `path`: directory to place file in.\n- `creates`: specific file to cherry-pick.\n\n### :dump\nStrips all directories from the archive and dumps the contained files into a specified path.\n\nNOTE: This currently only works for zip archives\n\n#### Attribute Parameters for :dump\n- `path`: path to dump files to.\n- `mode`: file mode for `app_home`, as an integer.\n - Example: `0775`\n\n- `creates`: if you are appending files to a given directory, ark needs a condition to test whether the file has already been extracted. You can specify with creates, a file whose existence indicates the ark has previously been extracted and does not need to be extracted again.\n\n### :put\nExtract the archive to a specified path, does not create any symbolic links.\n\n#### Attribute Parameters for :put\n- `path`: path to extract to.\n - Default: `/usr/local`\n\n- `append_env_path`: boolean, if true, append the `./bin` directory of the extracted directory to the global `PATH` variable for all users.\n\n### Attribute Parameters\n- `name`: name of the package, defaults to the resource name.\n- `url`: url for tarball, `.tar.gz`, `.bin` (oracle-specific), `.war`, and `.zip` currently supported. Also supports special syntax\n- `:name:version:apache_mirror:` that will auto-magically construct download url from the apache mirrors site.\n- `version`: software version, defaults to `1`.\n- `mode`: file mode for `app_home`, is an integer.\n- `prefix_root`: default `prefix_root`, for use with `:install*` actions.\n- `prefix_home`: default directory prefix for a friendly symlink to the path.\n - Example: `/usr/local/maven` -> `/usr/local/maven-2.2.1`\n\n- `prefix_bin`: default directory to place a symlink to a binary command.\n - Example: `/opt/bin/mvn` -> `/opt/maven-2.2.1/bin/mvn`, where the `prefix_bin` is `/opt/bin`\n\n- `path`: path to extract the ark to. The `:install*` actions overwrite any user-provided values for `:path`.\n - Default: `/usr/local/-` for the `:install`, `:install_with_make` actions\n\n- `home_dir`: symbolic link to the path `:prefix_root/:name-:version`, does not apply to `:dump`, `:put`, or `:cherry_pick` actions.\n - Default: `:prefix_root/:name`\n\n- `has_binaries`: array of binary commands to symlink into `/usr/local/bin/`, you must specify the relative path.\n - Example: `[ 'bin/java', 'bin/javaws' ]`\n\n- `append_env_path`: boolean, similar to `has_binaries` but less granular. If true, append the `./bin` directory of the extracted directory to. the `PATH` environment variable for all users, by placing a file in `/etc/profile.d/`. The commands are symbolically linked into `/usr/bin/*`. This option provides more granularity than the boolean option.\n - Example: `mvn`, `java`, `javac`, etc.\n\n- `environment`: hash of environment variables to pass to invoked shell commands like `tar`, `unzip`, `configure`, and `make`.\n- `strip_components`: number of components in path to strip when extracting archive. With default value of `1`, ark strips the leading directory from an archive, which is the default for both `unzip` and `tar` commands.\n- `autoconf_opts`: an array of command line options for use with the GNU `autoconf` script.\n - Example: `[ '--include=/opt/local/include', '--force' ]`\n\n- `make_opts`: an array of command line options for use with `make`.\n - Example: `[ '--warn-undefined-variables', '--load-average=2' ]`\n\n- `owner`: owner of extracted directory.\n - Default: `root`\n\n#### Examples\nThis example copies `ivy.tar.gz` to `/var/cache/chef/ivy-2.2.0.tar.gz`, unpacks its contents to `/usr/local/ivy-2.2.0/` -- stripping the leading directory, and symlinks `/usr/local/ivy` to `/usr/local/ivy-2.2.0`\n\n```ruby\n # install Apache Ivy dependency resolution tool\n ark \"ivy\" do\n url 'http://someurl.example.com/ivy.tar.gz'\n version '2.2.0'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :install\n end\n```\n\nThis example copies `jdk-7u2-linux-x64.tar.gz` to `/var/cache/chef/jdk-7.2.tar.gz`, unpacks its contents to `/usr/local/jvm/jdk-7.2/` -- stripping the leading directory, symlinks `/usr/local/jvm/default` to `/usr/local/jvm/jdk-7.2`, and adds `/usr/local/jvm/jdk-7.2/bin/` to the global `PATH` for all users. The user 'foobar' is the owner of the `/usr/local/jvm/jdk-7.2` directory:\n\n```ruby\n ark 'jdk' do\n url 'http://download.example.com/jdk-7u2-linux-x64.tar.gz'\n version '7.2'\n path \"/usr/local/jvm/\"\n home_dir \"/usr/local/jvm/default\"\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n append_env_path true\n owner 'foobar'\n end\n```\n\nInstall Apache Ivy dependency resolution tool in /resource_name in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball:\n\n```ruby\n ark \"ivy\" do\n url 'http://someurl.example.com/ivy.tar.gz'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :put\n end\n```\n\nInstall Apache Ivy dependency resolution tool in /home/foobar/ivy, strip any leading directory if one exists:\n\n```ruby\n ark \"ivy\" do\n path \"/home/foobar\"\n url 'http://someurl.example.com/ivy.tar.gz'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :put\n end\n```\n\n Strip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist:\n\n```ruby\n ark \"my_jars\" do\n url \"http://example.com/bunch_of_jars.zip\"\n path \"/usr/local/tomcat/lib\"\n creates \"mysql.jar\"\n owner \"tomcat\"\n action :dump\n end\n```\n\nExtract specific files from a tarball (currently only handles one named file):\n\n```ruby\n ark 'mysql-connector-java' do\n url 'http://oracle.com/mysql-connector.zip'\n creates 'mysql-connector-java-5.0.8-bin.jar'\n path '/usr/local/tomcat/lib'\n action :cherry_pick\n end\n```\n\nBuild and install haproxy and use alternative values for `prefix_root`, `prefix_home`, and `prefix_bin`:\n\n```ruby\n ark \"haproxy\" do\n url \"http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz\"\n version \"1.5\"\n checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911'\n make_opts [ 'TARGET=linux26' ]\n prefix_root '/opt'\n prefix_home '/opt'\n prefix_bin '/opt/bin'\n action :install_with_make\n end\n```\n\nYou can also pass multiple actions to ark and supply the file extension in case the file extension can not be determined by the URL:\n\n```ruby\n ark \"test_autogen\" do\n url 'https://github.com/zeromq/libzmq/tarball/master'\n extension \"tar.gz\"\n action [ :configure, :install_with_make ]\n end\n```\n\n## License and Authors\n- Author: Philip (flip) Kromer - Infochimps, Inc([coders@infochimps.com](mailto:coders@infochimps.com))\n- Author: Bryan W. Berry ([bryan.berry@gmail.com](mailto:bryan.berry@gmail.com))\n- Author: Denis Barishev ([denis.barishev@gmail.com](mailto:denis.barishev@gmail.com))\n- Author: Sean OMeara ([someara@chef.io](mailto:someara@chef.io))\n- Author: John Bellone ([jbellone@bloomberg.net](mailto:jbellone@bloomberg.net))\n- Copyright: 2011, Philip (flip) Kromer - Infochimps, Inc\n- Copyright: 2012, Bryan W. Berry\n- Copyright: 2012, Denis Barishev\n- Copyright: 2013, Chef Software, Inc\n- Copyright: 2014, Bloomberg L.P.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Franklin Webber","maintainer_email":"frank@chef.io","license":"Apache 2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","suse":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","amazon":">= 0.0.0","windows":">= 0.0.0","mac_os_x":">= 0.0.0","smartos":">= 0.0.0","freebsd":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","windows":">= 0.0.0","seven_zip":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"ark::default":"Installs packages needed by the custom resource"}} \ No newline at end of file +{"name":"ark","version":"2.2.1","description":"Provides a custom resource for installing runtime artifacts in a predictable fashion","long_description":"# ark cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/ark.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ark) [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark)\n\n## Overview\n\nThis cookbook provides `ark`, a resource for managing software archives. It manages the fetch-unpack-configure-build-install process common to installing software from source, or from binary distributions that are not fully fledged OS packages.\n\nThis cookbook started its life as a modified version of Infochimp's install_from cookbook. It has since been heavily refactored and extended to meet different use cases.\n\nGiven a simple project archive available at a url:\n\n```ruby\nark 'pig' do\n url 'http://apache.org/pig/pig-0.8.0.tar.gz'\nend\n```\n\nThe provider will:\n\n- fetch it to to `/var/cache/chef/`\n- unpack it to the default path (`/usr/local/pig-0.8.0`)\n- create a symlink for `:home_dir` (`/usr/local/pig`) pointing to path\n- add specified binary commands to the environment `PATH` variable\n\nBy default, the ark will not run again if the `:path` is not empty. Ark provides many actions to accommodate different use cases, such as `:dump`, `:cherry_pick`, `:put`, and `:install_with_make`.\n\nAt this time ark only handles files available from URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) provider. It does handle local files using the `file://` protocol.\n\n## Requirements\n\n### Platforms\n\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Oracle\n- Fedora\n- FreeBSD\n- SmartOS\n- Mac OS X\n- openSUSE / SUSE Linux Enterprises\n- Windows\n\nShould work on common Unix/Linux systems with typical userland utilities like tar, gzip, etc. May require the installation of build tools for compiling from source, but that installation is outside the scope of this cookbook.\n\n### Chef\n\n- Chef 12.1+\n\n### Cookbooks\n\n- build-essential\n- seven_zip\n- windows\n\n## Attributes\n\nCustomize the attributes to suit site specific conventions and defaults.\n\n- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. default: `http://apache.mirrors.tds.net`\n- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. default: `/usr/local`\n- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. default: `/usr/local/bin`\n- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. default: `/usr/local`\n- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. default: varies based on platform\n- `node['ark']['tar']` - allows overriding the default path to the tar binary, which varies based on platform\n- `node['ark']['sevenzip_binary']` - allows overriding the default path to the 7zip binary, which is determined based on registry key value\n\n## Resources\n\n- `ark` - does the extract/build/configure dance\n\n### Actions\n\n- `:install`: extracts the file and creates a 'friendly' symbolic link to the extracted directory path\n- `:configure`: configure ahead of the install action\n- `:install_with_make`: extracts the archive to a path, runs `configure`, `make`, and `make install`.\n- `:dump`: strips all directories from the archive and dumps the contained files into a specified path\n- `:cherry_pick`: extract a specified file from an archive and places in specified path\n- `:put`: extract the archive to a specified path, does not create any symbolic links\n- `:remove`: removes the extracted directory and related symlink #TODO\n- `:setup_py`: runs the command \"python setup.py\" in the extracted directory\n- `:setup_py_build`: runs the command \"python setup.py build\" in the extracted directory\n- `:setup_py_install`: runs the command \"python setup.py install\" in the extracted directory\n\n### :cherry_pick\n\nExtract a specified file from an archive and places in specified path.\n\n#### Relevant Attribute Parameters for :cherry_pick\n\n- `path`: directory to place file in.\n- `creates`: specific file to cherry-pick.\n\n### :dump\n\nStrips all directories from the archive and dumps the contained files into a specified path.\n\nNOTE: This currently only works for zip archives\n\n#### Attribute Parameters for :dump\n\n- `path`: path to dump files to.\n- `mode`: file mode for `app_home`, as an integer.\n\n - Example: `0775`\n\n- `creates`: if you are appending files to a given directory, ark needs a condition to test whether the file has already been extracted. You can specify with creates, a file whose existence indicates the ark has previously been extracted and does not need to be extracted again.\n\n### :put\n\nExtract the archive to a specified path, does not create any symbolic links.\n\n#### Attribute Parameters for :put\n\n- `path`: path to extract to.\n\n - Default: `/usr/local`\n\n- `append_env_path`: boolean, if true, append the `./bin` directory of the extracted directory to the global `PATH` variable for all users.\n\n### Attribute Parameters\n\n- `name`: name of the package, defaults to the resource name.\n- `url`: url for tarball, `.tar.gz`, `.bin` (oracle-specific), `.war`, and `.zip` currently supported. Also supports special syntax\n- `:name:version:apache_mirror:` that will auto-magically construct download url from the apache mirrors site.\n- `version`: software version, defaults to `1`.\n- `mode`: file mode for `app_home`, is an integer.\n- `prefix_root`: default `prefix_root`, for use with `:install*` actions.\n- `prefix_home`: default directory prefix for a friendly symlink to the path.\n\n - Example: `/usr/local/maven` -> `/usr/local/maven-2.2.1`\n\n- `prefix_bin`: default directory to place a symlink to a binary command.\n\n - Example: `/opt/bin/mvn` -> `/opt/maven-2.2.1/bin/mvn`, where the `prefix_bin` is `/opt/bin`\n\n- `path`: path to extract the ark to. The `:install*` actions overwrite any user-provided values for `:path`.\n\n - Default: `/usr/local/-` for the `:install`, `:install_with_make` actions\n\n- `home_dir`: symbolic link to the path `:prefix_root/:name-:version`, does not apply to `:dump`, `:put`, or `:cherry_pick` actions.\n\n - Default: `:prefix_root/:name`\n\n- `has_binaries`: array of binary commands to symlink into `/usr/local/bin/`, you must specify the relative path.\n\n - Example: `[ 'bin/java', 'bin/javaws' ]`\n\n- `append_env_path`: boolean, similar to `has_binaries` but less granular. If true, append the `./bin` directory of the extracted directory to. the `PATH` environment variable for all users, by placing a file in `/etc/profile.d/`. The commands are symbolically linked into `/usr/bin/*`. This option provides more granularity than the boolean option.\n\n - Example: `mvn`, `java`, `javac`, etc.\n\n- `environment`: hash of environment variables to pass to invoked shell commands like `tar`, `unzip`, `configure`, and `make`.\n\n- `strip_components`: number of components in path to strip when extracting archive. With default value of `1`, ark strips the leading directory from an archive, which is the default for both `unzip` and `tar` commands.\n\n- `autoconf_opts`: an array of command line options for use with the GNU `autoconf` script.\n\n - Example: `[ '--include=/opt/local/include', '--force' ]`\n\n- `make_opts`: an array of command line options for use with `make`.\n\n - Example: `[ '--warn-undefined-variables', '--load-average=2' ]`\n\n- `owner`: owner of extracted directory.\n\n - Default: `root`\n\n- `group`: group of extracted directory.\n\n - Default: `root`\n\n- `backup`: The number of backups to be kept in /var/chef/backup (for UNIX- and Linux-based platforms) or C:/chef/backup (for the Microsoft Windows platform). Set to false to prevent backups from being kept.\n\n - Default: `5`\n\n#### Examples\n\nThis example copies `ivy.tar.gz` to `/var/cache/chef/ivy-2.2.0.tar.gz`, unpacks its contents to `/usr/local/ivy-2.2.0/` -- stripping the leading directory, and symlinks `/usr/local/ivy` to `/usr/local/ivy-2.2.0`\n\n```ruby\n # install Apache Ivy dependency resolution tool\n ark \"ivy\" do\n url 'http://someurl.example.com/ivy.tar.gz'\n version '2.2.0'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :install\n end\n```\n\nThis example copies `jdk-7u2-linux-x64.tar.gz` to `/var/cache/chef/jdk-7.2.tar.gz`, unpacks its contents to `/usr/local/jvm/jdk-7.2/` -- stripping the leading directory, symlinks `/usr/local/jvm/default` to `/usr/local/jvm/jdk-7.2`, and adds `/usr/local/jvm/jdk-7.2/bin/` to the global `PATH` for all users. The user 'foobar' is the owner of the `/usr/local/jvm/jdk-7.2` directory:\n\n```ruby\n ark 'jdk' do\n url 'http://download.example.com/jdk-7u2-linux-x64.tar.gz'\n version '7.2'\n path \"/usr/local/jvm/\"\n home_dir \"/usr/local/jvm/default\"\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n append_env_path true\n owner 'foobar'\n end\n```\n\nInstall Apache Ivy dependency resolution tool in `/resource_name` in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball:\n\n```ruby\n ark \"ivy\" do\n url 'http://someurl.example.com/ivy.tar.gz'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :put\n end\n```\n\nInstall Apache Ivy dependency resolution tool in `/home/foobar/ivy`, strip any leading directory if one exists, don't keep backup copies of `ivy.tar.gz`:\n\n```ruby\n ark \"ivy\" do\n path \"/home/foobar\"\n url 'http://someurl.example.com/ivy.tar.gz'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :put\n backup false\n end\n```\n\nStrip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist:\n\n```ruby\n ark \"my_jars\" do\n url \"http://example.com/bunch_of_jars.zip\"\n path \"/usr/local/tomcat/lib\"\n creates \"mysql.jar\"\n owner \"tomcat\"\n action :dump\n end\n```\n\nExtract specific files from a tarball (currently only handles one named file):\n\n```ruby\n ark 'mysql-connector-java' do\n url 'http://oracle.com/mysql-connector.zip'\n creates 'mysql-connector-java-5.0.8-bin.jar'\n path '/usr/local/tomcat/lib'\n action :cherry_pick\n end\n```\n\nBuild and install haproxy and use alternative values for `prefix_root`, `prefix_home`, and `prefix_bin`:\n\n```ruby\n ark \"haproxy\" do\n url \"http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz\"\n version \"1.5\"\n checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911'\n make_opts [ 'TARGET=linux26' ]\n prefix_root '/opt'\n prefix_home '/opt'\n prefix_bin '/opt/bin'\n action :install_with_make\n end\n```\n\nYou can also supply the file extension in case the file extension can not be determined by the URL:\n\n```ruby\n ark \"test_autogen\" do\n url 'https://github.com/zeromq/libzmq/tarball/master'\n extension \"tar.gz\"\n action :install_with_make\n end\n```\n\n## License & Authors\n\n- Author: Philip (flip) Kromer - Infochimps, Inc([coders@infochimps.com](mailto:coders@infochimps.com))\n- Author: Bryan W. Berry ([bryan.berry@gmail.com](mailto:bryan.berry@gmail.com))\n- Author: Denis Barishev ([denis.barishev@gmail.com](mailto:denis.barishev@gmail.com))\n- Author: Sean OMeara ([someara@chef.io](mailto:someara@chef.io))\n- Author: John Bellone ([jbellone@bloomberg.net](mailto:jbellone@bloomberg.net))\n- Copyright: 2011, Philip (flip) Kromer - Infochimps, Inc\n- Copyright: 2012, Bryan W. Berry\n- Copyright: 2012, Denis Barishev\n- Copyright: 2013-2016, Chef Software, Inc\n- Copyright: 2014, Bloomberg L.P.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","amazon":">= 0.0.0","windows":">= 0.0.0","mac_os_x":">= 0.0.0","smartos":">= 0.0.0","freebsd":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","windows":">= 0.0.0","seven_zip":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"ark::default":"Installs packages needed by the custom resource"}} \ No newline at end of file diff --git a/cookbooks/ark/providers/default.rb b/cookbooks/ark/providers/default.rb index 49eafcb..7f16a7f 100644 --- a/cookbooks/ark/providers/default.rb +++ b/cookbooks/ark/providers/default.rb @@ -6,7 +6,7 @@ # Author:: Sean OMeara # Copyright 2012, Bryan W. Berry -# Copyright 2013, Chef Software, Inc. +# Copyright 2013-2016, Chef Software, Inc. # Copyright 2014, Bloomberg L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,6 +44,7 @@ action :install do checksum new_resource.checksum if new_resource.checksum action :create notifies :run, "execute[unpack #{new_resource.release_file}]" + backup new_resource.backup end # unpack based on file extension @@ -61,7 +62,7 @@ action :install do action :nothing end - # usually on windows there is no central directory with executables where the applciations are linked + # usually on windows there is no central directory with executables where the applications are linked unless node['platform_family'] == 'windows' # symlink binaries new_resource.has_binaries.each do |bin| @@ -80,7 +81,7 @@ action :install do cookbook 'ark' source 'add_to_path.sh.erb' owner 'root' - group 'root' + group node['root_group'] mode '0755' cookbook 'ark' variables(directory: "#{new_resource.path}/bin") @@ -119,6 +120,7 @@ action :put do checksum new_resource.checksum if new_resource.checksum action :create notifies :run, "execute[unpack #{new_resource.release_file}]" + backup new_resource.backup end # unpack based on file extension diff --git a/cookbooks/ark/recipes/default.rb b/cookbooks/ark/recipes/default.rb index a52cc47..8b5072c 100644 --- a/cookbooks/ark/recipes/default.rb +++ b/cookbooks/ark/recipes/default.rb @@ -18,8 +18,6 @@ # limitations under the License. # -Array(node['ark']['package_dependencies']).each do |pkg| - package pkg -end +package node['ark']['package_dependencies'] unless %w(windows mac_os_x).include?(node['platform_family']) -include_recipe "seven_zip" if node['platform_family'] == 'windows' +include_recipe 'seven_zip' if node['platform_family'] == 'windows' diff --git a/cookbooks/ark/resources/default.rb b/cookbooks/ark/resources/default.rb index 9d6c14d..985d1e8 100644 --- a/cookbooks/ark/resources/default.rb +++ b/cookbooks/ark/resources/default.rb @@ -35,14 +35,15 @@ default_action :install attr_accessor :extension, :home_dir, + :owner, :path, :prefix_bin, :prefix_root, :release_file, :version -attribute :owner, kind_of: String, default: 'root' -attribute :group, kind_of: [String, Fixnum], default: 0 +attribute :owner, kind_of: String, default: nil +attribute :group, kind_of: [String, Integer], default: 0 attribute :url, kind_of: String, required: true attribute :path, kind_of: String, default: nil attribute :full_path, kind_of: String, default: nil @@ -53,7 +54,7 @@ attribute :creates, kind_of: String, default: nil attribute :release_file, kind_of: String, default: '' attribute :strip_leading_dir, kind_of: [TrueClass, FalseClass, NilClass] attribute :strip_components, kind_of: Integer, default: 1 -attribute :mode, kind_of: Fixnum, default: 0755 +attribute :mode, kind_of: Integer, default: 0755 attribute :prefix_root, kind_of: String, default: nil attribute :prefix_home, kind_of: String, default: nil attribute :prefix_bin, kind_of: String, default: nil @@ -66,3 +67,4 @@ attribute :make_opts, kind_of: Array, default: [] attribute :home_dir, kind_of: String, default: nil attribute :autoconf_opts, kind_of: Array, default: [] attribute :extension, kind_of: String +attribute :backup, kind_of: [FalseClass, Integer], default: 5