├── .editorconfig ├── .envrc ├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ ├── ci.yml │ └── stale.yml ├── .gitignore ├── .markdownlint-cli2.yaml ├── .mdlrc ├── .overcommit.yml ├── .vscode └── extensions.json ├── .yamllint ├── Berksfile ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dangerfile ├── LICENSE ├── README.md ├── TESTING.md ├── attributes └── default.rb ├── chefignore ├── documentation └── .gitkeep ├── files └── default │ ├── foo.tar.gz │ ├── foo.tbz │ ├── foo.tgz │ ├── foo.txz │ ├── foo.zip │ ├── foo_sub.tar.gz │ └── foo_sub.zip ├── kitchen.dokken.yml ├── kitchen.exec.yml ├── kitchen.global.yml ├── kitchen.yml ├── libraries ├── default.rb ├── general_owner.rb ├── platform_specific_builders.rb ├── resource_defaults.rb ├── resource_deprecations.rb ├── sevenzip_command_builder.rb ├── tar_command_builder.rb ├── unzip_command_builder.rb └── windows_owner.rb ├── metadata.rb ├── recipes └── default.rb ├── renovate.json ├── resources └── default.rb ├── spec ├── fixtures │ └── cookbooks │ │ └── ark_spec │ │ ├── README.md │ │ ├── metadata.rb │ │ └── recipes │ │ ├── cherry_pick.rb │ │ ├── cherry_pick_with_zip.rb │ │ ├── configure.rb │ │ ├── default.rb │ │ ├── dump.rb │ │ ├── install.rb │ │ ├── install_no_stripping.rb │ │ ├── install_stripping.rb │ │ ├── install_windows.rb │ │ ├── install_with_append_env_path.rb │ │ ├── install_with_binaries.rb │ │ ├── install_with_make.rb │ │ ├── put.rb │ │ ├── setup_py.rb │ │ ├── setup_py_build.rb │ │ ├── setup_py_install.rb │ │ ├── unzip.rb │ │ └── windows.rb ├── libraries │ ├── default_spec.rb │ ├── general_owner_spec.rb │ ├── resource_defaults_spec.rb │ ├── sevenzip_command_builder_spec.rb │ ├── tar_command_builder_spec.rb │ ├── unzip_command_builder_spec.rb │ └── windows_owner_spec.rb ├── recipes │ ├── centos │ │ └── default_spec.rb │ ├── debian │ │ └── default_spec.rb │ ├── default_spec.rb │ ├── fedora │ │ └── default_spec.rb │ ├── freebsd │ │ └── default_spec.rb │ ├── suse │ │ └── default_spec.rb │ ├── ubuntu │ │ └── default_spec.rb │ └── windows │ │ └── default_spec.rb ├── resources │ └── default_spec.rb └── spec_helper.rb └── templates └── add_to_path.sh.erb /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root=true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | indent_style = space 13 | indent_size = 2 14 | 15 | # Avoid issues parsing cookbook files later 16 | charset = utf-8 17 | 18 | # Avoid cookstyle warnings 19 | trim_trailing_whitespace = true 20 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use chefworkstation 2 | export KITCHEN_GLOBAL_YAML=kitchen.global.yml 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @sous-chefs/maintainers 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | 4 | "on": 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | lint-unit: 12 | uses: sous-chefs/.github/.github/workflows/lint-unit.yml@3.1.1 13 | permissions: 14 | actions: write 15 | checks: write 16 | pull-requests: write 17 | statuses: write 18 | issues: write 19 | 20 | integration: 21 | needs: lint-unit 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | os: 26 | - almalinux-8 27 | - amazonlinux-2 28 | - centos-7 29 | - centos-stream-8 30 | - debian-10 31 | - debian-11 32 | - fedora-latest 33 | - opensuse-leap-15 34 | - rockylinux-8 35 | - ubuntu-1804 36 | - ubuntu-2004 37 | suite: 38 | - default 39 | fail-fast: false 40 | 41 | steps: 42 | - name: Check out code 43 | uses: actions/checkout@v4 44 | - name: Install Chef 45 | uses: actionshub/chef-install@3.0.1 46 | - name: Dokken 47 | uses: actionshub/test-kitchen@3.0.0 48 | env: 49 | CHEF_LICENSE: accept-no-persist 50 | KITCHEN_LOCAL_YAML: kitchen.dokken.yml 51 | with: 52 | suite: ${{ matrix.suite }} 53 | os: ${{ matrix.os }} 54 | 55 | integration-windows: 56 | needs: lint-unit 57 | runs-on: windows-latest 58 | strategy: 59 | matrix: 60 | os: 61 | - windows-latest 62 | suite: 63 | - windows 64 | fail-fast: false 65 | 66 | steps: 67 | - name: Check out code 68 | uses: actions/checkout@v4 69 | - name: Install Chef 70 | uses: actionshub/chef-install@3.0.1 71 | - name: test-kitchen 72 | uses: actionshub/test-kitchen@3.0.0 73 | env: 74 | CHEF_LICENSE: accept-no-persist 75 | KITCHEN_LOCAL_YAML: kitchen.exec.yml 76 | with: 77 | suite: ${{ matrix.suite }} 78 | os: ${{ matrix.os }} 79 | 80 | integration-macos: 81 | needs: lint-unit 82 | runs-on: macos-latest 83 | strategy: 84 | matrix: 85 | os: 86 | - macos-latest 87 | suite: 88 | - default 89 | fail-fast: false 90 | 91 | steps: 92 | - name: Check out code 93 | uses: actions/checkout@v4 94 | - name: Install Chef 95 | uses: actionshub/chef-install@3.0.1 96 | - name: test-kitchen 97 | uses: actionshub/test-kitchen@3.0.0 98 | env: 99 | CHEF_LICENSE: accept-no-persist 100 | KITCHEN_LOCAL_YAML: kitchen.exec.yml 101 | with: 102 | suite: ${{ matrix.suite }} 103 | os: ${{ matrix.os }} 104 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Mark stale issues and pull requests 3 | 4 | "on": 5 | schedule: [cron: "0 0 * * *"] 6 | 7 | jobs: 8 | stale: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/stale@v9 12 | with: 13 | repo-token: ${{ secrets.GITHUB_TOKEN }} 14 | close-issue-message: > 15 | Closing due to inactivity. 16 | If this is still an issue please reopen or open another issue. 17 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 18 | Thanks, Sous-Chefs. 19 | days-before-close: 7 20 | days-before-stale: 365 21 | stale-issue-message: > 22 | Marking stale due to inactivity. 23 | Remove stale label or comment or this will be closed in 7 days. 24 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 25 | Thanks, Sous-Chefs. 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | InstalledFiles 4 | pkg 5 | test/tmp 6 | test/version_tmp 7 | tmp 8 | _Store 9 | *~ 10 | *# 11 | .#* 12 | \#*# 13 | *.un~ 14 | *.tmp 15 | *.bk 16 | *.bkup 17 | 18 | # editor files 19 | .idea 20 | .*.sw[a-z] 21 | 22 | # ruby/bundler/rspec files 23 | .ruby-version 24 | .ruby-gemset 25 | .rvmrc 26 | Gemfile.lock 27 | .bundle 28 | *.gem 29 | coverage 30 | spec/reports 31 | 32 | # YARD / rdoc artifacts 33 | .yardoc 34 | _yardoc 35 | doc/ 36 | rdoc 37 | 38 | # chef infra stuff 39 | Berksfile.lock 40 | .kitchen 41 | kitchen.local.yml 42 | vendor/ 43 | .coverage/ 44 | .zero-knife.rb 45 | Policyfile.lock.json 46 | 47 | # vagrant stuff 48 | .vagrant/ 49 | .vagrant.d/ 50 | -------------------------------------------------------------------------------- /.markdownlint-cli2.yaml: -------------------------------------------------------------------------------- 1 | config: 2 | ul-indent: false # MD007 3 | line-length: false # MD013 4 | no-duplicate-heading: false # MD024 5 | reference-links-images: false # MD052 6 | ignores: 7 | - .github/copilot-instructions.md 8 | -------------------------------------------------------------------------------- /.mdlrc: -------------------------------------------------------------------------------- 1 | rules "~MD013", "~MD024", "~MD025" 2 | -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | PreCommit: 3 | TrailingWhitespace: 4 | enabled: true 5 | YamlLint: 6 | enabled: true 7 | required_executable: "yamllint" 8 | ChefSpec: 9 | enabled: true 10 | required_executable: "chef" 11 | command: ["chef", "exec", "rspec"] 12 | Cookstyle: 13 | enabled: true 14 | required_executable: "cookstyle" 15 | command: ["cookstyle"] 16 | MarkdownLint: 17 | enabled: false 18 | required_executable: "npx" 19 | command: ["npx", "markdownlint-cli2", "'**/*.md'"] 20 | include: ["**/*.md"] 21 | 22 | CommitMsg: 23 | HardTabs: 24 | enabled: true 25 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "chef-software.chef", 4 | "rebornix.ruby", 5 | "editorconfig.editorconfig", 6 | "DavidAnson.vscode-markdownlint" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | rules: 4 | line-length: 5 | max: 256 6 | level: warning 7 | document-start: disable 8 | braces: 9 | forbid: false 10 | min-spaces-inside: 0 11 | max-spaces-inside: 1 12 | min-spaces-inside-empty: -1 13 | max-spaces-inside-empty: -1 14 | comments: 15 | min-spaces-from-content: 1 16 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'freebsd' 7 | cookbook 'ark_spec', path: 'spec/fixtures/cookbooks/ark_spec' 8 | end 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # ark Cookbook CHANGELOG 2 | 3 | This file is used to list changes made in each version of the ark cookbook. 4 | 5 | ## Unreleased 6 | 7 | ## 6.0.32 - *2024-12-05* 8 | 9 | ## 6.0.31 - *2024-11-18* 10 | 11 | Standardise files with files in sous-chefs/repo-management 12 | 13 | Standardise files with files in sous-chefs/repo-management 14 | 15 | ## 6.0.30 - *2024-07-15* 16 | 17 | Standardise files with files in sous-chefs/repo-management 18 | 19 | Standardise files with files in sous-chefs/repo-management 20 | 21 | ## 6.0.29 - *2024-05-03* 22 | 23 | ## 6.0.28 - *2024-05-03* 24 | 25 | ## 6.0.27 - *2023-12-21* 26 | 27 | ## 6.0.26 - *2023-10-03* 28 | 29 | - Update README 30 | 31 | ## 6.0.25 - *2023-09-28* 32 | 33 | ## 6.0.24 - *2023-09-04* 34 | 35 | ## 6.0.23 - *2023-09-04* 36 | 37 | ## 6.0.22 - *2023-05-17* 38 | 39 | ## 6.0.21 - *2023-04-17* 40 | 41 | ## 6.0.20 - *2023-04-07* 42 | 43 | Standardise files with files in sous-chefs/repo-management 44 | 45 | ## 6.0.19 - *2023-04-01* 46 | 47 | ## 6.0.18 - *2023-04-01* 48 | 49 | ## 6.0.17 - *2023-04-01* 50 | 51 | Standardise files with files in sous-chefs/repo-management 52 | 53 | ## 6.0.16 - *2023-03-20* 54 | 55 | Standardise files with files in sous-chefs/repo-management 56 | 57 | ## 6.0.15 - *2023-03-02* 58 | 59 | - Remove private Chef boxes 60 | 61 | ## 6.0.14 - *2023-03-01* 62 | 63 | - Update workflows to 2.0.1 64 | - Remove mdl and replace with markdownlint-cli2 65 | 66 | ## 6.0.13 - *2023-02-23* 67 | 68 | Standardise files with files in sous-chefs/repo-management 69 | 70 | ## 6.0.12 - *2023-02-16* 71 | 72 | Standardise files with files in sous-chefs/repo-management 73 | 74 | ## 6.0.11 - *2023-02-15* 75 | 76 | ## 6.0.10 - *2023-02-15* 77 | 78 | Standardise files with files in sous-chefs/repo-management 79 | 80 | ## 6.0.9 - *2023-02-14* 81 | 82 | ## 6.0.8 - *2023-02-14* 83 | 84 | ## 6.0.7 - *2023-02-13* 85 | 86 | ## 6.0.6 - *2023-02-13* 87 | 88 | ## 6.0.5 - *2022-12-15* 89 | 90 | - Standardise files with files in sous-chefs/repo-management 91 | 92 | ## 6.0.4 - *2022-02-03* 93 | 94 | - Update tested platforms 95 | - Remove delivery and move to calling RSpec directly via a reusable workflow 96 | 97 | ## 6.0.3 - *2021-08-30* 98 | 99 | - Standardise files with files in sous-chefs/repo-management 100 | 101 | ## 6.0.2 - *2021-06-18* 102 | 103 | - Update location of test archive fixtures 104 | 105 | ## 6.0.1 - *2021-06-01* 106 | 107 | - Standardise files with files in sous-chefs/repo-management 108 | 109 | ## 6.0.0 - *2021-05-22* 110 | 111 | - Chef 17 updates: enable `unified_mode` on all resources 112 | - Bump required Chef Infra Client to >= 15.3 113 | - Migrate to using `seven_zip_tool` resource directly and require `seven_zip` >= 3.1 114 | - Various ChefSpec fixes 115 | 116 | ## 5.1.1 - *2021-04-29* 117 | 118 | - Added a version pin on seven_zip 119 | 120 | ## 5.1.0 - *2021-01-24* 121 | 122 | - Sous Chefs Adoption 123 | - Standardise files with files in sous-chefs/repo-management 124 | - Cookstyle fixes 125 | - Add integration testing for Windows and MacOS 126 | - Remove testing for Amazon Linux 201x, CentOS 6 and Ubuntu 16.04 127 | - Fix ChefSpec tests 128 | - Fix issues with `--strip-components` with the `:cherry_pick` action on MacOS 129 | - Ensure `/etc/profile.d` exists on MacOS if `append_env_path` is used 130 | 131 | ## 5.0.0 (2020-01-02) 132 | 133 | - Require Chef Infra Client 14+ and remove the need for the build_essential dependency - [@tas50](https://github.com/tas50) 134 | - Use Ruby classes in resource properties - [@tas50](https://github.com/tas50) 135 | - Simplify the platform check logic - [@tas50](https://github.com/tas50) 136 | - Remove the .foocritic file - [@tas50](https://github.com/tas50) 137 | - Remove long_description and recipe metadata - [@tas50](https://github.com/tas50) 138 | - Expand testing - [@tas50](https://github.com/tas50) 139 | - Remove Ubuntu 14.04 testing - [@tas50](https://github.com/tas50) 140 | 141 | ## 4.0.0 (2018-07-25) 142 | 143 | - Support append_env_path property on Windows, which increases the minimum required Chef release to Chef 13.4 144 | 145 | ## 3.1.1 (2018-07-24) 146 | 147 | - Remove ChefSpec matchers since these are autogenerated now 148 | - Update specs to the latest platform versions 149 | - Remove template out of defaults directory 150 | - Remove dependency on the Windows cookbook 151 | 152 | ## 3.1.0 (2017-05-06) 153 | 154 | - Ensure the dependencies get installed on Chef 13 Amazon Linux systems 155 | - Require Chef 12.7+ and remove action_class.class_eval usage 156 | 157 | ## 3.0.0 (2017-04-05) 158 | 159 | - Rewrite of resource to custom resources. 160 | - Remove EOL platforms from testing. 161 | - Update zlib URL 162 | 163 | ## 2.2.1 (2016-12-16) 164 | 165 | - Use Ohai root_group attribute to avoid trying to set the group to root on BSD/macOS. 166 | - Add missing accessor for owner property 167 | 168 | ## 2.2.0 (2016-12-14) 169 | 170 | - Add detection of .7z file extensions 171 | - Fix 7zip extraction using strip_components >= 1 to properly extract to the path instead of the user's home_dir 172 | - Always quote the path to the 7zip and xcopy binaries as they may have spaces 173 | - Clarified in the readme that the install_with_make action includes the configure action 174 | - Fix files with very long paths failing to extract on Windows 175 | - Fix default owner of 'root' failing on Windows 176 | - Fix 7-zip extraction with long paths when strip_components is >= 1 177 | - Add the group attribute parameter to README 178 | - Fix package installation failure on macOS systems 179 | - Use x to extract with 7-zip, not e. Use e only for dump, which strips directories. 180 | 181 | ## 2.1.0 (2016-11-15) 182 | 183 | - Move tar/7zip path logic out of attributes and into helpers to prevent failures when 7zip is not installed before the chef run starts 184 | - Improve platform testing in Test Kitchen 185 | - Recognize Windows as a supported platform in the readme 186 | - Introduce a new attribute for overriding the 7-zip location: node['ark']['sevenzip_binary'] 187 | 188 | ## 2.0.2 (2016-11-03) 189 | 190 | - Fix suse support and centos < 6 191 | 192 | ## 2.1.0 (2016-11-01) 193 | 194 | - Use multipackage installs to speed up installation 195 | - Avoid installation package dependencies on Windows entirely 196 | - Remove the testing bin stubs 197 | 198 | ## 2.0.0 (2016-09-15) 199 | 200 | - Add CentOS 7.2, Fedora 23, and Suse specs 201 | - Add centos 5, debian, and opensuse travis testing 202 | - Add a contributing doc 203 | - Fix cookstyle warnings 204 | - Require Chef 12.1+ 205 | 206 | ## [v1.2.0](https://github.com/chef-cookbooks/ark/tree/v1.2.0) (2016-07-03) 207 | 208 | [Full Changelog](https://github.com/chef-cookbooks/ark/compare/v1.1.0...v1.2.0) 209 | 210 | - Create seven_zip unpack command when strip_components is 0 [#155](https://github.com/chef-cookbooks/ark/pull/155) ([terkill](https://github.com/terkill)) 211 | - Get 7zip path from the windows registry. [#153](https://github.com/chef-cookbooks/ark/pull/153) ([buri17](https://github.com/buri17)) 212 | - Use fullpath for xcopy and icacls. [#152](https://github.com/chef-cookbooks/ark/pull/152) ([buri17](https://github.com/buri17)) 213 | - Define custom matcher helper for notification testing, fixes #139 [#144](https://github.com/chef-cookbooks/ark/pull/144) ([szymonpk](https://github.com/szymonpk)) 214 | 215 | ## v1.1.0 (2016-05-19) 216 | 217 | - Add support for RHEL 7 218 | - Fixes to the readme to clarify actions / properties 219 | - Expose the backup property in remote file to the ark resource 220 | - Transfer the cookbook back to Chef 221 | - Resolve all rubocop warnings 222 | - Add maintainers files and Chef contributing docs 223 | - Test on the latest platforms in .kitchen.yml and update Travis to use kitchen-dokken with additional platforms 224 | 225 | ## v1.0.1 (2016-02-16) 226 | 227 | - Remove a large number of zero byte archives that snuck into the repository 228 | - Remove a Chef 10 compatibility check in the custom resource 229 | 230 | ## v1.0.0 (2016-02-09) 231 | 232 | - Added the pkg-config package to the debian platform family 233 | - Added tar, xz-lzma-compat, and bzip2 packages to the RHEL and fedora platform families 234 | - Updated FreeBSD to install gmake instead of make 235 | - Added OS X, SmartOS, and FreeBSD to the tar path attributes to support those platforms 236 | - Removed the has_binaries attribute from put action documentation in the readme file since this isn't supported there 237 | - Moved the libraries module locations to no longer be under Opscode:: and broke out libraries into more logical units 238 | - Fixed issues with spaces in Windows paths that could cause failures 239 | - Fixed a bad attribute for the 7zip home on windows. Instead of using a node attribute use the value directly to avoid computed attribute overiding issues 240 | - Switched from the 7-zip cookbook to seven_zip since the 7-zip cookbook is now deprecated 241 | - Changed unzip commands to not use -u so that a newer archive can overwrite an existing directory 242 | - Added support for actions py_setup, py_setup_install, py_setup_build 243 | - Fixed setting home_dir attribute 244 | - Added source_url and issues_url to the metadata.rb 245 | - Expanded the supported platforms in metadata.rb 246 | - Removed all references to Opscode 247 | - Improved error logging when an unknown extension is encountered 248 | - Added support for .tar files 249 | - Improved overall testing: 250 | 251 | - Removed the kitchen.cloud.yml file and gem dependencies 252 | - Added integration testing in Travis with Kitchen-Docker and Travis tests now run using the nightly build of ChefDK 253 | - Expanded platforms tested in the .kitchen.yml file 254 | - Updated the Gemfile with the latest testing dependencies 255 | - Added full Chefspec coverage 256 | - Greatly expanded the ark_spec test cookbook 257 | - Removed the original minitests 258 | 259 | - Added standard Chef .gitignore and chefignore files 260 | 261 | - Resolved a large number of rubocop warnings 262 | 263 | - Removed old Opscode contributing and testing docs 264 | 265 | - Added a cookbook version badge to the readme 266 | 267 | - Removed the Toftfile 268 | 269 | ## v0.9.0 (2014-06-06) 270 | 271 | - [COOK-3642] Add Windows support 272 | 273 | ## v0.8.2 (2014-04-23) 274 | 275 | - [COOK-4514] - Support for SLES with the Ark cookbook 276 | 277 | ## v0.8.0 (2014-04-10) 278 | 279 | - [COOK-2771] - Add support for XZ compression 280 | 281 | ## v0.7.2 (2014-03-28) 282 | 283 | - [COOK-4477] - Fix failing test suite 284 | - [COOK-4484] - Replace strip_leading_dir attribute with more general strip_components 285 | 286 | ## v0.7.0 (2014-03-18) 287 | 288 | - [COOK-4437] - configure and install_with_make should chown after unpack 289 | 290 | ## v0.6.0 (2014-02-27) 291 | 292 | [COOK-3786] - Unable to install multiple versions of archive without duplication 293 | 294 | ## v0.5.0 (2014-02-21) 295 | 296 | ### Bug 297 | 298 | - **[COOK-4288](https://tickets.opscode.com/browse/COOK-4288)** - Cleanup the Kitchen 299 | 300 | ### Improvement 301 | 302 | - **[COOK-4264](https://tickets.opscode.com/browse/COOK-4264)** - Add node['ark']['package_dependencies'] to allow tuning packages. 303 | 304 | ## v0.4.2 305 | 306 | ### Improvement 307 | 308 | - **[COOK-3854](https://tickets.opscode.com/browse/COOK-3854)** - Capability with mac_os_x: '/bin/chown' - No such file or directory 309 | - Cleaning up some style for rubucop 310 | - Updating test harness 311 | 312 | ## v0.4.0 313 | 314 | ### Improvement 315 | 316 | - **[COOK-3539](https://tickets.opscode.com/browse/COOK-3539)** - Allow dumping of bz2 and gzip files 317 | 318 | ## v0.3.2 319 | 320 | ### Bug 321 | 322 | - **[COOK-3191](https://tickets.opscode.com/browse/COOK-3191)** - Propogate unzip failures 323 | - **[COOK-3118](https://tickets.opscode.com/browse/COOK-3118)** - Set cookbook attribute in provider 324 | - **[COOK-3055](https://tickets.opscode.com/browse/COOK-3055)** - Use proper scope in helper module 325 | - **[COOK-3054](https://tickets.opscode.com/browse/COOK-3054)** - Fix notification resource updating 326 | 327 | ### Improvement 328 | 329 | - **[COOK-3179](https://tickets.opscode.com/browse/COOK-3179)** - README updates and refactor 330 | 331 | ## v0.3.0 332 | 333 | ### Improvement 334 | 335 | - [COOK-3087]: Can't use ark with chef < 11 336 | 337 | ### Bug 338 | 339 | - [COOK-3064]: `only_if` statements in ark's `install_with_make` and configure actions are not testing for file existence correctly. 340 | - [COOK-3067]: ark kitchen test for `cherry_pick` is expecting the binary to be in the same parent folder as in the archive. 341 | 342 | ## v0.2.4 343 | 344 | ### Bug 345 | 346 | - [COOK-3048]: Ark provider contains a `ruby_block` resource without a block attribute 347 | - [COOK-3063]: Ark cookbook `cherry_pick` action's unzip command does not close if statement 348 | - [COOK-3065]: Ark install action does not symlink binaries correctly 349 | 350 | ## v0.2.2 351 | 352 | - Update the README to reflect the requirement for Chef 11 to use the ark resource (`use_inline_resources`). 353 | - Making this a release so it will also appear on the community site page. 354 | 355 | ## v0.2.0 356 | 357 | ### Bug 358 | 359 | - [COOK-2772]: Ark cookbook has foodcritic failures in provides/default.rb 360 | 361 | ### Improvement 362 | 363 | - [COOK-2520]: Refactor ark providers to use the '`use_inline_resources`' LWRP DSL feature 364 | 365 | ## v0.1.0 366 | 367 | - [COOK-2335] - ark resource broken on Chef 11 368 | 369 | ## v0.0.1 370 | 371 | - [COOK-2026] - Allow `cherry_pick` action to be used for directories as well as files 372 | 373 | ## v0.0.1 374 | 375 | - [COOK-1593] - README formatting updates for better display on Community Site 376 | 377 | ## v0.0.1 378 | 379 | ### Bug 380 | 381 | - dangling "unless" 382 | 383 | ### Improvement 384 | 385 | - add `setup_py_*` actions 386 | - add vagrantfile 387 | - add foodcritic test 388 | - travis.ci support 389 | 390 | ## v0.0.10 (May 23, 2012 391 | 392 | ### Bug 393 | 394 | - `strip_leading_dir` not working for zip files 395 | 396 | ### Improvement 397 | 398 | - use autogen.sh to generate configure script for configure action 399 | - support more file extensions 400 | - add extension attribute which allows you to download files which do not have the file extension as part of the URL 401 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Guidelines 2 | 3 | This project follows the Chef Community Guidelines 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please refer to 4 | [https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD) 5 | -------------------------------------------------------------------------------- /Dangerfile: -------------------------------------------------------------------------------- 1 | # Reference: http://danger.systems/reference.html 2 | 3 | # A pull request summary is required. Add a description of the pull request purpose. 4 | # Changelog must be updated for each pull request that changes code. 5 | # Warnings will be issued for: 6 | # Pull request with more than 400 lines of code changed 7 | # Pull reqest that change more than 5 lines without test changes 8 | # Failures will be issued for: 9 | # Pull request without summary 10 | # Pull requests with code changes without changelog entry 11 | 12 | def code_changes? 13 | code = %w(libraries attributes recipes resources files templates) 14 | code.each do |location| 15 | return true unless git.modified_files.grep(/#{location}/).empty? 16 | end 17 | false 18 | end 19 | 20 | def test_changes? 21 | tests = %w(spec test kitchen.yml kitchen.dokken.yml) 22 | tests.each do |location| 23 | return true unless git.modified_files.grep(/#{location}/).empty? 24 | end 25 | false 26 | end 27 | 28 | failure 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10 29 | 30 | warn 'This is a big Pull Request.' if git.lines_of_code > 400 31 | 32 | warn 'This is a Table Flip.' if git.lines_of_code > 2000 33 | 34 | # Require a CHANGELOG entry for non-test changes. 35 | if !git.modified_files.include?('CHANGELOG.md') && code_changes? 36 | failure 'Please include a CHANGELOG entry.' 37 | end 38 | 39 | # Require Major Minor Patch version labels 40 | unless github.pr_labels.grep /minor|major|patch/i 41 | warn 'Please add a release label to this pull request' 42 | end 43 | 44 | # A sanity check for tests. 45 | if git.lines_of_code > 5 && code_changes? && !test_changes? 46 | warn 'This Pull Request is probably missing tests.' 47 | end 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ark cookbook 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark) 4 | [![CI State](https://github.com/sous-chefs/ark/workflows/ci/badge.svg)](https://github.com/sous-chefs/ark/actions?query=workflow%3Aci) 5 | [![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) 6 | [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | ## Overview 10 | 11 | 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. 12 | 13 | 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. 14 | 15 | Given a simple project archive available at a url: 16 | 17 | ```ruby 18 | ark 'pig' do 19 | url 'http://apache.org/pig/pig-0.8.0.tar.gz' 20 | end 21 | ``` 22 | 23 | The `ark` resource will: 24 | 25 | - fetch it to to `/var/cache/chef/` 26 | - unpack it to the default path (`/usr/local/pig-0.8.0`) 27 | - create a symlink for `:home_dir` (`/usr/local/pig`) pointing to path 28 | - add specified binary commands to the environment `PATH` variable 29 | 30 | By 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`. 31 | 32 | For remote files ark supports URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) resource. Local files are accessed with the `file://` syntax. 33 | 34 | ## Maintainers 35 | 36 | This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). 37 | 38 | ## Requirements 39 | 40 | ### Platforms 41 | 42 | - Debian/Ubuntu 43 | - RHEL/CentOS/Scientific/Oracle 44 | - Fedora 45 | - FreeBSD 46 | - SmartOS 47 | - macOS 48 | - openSUSE / SUSE Linux Enterprises 49 | - Windows 50 | 51 | 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. 52 | 53 | ### Chef 54 | 55 | - Chef 15.3+ 56 | 57 | ### Cookbooks 58 | 59 | - seven_zip 60 | 61 | ## Attributes 62 | 63 | Customize the attributes to suit site specific conventions and defaults. 64 | 65 | - `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. default: `http://apache.mirrors.tds.net` 66 | - `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. default: `/usr/local` 67 | - `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. default: `/usr/local/bin` 68 | - `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. default: `/usr/local` 69 | - `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. default: varies based on platform 70 | - `node['ark']['tar']` - allows overriding the default path to the tar binary, which varies based on platform 71 | - `node['ark']['sevenzip_binary']` - allows overriding the default path to the 7zip binary, which is determined based on registry key value 72 | 73 | ## Resources 74 | 75 | - `ark` - does the extract/build/configure 76 | 77 | ### Actions 78 | 79 | - `:install`: extracts the file and creates a 'friendly' symbolic link to the extracted directory path 80 | - `:configure`: configure ahead of the install action 81 | - `:install_with_make`: extracts the archive to a path, runs `configure`, `make`, and `make install`. 82 | - `:dump`: strips all directories from the archive and dumps the contained files into a specified path 83 | - `:cherry_pick`: extract a specified file from an archive and places in specified path 84 | - `:put`: extract the archive to a specified path, does not create any symbolic links 85 | - `:remove`: removes the extracted directory and related symlink #TODO 86 | - `:setup_py`: runs the command "python setup.py" in the extracted directory 87 | - `:setup_py_build`: runs the command "python setup.py build" in the extracted directory 88 | - `:setup_py_install`: runs the command "python setup.py install" in the extracted directory 89 | 90 | ### Action: cherry_pick 91 | 92 | Extract a specified file from an archive and places in specified path. 93 | 94 | #### Parameters for `cherry_pick` 95 | 96 | - `path`: directory to place file in. 97 | - `creates`: specific file to cherry-pick. 98 | 99 | ### Action: dump 100 | 101 | Strips all directories from the archive and dumps the contained files into a specified path. 102 | 103 | NOTE: This currently only works for zip archives 104 | 105 | #### Parameters for :dump 106 | 107 | - `path`: path to dump files to. 108 | - `mode`: file mode for `app_home`, as an integer. 109 | 110 | - Example: `0775` 111 | 112 | - `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. 113 | 114 | ### Action: put 115 | 116 | Extract the archive to a specified path, does not create any symbolic links. 117 | 118 | #### Parameters for :put 119 | 120 | - `path`: path to extract to. 121 | 122 | - Default: `/usr/local` 123 | 124 | - `append_env_path`: boolean, if true, append the `./bin` directory of the extracted directory to the global `PATH` variable for all users. 125 | 126 | ### Attribute Parameters 127 | 128 | - `name`: name of the package, defaults to the resource name. 129 | - `url`: url for tarball, `.tar.gz`, `.bin` (oracle-specific), `.war`, and `.zip` currently supported. Also supports special syntax 130 | - `:name:version:apache_mirror:` that will auto-magically construct download url from the apache mirrors site. 131 | - `version`: software version, defaults to `1`. 132 | - `mode`: file mode for `app_home`, is an integer. 133 | - `prefix_root`: default `prefix_root`, for use with `:install*` actions. 134 | - `prefix_home`: default directory prefix for a friendly symlink to the path. 135 | 136 | - Example: `/usr/local/maven` -> `/usr/local/maven-2.2.1` 137 | 138 | - `prefix_bin`: default directory to place a symlink to a binary command. 139 | 140 | - Example: `/opt/bin/mvn` -> `/opt/maven-2.2.1/bin/mvn`, where the `prefix_bin` is `/opt/bin` 141 | 142 | - `path`: path to extract the ark to. The `:install*` actions overwrite any user-provided values for `:path`. 143 | 144 | - Default: `/usr/local/-` for the `:install`, `:install_with_make` actions 145 | 146 | - `home_dir`: symbolic link to the path `:prefix_root/:name-:version`, does not apply to `:dump`, `:put`, or `:cherry_pick` actions. 147 | 148 | - Default: `:prefix_root/:name` 149 | 150 | - `has_binaries`: array of binary commands to symlink into `/usr/local/bin/`, you must specify the relative path. 151 | 152 | - Example: `[ 'bin/java', 'bin/javaws' ]` 153 | 154 | - `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. 155 | 156 | - Example: `mvn`, `java`, `javac`, etc. 157 | 158 | - `environment`: hash of environment variables to pass to invoked shell commands like `tar`, `unzip`, `configure`, and `make`. 159 | 160 | - `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. 161 | 162 | - `autoconf_opts`: an array of command line options for use with the GNU `autoconf` script. 163 | 164 | - Example: `[ '--include=/opt/local/include', '--force' ]` 165 | 166 | - `make_opts`: an array of command line options for use with `make`. 167 | 168 | - Example: `[ '--warn-undefined-variables', '--load-average=2' ]` 169 | 170 | - `owner`: owner of extracted directory. 171 | 172 | - Default: `root` 173 | 174 | - `group`: group of extracted directory. 175 | 176 | - Default: `root` 177 | 178 | - `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. 179 | 180 | - Default: `5` 181 | 182 | #### Examples 183 | 184 | 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` 185 | 186 | ```ruby 187 | # install Apache Ivy dependency resolution tool 188 | ark "ivy" do 189 | url 'http://someurl.example.com/ivy.tar.gz' 190 | version '2.2.0' 191 | checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5' 192 | action :install 193 | end 194 | ``` 195 | 196 | This 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: 197 | 198 | ```ruby 199 | ark 'jdk' do 200 | url 'http://download.example.com/jdk-7u2-linux-x64.tar.gz' 201 | version '7.2' 202 | path "/usr/local/jvm/" 203 | home_dir "/usr/local/jvm/default" 204 | checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5' 205 | append_env_path true 206 | owner 'foobar' 207 | end 208 | ``` 209 | 210 | 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: 211 | 212 | ```ruby 213 | ark "ivy" do 214 | url 'http://someurl.example.com/ivy.tar.gz' 215 | checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5' 216 | action :put 217 | end 218 | ``` 219 | 220 | 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`: 221 | 222 | ```ruby 223 | ark "ivy" do 224 | path "/home/foobar" 225 | url 'http://someurl.example.com/ivy.tar.gz' 226 | checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5' 227 | action :put 228 | backup false 229 | end 230 | ``` 231 | 232 | 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: 233 | 234 | ```ruby 235 | ark "my_jars" do 236 | url "http://example.com/bunch_of_jars.zip" 237 | path "/usr/local/tomcat/lib" 238 | creates "mysql.jar" 239 | owner "tomcat" 240 | action :dump 241 | end 242 | ``` 243 | 244 | Extract specific files from a tarball (currently only handles one named file): 245 | 246 | ```ruby 247 | ark 'mysql-connector-java' do 248 | url 'http://oracle.com/mysql-connector.zip' 249 | creates 'mysql-connector-java-5.0.8-bin.jar' 250 | path '/usr/local/tomcat/lib' 251 | action :cherry_pick 252 | end 253 | ``` 254 | 255 | Build and install haproxy and use alternative values for `prefix_root`, `prefix_home`, and `prefix_bin`: 256 | 257 | ```ruby 258 | ark "haproxy" do 259 | url "http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz" 260 | version "1.5" 261 | checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911' 262 | make_opts [ 'TARGET=linux26' ] 263 | prefix_root '/opt' 264 | prefix_home '/opt' 265 | prefix_bin '/opt/bin' 266 | action :install_with_make 267 | end 268 | ``` 269 | 270 | You can also supply the file extension in case the file extension can not be determined by the URL: 271 | 272 | ```ruby 273 | ark "test_autogen" do 274 | url 'https://github.com/zeromq/libzmq/tarball/master' 275 | extension "tar.gz" 276 | action :install_with_make 277 | end 278 | ``` 279 | 280 | ## Contributors 281 | 282 | This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) 283 | 284 | ### Backers 285 | 286 | Thank you to all our backers! 287 | 288 | ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) 289 | 290 | ### Sponsors 291 | 292 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. 293 | 294 | ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) 295 | ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) 296 | ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) 297 | ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) 298 | ![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) 299 | ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) 300 | ![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) 301 | ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) 302 | ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) 303 | ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) 304 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). 4 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ark 3 | # Attributes:: default 4 | # 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | default['ark']['apache_mirror'] = 'http://apache.mirrors.tds.net' 20 | default['ark']['prefix_root'] = '/usr/local' 21 | default['ark']['prefix_bin'] = '/usr/local/bin' 22 | default['ark']['prefix_home'] = '/usr/local' 23 | 24 | # the default path will be determined based on platform, but can be overridden here 25 | default['ark']['tar'] = nil 26 | 27 | # the default path will be determined from the registry, but you may override here 28 | default['ark']['sevenzip_binary'] = nil 29 | 30 | pkgs = %w(libtool autoconf) unless platform_family?('mac_os_x') 31 | pkgs += %w(make) unless platform_family?('mac_os_x', 'freebsd') 32 | pkgs += %w(unzip rsync gcc) unless platform_family?('mac_os_x') 33 | pkgs += %w(autogen) unless platform_family?('rhel', 'fedora', 'mac_os_x', 'suse', 'amazon') 34 | pkgs += %w(gtar) if platform?('freebsd', 'smartos') 35 | pkgs += %w(gmake) if platform?('freebsd') 36 | if platform_family?('rhel', 'suse', 'amazon') 37 | if node['platform_version'].to_i >= 7 38 | pkgs += %w(xz bzip2 tar) 39 | elsif node['platform_version'].to_i < 7 40 | pkgs += %w(xz-lzma-compat bzip2 tar) 41 | end 42 | elsif platform_family?('fedora') 43 | pkgs += %w(xz-lzma-compat bzip2 tar) 44 | end 45 | pkgs += %w(shtool pkg-config) if platform_family?('debian') 46 | 47 | default['ark']['package_dependencies'] = pkgs 48 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a Chef Infra Server or Supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | ehthumbs.db 9 | Icon? 10 | nohup.out 11 | Thumbs.db 12 | .envrc 13 | 14 | # EDITORS # 15 | ########### 16 | .#* 17 | .project 18 | .settings 19 | *_flymake 20 | *_flymake.* 21 | *.bak 22 | *.sw[a-z] 23 | *.tmproj 24 | *~ 25 | \#* 26 | REVISION 27 | TAGS* 28 | tmtags 29 | .vscode 30 | .editorconfig 31 | 32 | ## COMPILED ## 33 | ############## 34 | *.class 35 | *.com 36 | *.dll 37 | *.exe 38 | *.o 39 | *.pyc 40 | *.so 41 | */rdoc/ 42 | a.out 43 | mkmf.log 44 | 45 | # Testing # 46 | ########### 47 | .circleci/* 48 | .codeclimate.yml 49 | .delivery/* 50 | .foodcritic 51 | .kitchen* 52 | .mdlrc 53 | .overcommit.yml 54 | .rspec 55 | .rubocop.yml 56 | .travis.yml 57 | .watchr 58 | .yamllint 59 | azure-pipelines.yml 60 | Dangerfile 61 | examples/* 62 | features/* 63 | Guardfile 64 | kitchen*.yml 65 | mlc_config.json 66 | Procfile 67 | Rakefile 68 | spec/* 69 | test/* 70 | 71 | # SCM # 72 | ####### 73 | .git 74 | .gitattributes 75 | .gitconfig 76 | .github/* 77 | .gitignore 78 | .gitkeep 79 | .gitmodules 80 | .svn 81 | */.bzr/* 82 | */.git 83 | */.hg/* 84 | */.svn/* 85 | 86 | # Berkshelf # 87 | ############# 88 | Berksfile 89 | Berksfile.lock 90 | cookbooks/* 91 | tmp 92 | 93 | # Bundler # 94 | ########### 95 | vendor/* 96 | Gemfile 97 | Gemfile.lock 98 | 99 | # Policyfile # 100 | ############## 101 | Policyfile.rb 102 | Policyfile.lock.json 103 | 104 | # Documentation # 105 | ############# 106 | CODE_OF_CONDUCT* 107 | CONTRIBUTING* 108 | documentation/* 109 | TESTING* 110 | UPGRADING* 111 | 112 | # Vagrant # 113 | ########### 114 | .vagrant 115 | Vagrantfile 116 | -------------------------------------------------------------------------------- /documentation/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/documentation/.gitkeep -------------------------------------------------------------------------------- /files/default/foo.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo.tar.gz -------------------------------------------------------------------------------- /files/default/foo.tbz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo.tbz -------------------------------------------------------------------------------- /files/default/foo.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo.tgz -------------------------------------------------------------------------------- /files/default/foo.txz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo.txz -------------------------------------------------------------------------------- /files/default/foo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo.zip -------------------------------------------------------------------------------- /files/default/foo_sub.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo_sub.tar.gz -------------------------------------------------------------------------------- /files/default/foo_sub.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/files/default/foo_sub.zip -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: { name: dokken } 7 | provisioner: { name: dokken } 8 | 9 | platforms: 10 | - name: almalinux-8 11 | driver: 12 | image: dokken/almalinux-8 13 | pid_one_command: /usr/lib/systemd/systemd 14 | 15 | - name: almalinux-9 16 | driver: 17 | image: dokken/almalinux-9 18 | pid_one_command: /usr/lib/systemd/systemd 19 | 20 | - name: almalinux-10 21 | driver: 22 | image: dokken/almalinux-10 23 | pid_one_command: /usr/lib/systemd/systemd 24 | 25 | - name: amazonlinux-2023 26 | driver: 27 | image: dokken/amazonlinux-2023 28 | pid_one_command: /usr/lib/systemd/systemd 29 | 30 | - name: centos-stream-9 31 | driver: 32 | image: dokken/centos-stream-9 33 | pid_one_command: /usr/lib/systemd/systemd 34 | 35 | - name: centos-stream-10 36 | driver: 37 | image: dokken/centos-stream-10 38 | pid_one_command: /usr/lib/systemd/systemd 39 | 40 | - name: debian-11 41 | driver: 42 | image: dokken/debian-11 43 | pid_one_command: /bin/systemd 44 | 45 | - name: debian-12 46 | driver: 47 | image: dokken/debian-12 48 | pid_one_command: /bin/systemd 49 | 50 | - name: fedora-latest 51 | driver: 52 | image: dokken/fedora-latest 53 | pid_one_command: /usr/lib/systemd/systemd 54 | 55 | - name: opensuse-leap-15 56 | driver: 57 | image: dokken/opensuse-leap-15 58 | pid_one_command: /usr/lib/systemd/systemd 59 | 60 | - name: oraclelinux-8 61 | driver: 62 | image: dokken/oraclelinux-8 63 | pid_one_command: /usr/lib/systemd/systemd 64 | 65 | - name: oraclelinux-9 66 | driver: 67 | image: dokken/oraclelinux-9 68 | pid_one_command: /usr/lib/systemd/systemd 69 | 70 | - name: rockylinux-8 71 | driver: 72 | image: dokken/rockylinux-8 73 | pid_one_command: /usr/lib/systemd/systemd 74 | 75 | - name: rockylinux-9 76 | driver: 77 | image: dokken/rockylinux-9 78 | pid_one_command: /usr/lib/systemd/systemd 79 | 80 | - name: ubuntu-20.04 81 | driver: 82 | image: dokken/ubuntu-20.04 83 | pid_one_command: /bin/systemd 84 | 85 | - name: ubuntu-22.04 86 | driver: 87 | image: dokken/ubuntu-22.04 88 | pid_one_command: /bin/systemd 89 | 90 | - name: ubuntu-24.04 91 | driver: 92 | image: dokken/ubuntu-24.04 93 | pid_one_command: /bin/systemd 94 | -------------------------------------------------------------------------------- /kitchen.exec.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: { name: exec } 3 | transport: { name: exec } 4 | 5 | platforms: 6 | - name: macos-latest 7 | - name: windows-latest 8 | -------------------------------------------------------------------------------- /kitchen.global.yml: -------------------------------------------------------------------------------- 1 | --- 2 | provisioner: 3 | name: chef_infra 4 | product_name: chef 5 | product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> 6 | channel: stable 7 | install_strategy: once 8 | chef_license: accept 9 | enforce_idempotency: <%= ENV['ENFORCE_IDEMPOTENCY'] || true %> 10 | multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> 11 | deprecations_as_errors: true 12 | log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> 13 | 14 | verifier: 15 | name: inspec 16 | 17 | platforms: 18 | - name: almalinux-8 19 | - name: almalinux-9 20 | - name: amazonlinux-2023 21 | - name: centos-stream-9 22 | - name: debian-11 23 | - name: debian-12 24 | - name: fedora-latest 25 | - name: opensuse-leap-15 26 | - name: oraclelinux-8 27 | - name: oraclelinux-9 28 | - name: rockylinux-8 29 | - name: rockylinux-9 30 | - name: ubuntu-20.04 31 | - name: ubuntu-22.04 32 | - name: ubuntu-24.04 33 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: vagrant 3 | 4 | provisioner: 5 | name: chef_infra 6 | product_name: chef 7 | deprecations_as_errors: true 8 | chef_license: accept-no-persist 9 | 10 | verifier: 11 | name: inspec 12 | 13 | platforms: 14 | - name: almalinux-8 15 | - name: amazonlinux-2 16 | - name: centos-7 17 | - name: centos-stream-8 18 | - name: debian-10 19 | - name: debian-11 20 | - name: fedora-latest 21 | - name: freebsd-12 22 | - name: opensuse-leap-15 23 | - name: rockylinux-8 24 | - name: ubuntu-18.04 25 | - name: ubuntu-20.04 26 | - name: windows-2012r2 27 | driver: 28 | box: tas50/windows_2012r2 29 | - name: windows-2016 30 | driver_config: 31 | box: tas50/windows_2016 32 | - name: windows-2019 33 | driver_config: 34 | box: tas50/windows_2019 35 | 36 | suites: 37 | - name: default 38 | run_list: 39 | - recipe[ark_spec] 40 | excludes: 41 | - windows-2012r2 42 | - windows-2016 43 | - windows-2019 44 | - windows-latest 45 | - name: windows 46 | run_list: 47 | - recipe[ark_spec::windows] 48 | includes: 49 | - windows-2012r2 50 | - windows-2016 51 | - windows-2019 52 | - windows-latest 53 | -------------------------------------------------------------------------------- /libraries/default.rb: -------------------------------------------------------------------------------- 1 | require_relative 'platform_specific_builders' 2 | require_relative 'resource_deprecations' 3 | require_relative 'resource_defaults' 4 | require_relative 'sevenzip_command_builder' 5 | require_relative 'unzip_command_builder' 6 | require_relative 'tar_command_builder' 7 | require_relative 'general_owner' 8 | require_relative 'windows_owner' 9 | 10 | module Ark 11 | module ProviderHelpers 12 | extend ::Ark::PlatformSpecificBuilders 13 | 14 | generates_archive_commands_for :seven_zip, 15 | when_the: -> { node['platform_family'] == 'windows' }, 16 | with_klass: ::Ark::SevenZipCommandBuilder 17 | 18 | generates_archive_commands_for :unzip, 19 | when_the: -> { new_resource.extension =~ /zip|war|jar/ }, 20 | with_klass: ::Ark::UnzipCommandBuilder 21 | 22 | generates_archive_commands_for :tar, 23 | when_the: -> { true }, 24 | with_klass: ::Ark::TarCommandBuilder 25 | 26 | generates_owner_commands_for :windows, 27 | when_the: -> { node['platform_family'] == 'windows' }, 28 | with_klass: ::Ark::WindowsOwner 29 | 30 | generates_owner_commands_for :all_other_platforms, 31 | when_the: -> { true }, 32 | with_klass: ::Ark::GeneralOwner 33 | 34 | def deprecations 35 | ::Ark::ResourceDeprecations.on(new_resource) 36 | end 37 | 38 | def show_deprecations 39 | deprecations.each { |message| Chef::Log.warn("DEPRECATED: #{message}") } 40 | end 41 | 42 | def defaults 43 | @resource_defaults ||= ::Ark::ResourceDefaults.new(new_resource) 44 | end 45 | 46 | def set_paths 47 | new_resource.extension = defaults.extension 48 | new_resource.prefix_bin = defaults.prefix_bin 49 | new_resource.prefix_root = defaults.prefix_root 50 | new_resource.home_dir = defaults.home_dir 51 | new_resource.version = defaults.version 52 | new_resource.owner = defaults.owner 53 | 54 | # TODO: what happens when the path is already set -- 55 | # with the current logic we overwrite it 56 | # if you are in windows we overwrite it 57 | # otherwise we overwrite it with the root/name-version 58 | new_resource.path = defaults.path 59 | new_resource.release_file = defaults.release_file 60 | end 61 | 62 | def set_put_paths 63 | new_resource.extension = defaults.extension 64 | 65 | # TODO: Should we be setting the prefix_root - 66 | # as the prefix_root could be used in the path_with_version 67 | # new_resource.prefix_root = default.prefix_root 68 | new_resource.path = defaults.path_without_version 69 | new_resource.release_file = defaults.release_file_without_version 70 | end 71 | 72 | def set_dump_paths 73 | new_resource.extension = defaults.extension 74 | new_resource.release_file = defaults.release_file_without_version 75 | end 76 | 77 | def unpack_command 78 | archive_application.unpack 79 | end 80 | 81 | def dump_command 82 | archive_application.dump 83 | end 84 | 85 | def cherry_pick_command 86 | archive_application.cherry_pick 87 | end 88 | 89 | def unzip_command 90 | archive_application.unpack 91 | end 92 | 93 | def owner_command 94 | owner_builder_klass.new(new_resource).command 95 | end 96 | 97 | private 98 | 99 | def archive_application 100 | @archive_application ||= archive_builder_klass.new(new_resource) 101 | end 102 | 103 | def archive_builder_klass 104 | new_resource.extension ||= defaults.extension 105 | Ark::ProviderHelpers.archive_command_generators.find { |condition, _klass| instance_exec(&condition) }.last 106 | end 107 | 108 | def owner_builder_klass 109 | Ark::ProviderHelpers.owner_command_generators.find { |condition, _klass| instance_exec(&condition) }.last 110 | end 111 | end 112 | end 113 | -------------------------------------------------------------------------------- /libraries/general_owner.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class GeneralOwner 3 | def initialize(resource) 4 | @resource = resource 5 | end 6 | 7 | attr_reader :resource 8 | 9 | def command 10 | "chown -R #{resource.owner}:#{resource.group} #{resource.path}" 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /libraries/platform_specific_builders.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | module PlatformSpecificBuilders 3 | def generates_archive_commands_for(_name, options) 4 | condition = options[:when_the] 5 | builder = options[:with_klass] 6 | archive_command_generators.push [condition, builder] 7 | end 8 | 9 | def archive_command_generators 10 | @archive_command_generators ||= [] 11 | end 12 | 13 | def generates_owner_commands_for(_name, options) 14 | condition = options[:when_the] 15 | builder = options[:with_klass] 16 | owner_command_generators.push [condition, builder] 17 | end 18 | 19 | def owner_command_generators 20 | @owner_command_generators ||= [] 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /libraries/resource_defaults.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class ResourceDefaults 3 | def extension 4 | resource.extension || generate_extension_from_url(resource.url.clone) 5 | end 6 | 7 | def prefix_bin 8 | resource.prefix_bin || prefix_bin_from_node_in_run_context 9 | end 10 | 11 | def prefix_root 12 | resource.prefix_root || prefix_root_from_node_in_run_context 13 | end 14 | 15 | def home_dir 16 | if resource.home_dir.nil? || resource.home_dir.empty? 17 | prefix_home = resource.prefix_home || prefix_home_from_node_in_run_context 18 | ::File.join(prefix_home, resource.name) 19 | else 20 | resource.home_dir 21 | end 22 | end 23 | 24 | def version 25 | resource.version || default_version 26 | end 27 | 28 | def path 29 | if windows? 30 | resource.win_install_dir 31 | else 32 | ::File.join(resource.prefix_root, "#{resource.name}-#{resource.version}") 33 | end 34 | end 35 | 36 | def owner 37 | resource.owner || default_owner 38 | end 39 | 40 | def windows? 41 | node_in_run_context['platform_family'] == 'windows' 42 | end 43 | 44 | def path_without_version 45 | partial_path = resource.path || prefix_root_from_node_in_run_context 46 | ::File.join(partial_path, resource.name) 47 | end 48 | 49 | def release_file 50 | release_filename = "#{resource.name}-#{resource.version}.#{resource.extension}" 51 | ::File.join(file_cache_path, release_filename) 52 | end 53 | 54 | def release_file_without_version 55 | release_filename = "#{resource.name}.#{resource.extension}" 56 | ::File.join(file_cache_path, release_filename) 57 | end 58 | 59 | def initialize(resource) 60 | @resource = resource 61 | end 62 | 63 | private 64 | 65 | attr_reader :resource 66 | 67 | def generate_extension_from_url(url) 68 | # purge any trailing redirect 69 | url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip|7z)(\/.*\/)} 70 | url.gsub!(Regexp.last_match(2), '') unless Regexp.last_match(2).nil? 71 | # remove trailing query string 72 | release_basename = ::File.basename(url.gsub(/\?.*\z/, '')).gsub(/-bin\b/, '') 73 | # (\?.*)? accounts for a trailing querystring 74 | Chef::Log.debug("DEBUG: release_basename is #{release_basename}") 75 | release_basename =~ /^(.+?)\.(jar|tar\.bz2|tar\.gz|tar\.xz|tbz|tgz|txz|war|zip|tar|7z)(\?.*)?/ 76 | Chef::Log.debug("DEBUG: file_extension is #{Regexp.last_match(2)}") 77 | Regexp.last_match(2) 78 | end 79 | 80 | def prefix_bin_from_node_in_run_context 81 | node_in_run_context['ark']['prefix_bin'] 82 | end 83 | 84 | def prefix_root_from_node_in_run_context 85 | node_in_run_context['ark']['prefix_root'] 86 | end 87 | 88 | def prefix_home_from_node_in_run_context 89 | node_in_run_context['ark']['prefix_home'] 90 | end 91 | 92 | def default_version 93 | '1' 94 | end 95 | 96 | def default_owner 97 | if windows? 98 | wmi_property_from_query(:name, "select * from Win32_UserAccount where sid like 'S-1-5-21-%-500' and LocalAccount=True") 99 | else 100 | 'root' 101 | end 102 | end 103 | 104 | def wmi_property_from_query(wmi_property, wmi_query) 105 | @wmi = ::WIN32OLE.connect('winmgmts://') 106 | result = @wmi.ExecQuery(wmi_query) 107 | return unless result.each.count > 0 108 | result.each.next.send(wmi_property) 109 | end 110 | 111 | def file_cache_path 112 | Chef::Config[:file_cache_path] 113 | end 114 | 115 | def node_in_run_context 116 | resource.run_context.node 117 | end 118 | end 119 | end 120 | -------------------------------------------------------------------------------- /libraries/resource_deprecations.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class ResourceDeprecations 3 | def self.on(resource) 4 | new(resource).warnings 5 | end 6 | 7 | def initialize(resource) 8 | @resource = resource 9 | end 10 | 11 | attr_reader :resource 12 | 13 | def warnings 14 | applicable_deprecrations.map { |_, message| message } 15 | end 16 | 17 | def applicable_deprecrations 18 | deprecations.select { |condition, _| send(condition) } 19 | end 20 | 21 | def deprecations 22 | { strip_leading_dir_feature: strip_leading_dir_feature_message } 23 | end 24 | 25 | def strip_leading_dir_feature 26 | [true, false].include?(resource.strip_leading_dir) 27 | end 28 | 29 | def strip_leading_dir_feature_message 30 | 'strip_leading_dir attribute was deprecated. Use strip_components instead.' 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /libraries/sevenzip_command_builder.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class SevenZipCommandBuilder 3 | def unpack 4 | sevenzip_command 5 | end 6 | 7 | def dump 8 | sevenzip_command_builder(resource.path, 'e') 9 | end 10 | 11 | def cherry_pick 12 | "#{sevenzip_command_builder(resource.path, 'x')} -r #{resource.creates}" 13 | end 14 | 15 | def initialize(resource) 16 | @resource = resource 17 | end 18 | 19 | private 20 | 21 | attr_reader :resource 22 | 23 | def node 24 | resource.run_context.node 25 | end 26 | 27 | def sevenzip_command 28 | return sevenzip_command_builder(resource.path, 'x') if resource.strip_components <= 0 29 | 30 | tmpdir = make_temp_directory.tr('/', '\\') 31 | cmd = sevenzip_command_builder(tmpdir, 'x') 32 | 33 | cmd += ' && ' 34 | currdir = tmpdir 35 | 36 | 1.upto(resource.strip_components).each do |count| 37 | cmd += "for /f %#{count} in ('dir /ad /b \"#{currdir}\"') do " 38 | currdir += "\\%#{count}" 39 | end 40 | 41 | cmd += "(\"#{ENV.fetch('SystemRoot')}\\System32\\robocopy\" \"#{currdir}\" \"#{resource.path}\" /s /e) ^& IF %ERRORLEVEL% LEQ 3 cmd /c exit 0" 42 | end 43 | 44 | def sevenzip_binary 45 | @tar_binary ||= "\"#{node['ark']['sevenzip_binary'] || sevenzip_path_from_registry}\"" 46 | end 47 | 48 | def sevenzip_path_from_registry 49 | begin 50 | basepath = ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').read_s('Path') 51 | 52 | # users like pretty errors 53 | rescue ::Win32::Registry::Error 54 | 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"]' 55 | end 56 | "#{basepath}7z.exe" 57 | end 58 | 59 | def sevenzip_command_builder(dir, command) 60 | "#{sevenzip_binary} #{command} \"#{resource.release_file}\"#{extension_is_tar} -o\"#{dir}\" -uy" 61 | end 62 | 63 | def extension_is_tar 64 | if resource.extension =~ /tar.gz|tgz|tar.bz2|tbz|tar.xz|txz/ 65 | " -so | #{sevenzip_binary} x -aoa -si -ttar" 66 | else 67 | ' -aoa' # force overwrite, Fixes #164 68 | end 69 | end 70 | 71 | def make_temp_directory 72 | require 'tmpdir' 73 | Dir.mktmpdir 74 | end 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /libraries/tar_command_builder.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class TarCommandBuilder 3 | def unpack 4 | "#{tar_binary} #{args} #{resource.release_file}#{strip_args}" 5 | end 6 | 7 | def dump 8 | "tar -mxf \"#{resource.release_file}\" -C \"#{resource.path}\"" 9 | end 10 | 11 | def cherry_pick 12 | "#{tar_binary} #{args} #{resource.release_file} -C #{resource.path}#{strip_args} #{resource.creates}" 13 | end 14 | 15 | def initialize(resource) 16 | @resource = resource 17 | end 18 | 19 | private 20 | 21 | attr_reader :resource 22 | 23 | def node 24 | resource.run_context.node 25 | end 26 | 27 | def tar_binary 28 | @tar_binary ||= node['ark']['tar'] || case node['platform_family'] 29 | when 'mac_os_x', 'freebsd' 30 | '/usr/bin/tar' 31 | when 'smartos' 32 | '/bin/gtar' 33 | else 34 | '/bin/tar' 35 | end 36 | end 37 | 38 | def args 39 | case resource.extension 40 | when /^(tar)$/ then 'xf' 41 | when /^(tar.gz|tgz)$/ then 'xzf' 42 | when /^(tar.bz2|tbz)$/ then 'xjf' 43 | when /^(tar.xz|txz)$/ then 'xJf' 44 | else raise unsupported_extension 45 | end 46 | end 47 | 48 | def strip_args 49 | resource.strip_components > 0 ? " --strip-components=#{resource.strip_components}" : '' 50 | end 51 | 52 | def unsupported_extension 53 | "Don't know how to expand #{resource.url} (extension: #{resource.extension})" 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /libraries/unzip_command_builder.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class UnzipCommandBuilder 3 | def unpack 4 | if resource.strip_components > 0 5 | unzip_with_strip_components 6 | else 7 | "unzip -q -o #{resource.release_file} -d #{resource.path}" 8 | end 9 | end 10 | 11 | def dump 12 | "unzip -j -q -o \"#{resource.release_file}\" -d \"#{resource.path}\"" 13 | end 14 | 15 | def cherry_pick 16 | cmd = "unzip -t #{resource.release_file} \"*/#{resource.creates}\" ; stat=$? ;" 17 | cmd += 'if [ $stat -eq 11 ] ; then ' 18 | cmd += "unzip -j -o #{resource.release_file} \"#{resource.creates}\" -d #{resource.path} ;" 19 | cmd += 'elif [ $stat -ne 0 ] ; then false ;' 20 | cmd += 'else ' 21 | cmd += "unzip -j -o #{resource.release_file} \"*/#{resource.creates}\" -d #{resource.path} ;" 22 | cmd += 'fi' 23 | cmd 24 | end 25 | 26 | def initialize(resource) 27 | @resource = resource 28 | end 29 | 30 | private 31 | 32 | attr_reader :resource 33 | 34 | def unzip_with_strip_components 35 | tmpdir = make_temp_directory 36 | strip_dir = '*/' * resource.strip_components 37 | cmd = "unzip -q -o #{resource.release_file} -d #{tmpdir}" 38 | cmd += " && rsync -a #{tmpdir}/#{strip_dir} #{resource.path}" 39 | cmd += " && rm -rf #{tmpdir}" 40 | cmd 41 | end 42 | 43 | def make_temp_directory 44 | require 'tmpdir' 45 | Dir.mktmpdir 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /libraries/windows_owner.rb: -------------------------------------------------------------------------------- 1 | module Ark 2 | class WindowsOwner 3 | def initialize(resource) 4 | @resource = resource 5 | end 6 | 7 | attr_reader :resource 8 | 9 | def command 10 | "#{ENV.fetch('SystemRoot')}\\System32\\icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\"" 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'ark' 2 | maintainer 'Sous Chefs' 3 | maintainer_email 'help@sous-chefs.org' 4 | license 'Apache-2.0' 5 | description 'Provides a custom resource for installing runtime artifacts in a predictable fashion' 6 | version '6.0.32' 7 | source_url 'https://github.com/sous-chefs/ark' 8 | issues_url 'https://github.com/sous-chefs/ark/issues' 9 | chef_version '>= 15.3' 10 | 11 | supports 'amazon' 12 | supports 'centos' 13 | supports 'debian' 14 | supports 'freebsd' 15 | supports 'mac_os_x' 16 | supports 'opensuse' 17 | supports 'opensuseleap' 18 | supports 'oracle' 19 | supports 'redhat' 20 | supports 'scientific' 21 | supports 'smartos' 22 | supports 'suse' 23 | supports 'ubuntu' 24 | supports 'windows' 25 | 26 | depends 'seven_zip', '>= 3.1' # for windows os 27 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ark 3 | # Recipe:: default 4 | # 5 | # Author:: Bryan W. Berry 6 | # Copyright:: 2012-2017, Bryan W. Berry 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | package node['ark']['package_dependencies'] unless platform_family?('windows', 'mac_os_x') 22 | 23 | seven_zip_tool 'ark' if platform_family?('windows') 24 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "packageRules": [ 5 | { 6 | "groupName": "Actions", 7 | "matchUpdateTypes": ["minor", "patch", "pin"], 8 | "automerge": true, 9 | "addLabels": ["Release: Patch", "Skip: Announcements"] 10 | }, 11 | { 12 | "groupName": "Actions", 13 | "matchUpdateTypes": ["major"], 14 | "automerge": false, 15 | "addLabels": ["Release: Patch", "Skip: Announcements"] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /resources/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: ark 3 | # Resource:: Ark 4 | # 5 | # Author:: Bryan W. Berry 6 | # Copyright:: 2012-2017, Bryan W. Berry 7 | # Copyright:: 2016-2017, Chef Software Inc. 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | property :owner, String 23 | property :group, [String, Integer], default: 0 24 | property :url, String, required: true 25 | property :path, String 26 | property :full_path, String 27 | property :append_env_path, [true, false], default: false 28 | property :checksum, String, regex: /^[a-zA-Z0-9]{64}$/ 29 | property :has_binaries, Array, default: [] 30 | property :creates, String 31 | property :release_file, String, default: '' 32 | property :strip_leading_dir, [true, false, NilClass] 33 | property :strip_components, Integer, default: 1 34 | property :mode, [Integer, String], default: 0755 35 | property :prefix_root, String 36 | property :prefix_home, String 37 | property :prefix_bin, String 38 | property :version, String 39 | property :home_dir, String 40 | property :win_install_dir, String 41 | property :environment, Hash, default: {} 42 | property :autoconf_opts, Array, default: [] 43 | property :make_opts, Array, default: [] 44 | property :home_dir, String 45 | property :autoconf_opts, Array, default: [] 46 | property :extension, String 47 | property :backup, [FalseClass, Integer], default: 5 48 | 49 | unified_mode true 50 | 51 | ################# 52 | # action :install 53 | ################# 54 | action :install do 55 | show_deprecations 56 | set_paths 57 | 58 | directory new_resource.path do 59 | recursive true 60 | action :create 61 | notifies :run, "execute[unpack #{new_resource.release_file}]" 62 | end 63 | 64 | remote_file new_resource.release_file do 65 | Chef::Log.debug('DEBUG: new_resource.release_file') 66 | source new_resource.url 67 | checksum new_resource.checksum if new_resource.checksum 68 | action :create 69 | notifies :run, "execute[unpack #{new_resource.release_file}]" 70 | backup new_resource.backup 71 | end 72 | 73 | # unpack based on file extension 74 | execute "unpack #{new_resource.release_file}" do 75 | command unpack_command 76 | cwd new_resource.path 77 | environment new_resource.environment 78 | notifies :run, "execute[set owner on #{new_resource.path}]" 79 | action :nothing 80 | end 81 | 82 | # set_owner 83 | execute "set owner on #{new_resource.path}" do 84 | command owner_command 85 | action :nothing 86 | end 87 | 88 | if platform_family?('windows') 89 | # usually on windows there is no central directory with executables where the applications are linked 90 | # so ignore has_binaries for now 91 | 92 | # Add to PATH permanently on Windows if append_env_path 93 | windows_path "#{new_resource.path}/bin" do 94 | action :add 95 | only_if { new_resource.append_env_path } 96 | end 97 | else 98 | # symlink binaries 99 | new_resource.has_binaries.each do |bin| 100 | link ::File.join(new_resource.prefix_bin, ::File.basename(bin)) do 101 | to ::File.join(new_resource.path, bin) 102 | end 103 | end 104 | 105 | # action_link_paths 106 | link new_resource.home_dir do 107 | to new_resource.path 108 | end 109 | 110 | # This directory doesn't exist by default on MacOS 111 | directory '/etc/profile.d' if platform_family?('mac_os_x') 112 | 113 | # Add to path for interactive bash sessions 114 | template "/etc/profile.d/#{new_resource.name}.sh" do 115 | cookbook 'ark' 116 | source 'add_to_path.sh.erb' 117 | owner 'root' 118 | group node['root_group'] 119 | mode '0755' 120 | cookbook 'ark' 121 | variables(directory: "#{new_resource.path}/bin") 122 | only_if { new_resource.append_env_path } 123 | end 124 | end 125 | 126 | # Add to path for the current chef-client converge. 127 | bin_path = ::File.join(new_resource.path, 'bin') 128 | ruby_block "adding '#{bin_path}' to chef-client ENV['PATH']" do 129 | block do 130 | ENV['PATH'] = bin_path + ':' + ENV['PATH'] 131 | end 132 | only_if do 133 | new_resource.append_env_path && ENV['PATH'].scan(bin_path).empty? 134 | end 135 | end 136 | end 137 | 138 | ############## 139 | # action :put 140 | ############## 141 | action :put do 142 | show_deprecations 143 | set_put_paths 144 | 145 | directory new_resource.path do 146 | recursive true 147 | action :create 148 | notifies :run, "execute[unpack #{new_resource.release_file}]" 149 | end 150 | 151 | # download 152 | remote_file new_resource.release_file do 153 | source new_resource.url 154 | checksum new_resource.checksum if new_resource.checksum 155 | action :create 156 | notifies :run, "execute[unpack #{new_resource.release_file}]" 157 | backup new_resource.backup 158 | end 159 | 160 | # unpack based on file extension 161 | execute "unpack #{new_resource.release_file}" do 162 | command unpack_command 163 | cwd new_resource.path 164 | environment new_resource.environment 165 | notifies :run, "execute[set owner on #{new_resource.path}]" 166 | action :nothing 167 | end 168 | 169 | # set_owner 170 | execute "set owner on #{new_resource.path}" do 171 | command owner_command 172 | action :nothing 173 | end 174 | end 175 | 176 | ########################### 177 | # action :dump 178 | ########################### 179 | action :dump do 180 | show_deprecations 181 | set_dump_paths 182 | 183 | directory new_resource.path do 184 | recursive true 185 | action :create 186 | notifies :run, "execute[unpack #{new_resource.release_file}]" 187 | end 188 | 189 | # download 190 | remote_file new_resource.release_file do 191 | Chef::Log.debug("DEBUG: new_resource.release_file #{new_resource.release_file}") 192 | source new_resource.url 193 | checksum new_resource.checksum if new_resource.checksum 194 | action :create 195 | notifies :run, "execute[unpack #{new_resource.release_file}]" 196 | end 197 | 198 | # unpack based on file extension 199 | execute "unpack #{new_resource.release_file}" do 200 | command dump_command 201 | cwd new_resource.path 202 | environment new_resource.environment 203 | notifies :run, "execute[set owner on #{new_resource.path}]" 204 | action :nothing 205 | end 206 | 207 | # set_owner 208 | execute "set owner on #{new_resource.path}" do 209 | command owner_command 210 | action :nothing 211 | end 212 | end 213 | 214 | ########################### 215 | # action :unzip 216 | ########################### 217 | action :unzip do 218 | show_deprecations 219 | set_dump_paths 220 | 221 | directory new_resource.path do 222 | recursive true 223 | action :create 224 | notifies :run, "execute[unpack #{new_resource.release_file}]" 225 | end 226 | 227 | # download 228 | remote_file new_resource.release_file do 229 | Chef::Log.debug("DEBUG: new_resource.release_file #{new_resource.release_file}") 230 | source new_resource.url 231 | checksum new_resource.checksum if new_resource.checksum 232 | action :create 233 | notifies :run, "execute[unpack #{new_resource.release_file}]" 234 | end 235 | 236 | # unpack based on file extension 237 | execute "unpack #{new_resource.release_file}" do 238 | command unzip_command 239 | cwd new_resource.path 240 | environment new_resource.environment 241 | notifies :run, "execute[set owner on #{new_resource.path}]" 242 | action :nothing 243 | end 244 | 245 | # set_owner 246 | execute "set owner on #{new_resource.path}" do 247 | command owner_command 248 | action :nothing 249 | end 250 | end 251 | 252 | ##################### 253 | # action :cherry_pick 254 | ##################### 255 | action :cherry_pick do 256 | show_deprecations 257 | set_dump_paths 258 | Chef::Log.debug("DEBUG: new_resource.creates #{new_resource.creates}") 259 | 260 | directory new_resource.path do 261 | recursive true 262 | action :create 263 | notifies :run, "execute[cherry_pick #{new_resource.creates} from #{new_resource.release_file}]" 264 | end 265 | 266 | # download 267 | remote_file new_resource.release_file do 268 | source new_resource.url 269 | checksum new_resource.checksum if new_resource.checksum 270 | action :create 271 | notifies :run, "execute[cherry_pick #{new_resource.creates} from #{new_resource.release_file}]" 272 | end 273 | 274 | execute "cherry_pick #{new_resource.creates} from #{new_resource.release_file}" do 275 | command cherry_pick_command 276 | creates "#{new_resource.path}/#{new_resource.creates}" 277 | notifies :run, "execute[set owner on #{new_resource.path}]" 278 | action :nothing 279 | end 280 | 281 | # set_owner 282 | execute "set owner on #{new_resource.path}" do 283 | command owner_command 284 | action :nothing 285 | end 286 | end 287 | 288 | ########################### 289 | # action :install_with_make 290 | ########################### 291 | action :install_with_make do 292 | show_deprecations 293 | set_paths 294 | 295 | directory new_resource.path do 296 | recursive true 297 | action :create 298 | notifies :run, "execute[unpack #{new_resource.release_file}]" 299 | end 300 | 301 | remote_file new_resource.release_file do 302 | Chef::Log.debug('DEBUG: new_resource.release_file') 303 | source new_resource.url 304 | checksum new_resource.checksum if new_resource.checksum 305 | action :create 306 | notifies :run, "execute[unpack #{new_resource.release_file}]" 307 | end 308 | 309 | # unpack based on file extension 310 | execute "unpack #{new_resource.release_file}" do 311 | command unpack_command 312 | cwd new_resource.path 313 | environment new_resource.environment 314 | notifies :run, "execute[set owner on #{new_resource.path}]" 315 | notifies :run, "execute[autogen #{new_resource.path}]" 316 | notifies :run, "execute[configure #{new_resource.path}]" 317 | notifies :run, "execute[make #{new_resource.path}]" 318 | notifies :run, "execute[make install #{new_resource.path}]" 319 | action :nothing 320 | end 321 | 322 | # set_owner 323 | execute "set owner on #{new_resource.path}" do 324 | command owner_command 325 | action :nothing 326 | end 327 | 328 | execute "autogen #{new_resource.path}" do 329 | command './autogen.sh' 330 | only_if { ::File.exist? "#{new_resource.path}/autogen.sh" } 331 | cwd new_resource.path 332 | environment new_resource.environment 333 | action :nothing 334 | ignore_failure true 335 | end 336 | 337 | execute "configure #{new_resource.path}" do 338 | command "./configure #{new_resource.autoconf_opts.join(' ')}" 339 | only_if { ::File.exist? "#{new_resource.path}/configure" } 340 | cwd new_resource.path 341 | environment new_resource.environment 342 | action :nothing 343 | end 344 | 345 | execute "make #{new_resource.path}" do 346 | command "make #{new_resource.make_opts.join(' ')}" 347 | cwd new_resource.path 348 | environment new_resource.environment 349 | action :nothing 350 | end 351 | 352 | execute "make install #{new_resource.path}" do 353 | command "make install #{new_resource.make_opts.join(' ')}" 354 | cwd new_resource.path 355 | environment new_resource.environment 356 | action :nothing 357 | end 358 | end 359 | 360 | action :setup_py_build do 361 | show_deprecations 362 | set_paths 363 | 364 | directory new_resource.path do 365 | recursive true 366 | action :create 367 | notifies :run, "execute[unpack #{new_resource.release_file}]" 368 | end 369 | 370 | remote_file new_resource.release_file do 371 | Chef::Log.debug('DEBUG: new_resource.release_file') 372 | source new_resource.url 373 | checksum new_resource.checksum if new_resource.checksum 374 | action :create 375 | notifies :run, "execute[unpack #{new_resource.release_file}]" 376 | end 377 | 378 | # unpack based on file extension 379 | execute "unpack #{new_resource.release_file}" do 380 | command unpack_command 381 | cwd new_resource.path 382 | environment new_resource.environment 383 | notifies :run, "execute[set owner on #{new_resource.path}]" 384 | notifies :run, "execute[python setup.py build #{new_resource.path}]" 385 | action :nothing 386 | end 387 | 388 | # set_owner 389 | execute "set owner on #{new_resource.path}" do 390 | command owner_command 391 | action :nothing 392 | end 393 | 394 | execute "python setup.py build #{new_resource.path}" do 395 | command "python setup.py build #{new_resource.make_opts.join(' ')}" 396 | cwd new_resource.path 397 | environment new_resource.environment 398 | action :nothing 399 | end 400 | end 401 | 402 | action :setup_py_install do 403 | show_deprecations 404 | set_paths 405 | 406 | directory new_resource.path do 407 | recursive true 408 | action :create 409 | notifies :run, "execute[unpack #{new_resource.release_file}]" 410 | end 411 | 412 | remote_file new_resource.release_file do 413 | Chef::Log.debug('DEBUG: new_resource.release_file') 414 | source new_resource.url 415 | checksum new_resource.checksum if new_resource.checksum 416 | action :create 417 | notifies :run, "execute[unpack #{new_resource.release_file}]" 418 | end 419 | 420 | # unpack based on file extension 421 | execute "unpack #{new_resource.release_file}" do 422 | command unpack_command 423 | cwd new_resource.path 424 | environment new_resource.environment 425 | notifies :run, "execute[set owner on #{new_resource.path}]" 426 | notifies :run, "execute[python setup.py install #{new_resource.path}]" 427 | action :nothing 428 | end 429 | 430 | # set_owner 431 | execute "set owner on #{new_resource.path}" do 432 | command owner_command 433 | action :nothing 434 | end 435 | 436 | execute "python setup.py install #{new_resource.path}" do 437 | command "python setup.py install #{new_resource.make_opts.join(' ')}" 438 | cwd new_resource.path 439 | environment new_resource.environment 440 | action :nothing 441 | end 442 | end 443 | 444 | action :setup_py do 445 | show_deprecations 446 | set_paths 447 | 448 | directory new_resource.path do 449 | recursive true 450 | action :create 451 | notifies :run, "execute[unpack #{new_resource.release_file}]" 452 | end 453 | 454 | remote_file new_resource.release_file do 455 | Chef::Log.debug('DEBUG: new_resource.release_file') 456 | source new_resource.url 457 | checksum new_resource.checksum if new_resource.checksum 458 | action :create 459 | notifies :run, "execute[unpack #{new_resource.release_file}]" 460 | end 461 | 462 | # unpack based on file extension 463 | execute "unpack #{new_resource.release_file}" do 464 | command unpack_command 465 | cwd new_resource.path 466 | environment new_resource.environment 467 | notifies :run, "execute[set owner on #{new_resource.path}]" 468 | notifies :run, "execute[python setup.py #{new_resource.path}]" 469 | action :nothing 470 | end 471 | 472 | # set_owner 473 | execute "set owner on #{new_resource.path}" do 474 | command owner_command 475 | action :nothing 476 | end 477 | 478 | execute "python setup.py #{new_resource.path}" do 479 | command "python setup.py #{new_resource.make_opts.join(' ')}" 480 | cwd new_resource.path 481 | environment new_resource.environment 482 | action :nothing 483 | end 484 | end 485 | 486 | action :configure do 487 | show_deprecations 488 | set_paths 489 | 490 | directory new_resource.path do 491 | recursive true 492 | action :create 493 | notifies :run, "execute[unpack #{new_resource.release_file}]" 494 | end 495 | 496 | remote_file new_resource.release_file do 497 | Chef::Log.debug('DEBUG: new_resource.release_file') 498 | source new_resource.url 499 | checksum new_resource.checksum if new_resource.checksum 500 | action :create 501 | notifies :run, "execute[unpack #{new_resource.release_file}]" 502 | end 503 | 504 | # unpack based on file extension 505 | execute "unpack #{new_resource.release_file}" do 506 | command unpack_command 507 | cwd new_resource.path 508 | environment new_resource.environment 509 | notifies :run, "execute[set owner on #{new_resource.path}]" 510 | notifies :run, "execute[autogen #{new_resource.path}]" 511 | notifies :run, "execute[configure #{new_resource.path}]" 512 | action :nothing 513 | end 514 | 515 | # set_owner 516 | execute "set owner on #{new_resource.path}" do 517 | command owner_command 518 | action :nothing 519 | end 520 | 521 | execute "autogen #{new_resource.path}" do 522 | command './autogen.sh' 523 | only_if { ::File.exist? "#{new_resource.path}/autogen.sh" } 524 | cwd new_resource.path 525 | environment new_resource.environment 526 | action :nothing 527 | ignore_failure true 528 | end 529 | 530 | execute "configure #{new_resource.path}" do 531 | command "./configure #{new_resource.autoconf_opts.join(' ')}" 532 | only_if { ::File.exist? "#{new_resource.path}/configure" } 533 | cwd new_resource.path 534 | environment new_resource.environment 535 | action :nothing 536 | end 537 | end 538 | 539 | action_class do 540 | include ::Ark::ProviderHelpers 541 | end 542 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/ark/2cc8d167706e28571caf41b86e2e1374ce9ed540/spec/fixtures/cookbooks/ark_spec/README.md -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'ark_spec' 2 | maintainer 'Bryan W. Berry' 3 | maintainer_email 'bryan.berry@gmail.com' 4 | license 'Apache-2.0' 5 | description 'Installs/Configures ark' 6 | version '0.9.1' 7 | 8 | %w( debian ubuntu centos redhat fedora windows ).each do |os| 9 | supports os 10 | end 11 | 12 | depends 'ark' 13 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb: -------------------------------------------------------------------------------- 1 | ark 'test_cherry_pick' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 3 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 4 | path '/usr/local/foo_cherry_pick' 5 | owner 'foobarbaz' 6 | group 'foobarbaz' 7 | creates 'foo_sub/foo1.txt' 8 | action :cherry_pick 9 | end 10 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick_with_zip.rb: -------------------------------------------------------------------------------- 1 | ark 'cherry_pick_with_zip' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 3 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 4 | path '/usr/local/foo_cherry_pick_from_zip' 5 | creates 'foo_sub/foo1.txt' 6 | action :cherry_pick 7 | end 8 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/configure.rb: -------------------------------------------------------------------------------- 1 | ark 'test_configure' do 2 | url 'https://github.com/zeromq/libzmq/tarball/master' 3 | extension 'tar.gz' 4 | action :configure 5 | end 6 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/default.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | include_recipe 'ark' 4 | 5 | # remove file so we can test sending notification on its creation 6 | FileUtils.rm_f '/tmp/foobarbaz/foo1.txt' if ::File.exist? '/tmp/foobarbaz/foo1.txt' 7 | 8 | ruby_block 'test_notification' do 9 | block do 10 | FileUtils.touch '/tmp/foobarbaz/notification_successful.txt' if ::File.exist? '/tmp/foobarbaz/foo1.txt' 11 | end 12 | action :nothing 13 | end 14 | 15 | group 'foobarbaz_group' 16 | 17 | user 'foobarbaz' do 18 | group 'foobarbaz_group' 19 | end 20 | 21 | directory '/opt/bin' do 22 | recursive true 23 | end 24 | 25 | ark 'foo' do 26 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 27 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 28 | version '2' 29 | prefix_root '/usr/local' 30 | owner 'foobarbaz' 31 | group 'foobarbaz_group' 32 | has_binaries ['bin/do_foo', 'bin/do_more_foo'] 33 | action :install 34 | end 35 | 36 | ark 'test_put' do 37 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 38 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 39 | owner 'foobarbaz' 40 | group 'foobarbaz_group' 41 | action :put 42 | end 43 | 44 | ark 'test_dump' do 45 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 46 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 47 | path '/usr/local/foo_dump' 48 | creates 'foo1.txt' 49 | owner 'foobarbaz' 50 | group 'foobarbaz_group' 51 | action :dump 52 | end 53 | 54 | ark 'cherry_pick_test' do 55 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 56 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 57 | path '/usr/local/foo_cherry_pick' 58 | owner 'foobarbaz' 59 | group 'foobarbaz_group' 60 | creates 'foo_sub/foo1.txt' 61 | action :cherry_pick 62 | end 63 | 64 | ark 'cherry_pick_with_zip' do 65 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 66 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 67 | path '/usr/local/foo_cherry_pick_from_zip' 68 | creates 'foo_sub/foo1.txt' 69 | action :cherry_pick 70 | end 71 | 72 | ark 'foo_append_env' do 73 | version '7.0.26' 74 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 75 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 76 | append_env_path true 77 | action :install 78 | end 79 | 80 | ark 'foo_dont_strip' do 81 | version '2' 82 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 83 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 84 | strip_components 0 85 | action :install 86 | end 87 | 88 | ark 'foo_zip_strip' do 89 | version '2' 90 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 91 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 92 | action :install 93 | end 94 | 95 | ark 'haproxy' do 96 | url 'http://www.haproxy.org/download/2.6/src/haproxy-2.6.7.tar.gz' 97 | version '2.6' 98 | checksum 'cff9b8b18a52bfec277f9c1887fac93c18e1b9f3eff48892255a7c6e64528b7d' 99 | make_opts ['TARGET=linux-glibc'] 100 | action :install_with_make 101 | end unless platform?('freebsd', 'mac_os_x') 102 | 103 | ark 'foo_alt_bin' do 104 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 105 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 106 | version '3' 107 | prefix_root '/opt' 108 | prefix_home '/opt' 109 | prefix_bin '/opt/bin' 110 | owner 'foobarbaz' 111 | group 'foobarbaz_group' 112 | has_binaries ['bin/do_foo'] 113 | action :install 114 | end 115 | 116 | ark 'foo_tbz' do 117 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tbz' 118 | version '3' 119 | end 120 | 121 | ark 'foo_tgz' do 122 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tgz' 123 | version '3' 124 | end 125 | 126 | ark 'foo_txz' do 127 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.txz' 128 | version '3' 129 | end 130 | 131 | ark 'test_notification' do 132 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 133 | path '/tmp/foobarbaz' 134 | creates 'foo1.txt' 135 | action :dump 136 | notifies :create, 'ruby_block[test_notification]', :immediately 137 | end 138 | 139 | ark 'test_autogen' do 140 | url 'http://zlib.net/zlib-1.2.13.tar.gz' 141 | extension 'tar.gz' 142 | action :configure 143 | end 144 | 145 | ark 'foo_sub_tar' do 146 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo_sub.tar.gz' 147 | version '1' 148 | strip_components 2 149 | end 150 | 151 | ark 'foo_sub_zip' do 152 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo_sub.zip' 153 | version '2' 154 | strip_components 2 155 | end 156 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/dump.rb: -------------------------------------------------------------------------------- 1 | ark 'test_dump' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 3 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 4 | path '/usr/local/foo_dump' 5 | creates 'foo1.txt' 6 | owner 'foobarbaz' 7 | group 'foobarbaz' 8 | action :dump 9 | end 10 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install.rb: -------------------------------------------------------------------------------- 1 | ark 'test_install' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 3 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 4 | version '2' 5 | prefix_root '/usr/local' 6 | owner 'foobarbaz' 7 | group 'foobarbaz_group' 8 | action :install 9 | end 10 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install_no_stripping.rb: -------------------------------------------------------------------------------- 1 | ark 'foo_dont_strip' do 2 | version '2' 3 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 4 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 5 | strip_components 0 6 | action :install 7 | end 8 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install_stripping.rb: -------------------------------------------------------------------------------- 1 | ark 'foo_zip_strip' do 2 | version '2' 3 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 4 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 5 | action :install 6 | end 7 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb: -------------------------------------------------------------------------------- 1 | ark 'test_install' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 3 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 4 | version '2' 5 | prefix_root 'C:\\' 6 | win_install_dir 'C:\\install' 7 | owner 'foobarbaz' 8 | group 'foobarbaz' 9 | # has_binaries %w( bin\do_foo bin\do_more_foo ) 10 | action :install 11 | end 12 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install_with_append_env_path.rb: -------------------------------------------------------------------------------- 1 | ark 'test_install_with_append_env_path' do 2 | version '7.0.26' 3 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 4 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 5 | append_env_path true 6 | action :install 7 | end 8 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb: -------------------------------------------------------------------------------- 1 | ark 'test_install' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 3 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 4 | version '2' 5 | prefix_root '/usr/local' 6 | owner 'foobarbaz' 7 | group 'foobarbaz' 8 | has_binaries ['bin/do_foo', 'bin/do_more_foo'] 9 | action :install 10 | end 11 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/install_with_make.rb: -------------------------------------------------------------------------------- 1 | ark 'test_install_with_make' do 2 | url 'http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz' 3 | version '1.5' 4 | checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911' 5 | make_opts ['TARGET=linux26'] 6 | action :install_with_make 7 | end 8 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/put.rb: -------------------------------------------------------------------------------- 1 | ark 'test_put' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 3 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 4 | owner 'foobarbaz' 5 | group 'foobarbaz' 6 | action :put 7 | end 8 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/setup_py.rb: -------------------------------------------------------------------------------- 1 | ark 'test_setup_py' do 2 | url 'https://codeload.github.com/s3tools/s3cmd/tar.gz/master' 3 | extension 'tar.gz' 4 | action :setup_py 5 | end 6 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/setup_py_build.rb: -------------------------------------------------------------------------------- 1 | ark 'test_setup_py_build' do 2 | url 'https://codeload.github.com/s3tools/s3cmd/tar.gz/master' 3 | extension 'tar.gz' 4 | action :setup_py_build 5 | end 6 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/setup_py_install.rb: -------------------------------------------------------------------------------- 1 | ark 'test_setup_py_install' do 2 | url 'https://codeload.github.com/s3tools/s3cmd/tar.gz/master' 3 | extension 'tar.gz' 4 | action :setup_py_install 5 | end 6 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb: -------------------------------------------------------------------------------- 1 | ark 'test_unzip' do 2 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.zip' 3 | checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0' 4 | path '/usr/local/foo_dump' 5 | creates 'foo1.txt' 6 | owner 'foobarbaz' 7 | group 'foobarbaz' 8 | action :unzip 9 | end 10 | -------------------------------------------------------------------------------- /spec/fixtures/cookbooks/ark_spec/recipes/windows.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'ark' 2 | 3 | group 'foobar' 4 | 5 | user 'foobarbaz' do 6 | group 'foobarbaz' 7 | end 8 | 9 | ark 'foo' do 10 | url 'https://github.com/sous-chefs/ark/raw/main/files/default/foo.tar.gz' 11 | checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' 12 | version '2' 13 | win_install_dir 'C:\dir' 14 | owner 'foobarbaz' 15 | group 'foobar' 16 | has_binaries ['bin\do_foo', 'bin\do_more_foo'] 17 | action :install 18 | end 19 | -------------------------------------------------------------------------------- /spec/libraries/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe_helpers Ark::ProviderHelpers do 5 | before(:each) do 6 | allow_any_instance_of(Ark::ResourceDefaults).to receive(:file_cache_path).and_return('/var/chef/cache') 7 | allow(ENV).to receive(:fetch).and_call_original 8 | allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows') 9 | end 10 | 11 | describe '#owner_command' do 12 | context 'when on windows' do 13 | it 'generates a icacls command' do 14 | with_node_attributes(platform_family: 'windows') 15 | with_resource_properties(owner: 'Bobo', path: 'C:\\temp') 16 | 17 | expect(owner_command).to eq('C:\\Windows\\System32\\icacls "C:\\temp\\*" /setowner "Bobo"') 18 | end 19 | end 20 | 21 | context 'when not on windows' do 22 | it 'generates a chown command' do 23 | with_resource_properties(owner: 'MouseTrap', group: 'RatCatchers', path: '/opt/rathole') 24 | 25 | expect(owner_command).to eq('chown -R MouseTrap:RatCatchers /opt/rathole') 26 | end 27 | end 28 | end 29 | 30 | describe '#show_deprecations' do 31 | context 'when setting the strip_leading_dir property on the resource' do 32 | it 'warns that it is deprecated when set to true' do 33 | with_resource_properties(strip_leading_dir: true) 34 | expect(Chef::Log).to receive(:warn) 35 | show_deprecations 36 | end 37 | 38 | it 'warns that it is deprecated when set to false' do 39 | with_resource_properties(strip_leading_dir: false) 40 | expect(Chef::Log).to receive(:warn) 41 | show_deprecations 42 | end 43 | end 44 | 45 | context 'when the strip_leading_dir property is not set on the resource' do 46 | it 'does not produce a warning' do 47 | with_resource_properties(strip_leading_dir: nil) 48 | expect(Chef::Log).not_to receive(:warn) 49 | show_deprecations 50 | end 51 | end 52 | end 53 | 54 | describe '#set_dump_paths' do 55 | it "sets the resource's release_file" do 56 | with_resource_properties(extension: 'tar.gz', name: 'what_is_a_good_name') 57 | set_dump_paths 58 | expect(new_resource.release_file).to eq('/var/chef/cache/what_is_a_good_name.tar.gz') 59 | end 60 | end 61 | 62 | describe '#set_put_paths' do 63 | context 'when the resource path is not set' do 64 | it "sets the resource's release_file and path" do 65 | with_resource_properties(extension: 'jar', name: 'gustav-moomoo') 66 | allow(defaults).to receive(:prefix_root_from_node_in_run_context) { '/opt/default' } 67 | set_put_paths 68 | 69 | expect(new_resource.release_file).to eq('/var/chef/cache/gustav-moomoo.jar') 70 | end 71 | end 72 | 73 | context 'when the resource path has been set' do 74 | it "sets the resource's release_file and path" do 75 | with_resource_properties( 76 | extension: 'jar', 77 | name: 'gustav-tootoo', 78 | path: '/path/piece' 79 | ) 80 | set_put_paths 81 | 82 | expect(new_resource.release_file).to eq('/var/chef/cache/gustav-tootoo.jar') 83 | expect(new_resource.path).to eq('/path/piece/gustav-tootoo') 84 | end 85 | end 86 | end 87 | 88 | describe '#set_paths' do 89 | it 'uses all the defaults' do 90 | with_resource_properties(extension: 'jar', name: 'resource_name') 91 | 92 | allow(defaults).to receive(:prefix_bin) { '/default/prefix/bin' } 93 | allow(defaults).to receive(:prefix_root) { '/default/prefix/root' } 94 | allow(defaults).to receive(:home_dir) { '/default/prefix/home' } 95 | allow(defaults).to receive(:version) { '99' } 96 | allow(defaults).to receive(:path) { '/default/path' } 97 | allow(defaults).to receive(:windows?) { false } 98 | 99 | set_paths 100 | 101 | expect(new_resource.release_file).to eq('/var/chef/cache/resource_name-99.jar') 102 | end 103 | 104 | it "sets the resource's release_file" do 105 | with_resource_properties( 106 | extension: 'jar', 107 | prefix_root: '/resource/prefix/root', 108 | prefix_bin: '/resource/prefix/bin', 109 | prefix_home: '/resource/prefix/home', 110 | version: '23', 111 | name: 'resource_name' 112 | ) 113 | 114 | allow(defaults).to receive(:path) { '/default/path' } 115 | allow(defaults).to receive(:windows?) { false } 116 | 117 | set_paths 118 | 119 | chef_config_file_cache_path = '/var/chef/cache' 120 | 121 | expect(new_resource.release_file).to eq("#{chef_config_file_cache_path}/resource_name-23.jar") 122 | end 123 | end 124 | 125 | describe '#cherry_pick_command' do 126 | include_context 'seven zip installed' 127 | 128 | context "when the node's platform_family is windows" do 129 | it 'generates a 7-zip command' do 130 | with_node_attributes(platform_family: 'windows') 131 | with_resource_properties( 132 | url: 'http://website.com/windows_package.zip', 133 | path: '/resource/path', 134 | creates: '/resource/creates', 135 | release_file: '/resource/release_file', 136 | run_context: double(node: { 'ark' => { 'tar' => 'sevenzip_command' } }) 137 | ) 138 | 139 | expect(cherry_pick_command).to eq('"C:\\Program Files\\7-Zip7z.exe" x "/resource/release_file" -aoa -o"/resource/path" -uy -r /resource/creates') 140 | end 141 | end 142 | 143 | context "when the node's platform_family is not windows" do 144 | context 'when the unpack_type is tar_xzf' do 145 | it 'generates a cherry pick tar command with the correct options' do 146 | with_resource_properties( 147 | url: 'http://website.com/package.tar.gz', 148 | path: '/resource/path', 149 | creates: '/resource/creates', 150 | release_file: '/resource/release_file', 151 | strip_components: 0, 152 | run_context: double(node: { 'ark' => { 'tar' => 'tar' } }) 153 | ) 154 | 155 | expect(cherry_pick_command).to eq('tar xzf /resource/release_file -C /resource/path /resource/creates') 156 | end 157 | end 158 | 159 | context 'when the unpack_type is tar_xjf' do 160 | it 'generates a cherry pick tar command with the correct options' do 161 | with_resource_properties( 162 | url: 'http://website.com/package.tar.bz2', 163 | path: '/resource/path', 164 | creates: '/resource/creates', 165 | release_file: '/resource/release_file', 166 | strip_components: 0, 167 | run_context: double(node: { 'ark' => { 'tar' => 'tar' } }) 168 | ) 169 | 170 | expect(cherry_pick_command).to eq('tar xjf /resource/release_file -C /resource/path /resource/creates') 171 | end 172 | end 173 | 174 | context 'when the unpack_type is tar_xJf' do 175 | it 'generates a cherry pick tar command with the correct options' do 176 | with_resource_properties( 177 | url: 'http://website.com/package.txz', 178 | path: '/resource/path', 179 | creates: '/resource/creates', 180 | release_file: '/resource/release_file', 181 | strip_components: 0, 182 | run_context: double(node: { 'ark' => { 'tar' => 'tar' } }) 183 | ) 184 | 185 | expect(cherry_pick_command).to eq('tar xJf /resource/release_file -C /resource/path /resource/creates') 186 | end 187 | end 188 | 189 | context 'when the unpack_type is unzip' do 190 | it 'generates an unzip command' do 191 | with_resource_properties( 192 | url: 'http://website.com/package.zip', 193 | path: '/resource/path', 194 | creates: '/resource/creates', 195 | release_file: '/resource/release_file', 196 | run_context: double(node: { 'ark' => { 'tar' => 'unzip_command' } }) 197 | ) 198 | 199 | expect(cherry_pick_command).to eq('unzip -t /resource/release_file "*//resource/creates" ; stat=$? ;if [ $stat -eq 11 ] ; then unzip -j -o /resource/release_file "/resource/creates" -d /resource/path ;elif [ $stat -ne 0 ] ; then false ;else unzip -j -o /resource/release_file "*//resource/creates" -d /resource/path ;fi') 200 | end 201 | end 202 | end 203 | end 204 | 205 | describe '#dump_command' do 206 | context "when the node's platform_family is windows" do 207 | it 'generates a 7-zip command' do 208 | end 209 | end 210 | 211 | context "when the node's platform_family is not windows" do 212 | context 'when the unpack_type is tar_xzf' do 213 | it 'generates a tar command' do 214 | with_resource_properties( 215 | url: 'http://website.com/package.tgz', 216 | release_file: '/resource/release_file', 217 | path: '/resource/path' 218 | ) 219 | 220 | expect(dump_command).to eq('tar -mxf "/resource/release_file" -C "/resource/path"') 221 | end 222 | end 223 | 224 | context 'when the unpack_type is tar_xjf' do 225 | it 'generates a tar command' do 226 | with_resource_properties( 227 | url: 'http://website.com/package.tbz', 228 | release_file: '/resource/release_file', 229 | path: '/resource/path' 230 | ) 231 | 232 | expect(dump_command).to eq('tar -mxf "/resource/release_file" -C "/resource/path"') 233 | end 234 | end 235 | 236 | context 'when the unpack_type is tar_xJf' do 237 | it 'generates a tar command' do 238 | with_resource_properties( 239 | url: 'http://website.com/package.tar.xz', 240 | release_file: '/resource/release_file', 241 | path: '/resource/path' 242 | ) 243 | 244 | expect(dump_command).to eq('tar -mxf "/resource/release_file" -C "/resource/path"') 245 | end 246 | end 247 | 248 | context 'when the unpack_type is unzip' do 249 | it 'generates an unzip command' do 250 | with_resource_properties( 251 | url: 'http://website.com/package.jar', 252 | release_file: '/resource/release_file', 253 | path: '/resource/path' 254 | ) 255 | 256 | expect(dump_command).to eq('unzip -j -q -o "/resource/release_file" -d "/resource/path"') 257 | end 258 | end 259 | end 260 | end 261 | end 262 | -------------------------------------------------------------------------------- /spec/libraries/general_owner_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe Ark::GeneralOwner do 5 | let(:subject) { described_class.new(resource) } 6 | 7 | let(:resource) do 8 | double(owner: 'owner', 9 | group: 'group', 10 | path: '/resource/path') 11 | end 12 | 13 | it 'generates the correct command for windows file ownership' do 14 | expect(subject.command).to eq('chown -R owner:group /resource/path') 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/libraries/resource_defaults_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe Ark::ResourceDefaults do 5 | before(:each) do 6 | allow_any_instance_of(Ark::ResourceDefaults).to receive(:file_cache_path).and_return('/var/chef/cache') 7 | end 8 | 9 | describe '#extension' do 10 | it 'returns the extension parameter specified on the resource' do 11 | resource = double(extension: 'me') 12 | defaults = described_class.new(resource) 13 | expect(defaults.extension).to eq 'me' 14 | end 15 | 16 | context 'when the extension is nil' do 17 | it 'creates an extension based on the file specified in the URL' do 18 | resource = double(extension: nil, url: 'http://localhost/file.tgz') 19 | defaults = described_class.new(resource) 20 | expect(defaults.extension).to eq 'tgz' 21 | end 22 | 23 | it 'creates an extension based on the file specified in the URL (and not other words with similar names to extensions)' do 24 | resource = double(extension: nil, url: 'https://jar.binfiles.tbz/file.tar.bz2') 25 | defaults = described_class.new(resource) 26 | expect(defaults.extension).to eq 'tar.bz2' 27 | end 28 | 29 | it 'creates an extension for tar files' do 30 | resource = double(extension: nil, url: 'https://jar.binfiles.tbz/file.tar') 31 | defaults = described_class.new(resource) 32 | expect(defaults.extension).to eq 'tar' 33 | end 34 | 35 | it 'creates an extension for 7z files' do 36 | resource = double(extension: nil, url: 'https://sourceforge.net/projects/boost/files/boost/1.62.0/boost_1_62_0.7z') 37 | defaults = described_class.new(resource) 38 | expect(defaults.extension).to eq '7z' 39 | end 40 | 41 | context 'when the archive format is not supported' do 42 | it 'it returns a nil extension' do 43 | resource = double(extension: nil, url: 'http://localhost/file.stuffit') 44 | defaults = described_class.new(resource) 45 | expect(defaults.extension).to eq nil 46 | end 47 | end 48 | 49 | context 'when the url contains a query string' do 50 | it 'creates an extension based on the file specified in the URL' do 51 | resource = double(extension: nil, url: 'http://localhost/file.version.txz-bin?latest=true') 52 | defaults = described_class.new(resource) 53 | expect(defaults.extension).to eq 'txz' 54 | end 55 | end 56 | end 57 | end 58 | 59 | describe '#prefix_bin' do 60 | context 'when the prefix bin has been specified' do 61 | it 'uses the value specified' do 62 | resource = double(prefix_bin: 'prefix_bin') 63 | defaults = described_class.new(resource) 64 | expect(defaults.prefix_bin).to eq 'prefix_bin' 65 | end 66 | end 67 | 68 | context 'when the prefix bin has not been specified' do 69 | it 'uses the value on the node' do 70 | resource = double(prefix_bin: nil) 71 | defaults = described_class.new(resource) 72 | allow(defaults).to receive(:prefix_bin_from_node_in_run_context) { 'node_bin' } 73 | expect(defaults.prefix_bin).to eq 'node_bin' 74 | end 75 | end 76 | end 77 | 78 | describe '#prefix_root' do 79 | context 'when the prefix root has been specified' do 80 | it 'uses the value specified' do 81 | resource = double(prefix_root: 'prefix_root') 82 | defaults = described_class.new(resource) 83 | expect(defaults.prefix_root).to eq 'prefix_root' 84 | end 85 | end 86 | 87 | context 'when the prefix root has not been specified' do 88 | it 'uses the value on the node' do 89 | resource = double(prefix_root: nil) 90 | defaults = described_class.new(resource) 91 | allow(defaults).to receive(:prefix_root_from_node_in_run_context) { 'node_root' } 92 | expect(defaults.prefix_root).to eq 'node_root' 93 | end 94 | end 95 | end 96 | 97 | describe '#home_dir' do 98 | context 'when the home dir has been specified' do 99 | it 'uses the value specified' do 100 | resource = double(prefix_home: 'prefix_home', name: 'application', home_dir: 'home_dir') 101 | defaults = described_class.new(resource) 102 | expect(defaults.home_dir).to eq 'home_dir' 103 | end 104 | end 105 | 106 | context 'when the prefix home has been specified' do 107 | it 'uses the value specified' do 108 | resource = double(prefix_home: 'prefix_home', name: 'application', home_dir: nil) 109 | defaults = described_class.new(resource) 110 | expect(defaults.home_dir).to eq 'prefix_home/application' 111 | end 112 | end 113 | 114 | context 'when the prefix home has not been specified' do 115 | it 'uses the value on the node' do 116 | resource = double(prefix_home: nil, name: 'application', home_dir: nil) 117 | defaults = described_class.new(resource) 118 | allow(defaults).to receive(:prefix_home_from_node_in_run_context) { 'node_home' } 119 | expect(defaults.home_dir).to eq 'node_home/application' 120 | end 121 | end 122 | end 123 | 124 | describe '#version' do 125 | context 'when the version is specified' do 126 | it 'uses the version on the resource' do 127 | resource = double(version: '99') 128 | defaults = described_class.new(resource) 129 | expect(defaults.version).to eq '99' 130 | end 131 | end 132 | 133 | context 'when the version is not specified' do 134 | it 'defaults to a version' do 135 | resource = double(version: nil) 136 | defaults = described_class.new(resource) 137 | expect(defaults.version).to eq '1' 138 | end 139 | end 140 | end 141 | 142 | describe '#path' do 143 | context 'when on windows' do 144 | it 'uses the windows install dir' do 145 | resource = double(extension: 'tgz', win_install_dir: 'C:\\win_install_dir') 146 | defaults = described_class.new(resource) 147 | allow(defaults).to receive(:windows?) { true } 148 | expect(defaults.path).to eq 'C:\\win_install_dir' 149 | end 150 | end 151 | 152 | context 'when not on windows' do 153 | it 'gives the correct default' do 154 | resource = double(name: 'application', prefix_root: 'prefix/root', version: '99') 155 | defaults = described_class.new(resource) 156 | allow(defaults).to receive(:windows?) { false } 157 | expect(defaults.path).to eq 'prefix/root/application-99' 158 | end 159 | end 160 | end 161 | 162 | describe '#path_without_version' do 163 | context 'when the path is specified' do 164 | it 'gives the correct default' do 165 | resource = double(extension: 'tgz', name: 'filename', path: 'path') 166 | defaults = described_class.new(resource) 167 | expect(defaults.path_without_version).to eq 'path/filename' 168 | end 169 | end 170 | 171 | context 'when the path is not specified' do 172 | it 'gives the correct default' do 173 | resource = double(extension: 'tgz', name: 'filename', path: nil) 174 | defaults = described_class.new(resource) 175 | allow(defaults).to receive(:prefix_root_from_node_in_run_context) { 'prefix/root' } 176 | expect(defaults.path_without_version).to eq 'prefix/root/filename' 177 | end 178 | end 179 | end 180 | 181 | describe '#release_file' do 182 | it 'gives the correct default' do 183 | resource = double(extension: 'tgz', version: '1.1', name: 'filename') 184 | defaults = described_class.new(resource) 185 | expect(defaults.release_file).to eq '/var/chef/cache/filename-1.1.tgz' 186 | end 187 | end 188 | 189 | describe '#release_file_without_version' do 190 | it 'gives the correct default' do 191 | resource = double(extension: 'zip', name: 'filename') 192 | defaults = described_class.new(resource) 193 | expect(defaults.release_file_without_version).to eq '/var/chef/cache/filename.zip' 194 | end 195 | end 196 | end 197 | -------------------------------------------------------------------------------- /spec/libraries/sevenzip_command_builder_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe Ark::SevenZipCommandBuilder do 5 | let(:subject) { described_class.new(resource) } 6 | 7 | let(:resource) do 8 | double(release_file: 'release_file', 9 | creates: 'creates', 10 | path: 'path', 11 | home_dir: 'home_dir', 12 | strip_components: 1, 13 | extension: 'tar.gz') 14 | end 15 | 16 | before(:each) do 17 | allow(subject).to receive(:sevenzip_binary) { '"C:\\Program Files\\7-zip\\7z.exe"' } 18 | allow(ENV).to receive(:fetch).and_call_original 19 | allow(ENV).to receive(:fetch).with('SystemRoot').and_return('c:\\Windows') 20 | end 21 | 22 | describe '#unpack' do 23 | it 'generates the correct command' do 24 | allow(subject).to receive(:make_temp_directory) { 'temp_directory' } 25 | expected_command = "\"C:\\Program Files\\7-zip\\7z.exe\" x \"release_file\" -so | \"C:\\Program Files\\7-zip\\7z.exe\" x -aoa -si -ttar -o\"temp_directory\" -uy && for /f %1 in ('dir /ad /b \"temp_directory\"') do (\"c:\\Windows\\System32\\robocopy\" \"temp_directory\\%1\" \"path\" /s /e) ^& IF %ERRORLEVEL% LEQ 3 cmd /c exit 0" 26 | expect(subject.unpack).to eq(expected_command) 27 | end 28 | end 29 | 30 | describe '#dump' do 31 | it 'generates the correct command' do 32 | expected_command = '"C:\\Program Files\\7-zip\\7z.exe" e "release_file" -so | "C:\\Program Files\\7-zip\\7z.exe" x -aoa -si -ttar -o"path" -uy' 33 | expect(subject.dump).to eq(expected_command) 34 | end 35 | end 36 | 37 | describe '#cherry_pick' do 38 | it 'generates the correct command' do 39 | expected_command = '"C:\\Program Files\\7-zip\\7z.exe" x "release_file" -so | "C:\\Program Files\\7-zip\\7z.exe" x -aoa -si -ttar -o"path" -uy -r creates' 40 | expect(subject.cherry_pick).to eq(expected_command) 41 | end 42 | end 43 | 44 | context 'strip_components == 0' do 45 | describe '#unpack' do 46 | it 'generates the correct command' do 47 | allow(resource).to receive(:strip_components).and_return(0) 48 | expected_command = '"C:\\Program Files\\7-zip\\7z.exe" x "release_file" -so | "C:\\Program Files\\7-zip\\7z.exe" x -aoa -si -ttar -o"path" -uy' 49 | expect(subject.unpack).to eq(expected_command) 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /spec/libraries/tar_command_builder_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe Ark::TarCommandBuilder do 5 | let(:subject) { described_class.new(resource) } 6 | 7 | let(:resource) do 8 | double(release_file: 'release_file', 9 | creates: 'creates', 10 | path: 'path', 11 | strip_components: 1, 12 | extension: 'tar.gz') 13 | end 14 | 15 | before(:each) do 16 | allow(subject).to receive(:tar_binary) { '/bin/tar' } 17 | end 18 | 19 | describe '#unpack' do 20 | context 'when the extension is supported' do 21 | it 'generates the correct command' do 22 | expected_command = '/bin/tar xzf release_file --strip-components=1' 23 | expect(subject.unpack).to eq(expected_command) 24 | end 25 | end 26 | 27 | context 'when the extension is tar (only tar)' do 28 | let(:resource) do 29 | double(release_file: 'release_file', 30 | creates: 'creates', 31 | path: 'path', 32 | strip_components: 1, 33 | extension: 'tar') 34 | end 35 | 36 | it 'generates the correct command' do 37 | expected_command = '/bin/tar xf release_file --strip-components=1' 38 | expect(subject.unpack).to eq(expected_command) 39 | end 40 | end 41 | 42 | context 'when the extension is not supported' do 43 | let(:resource) do 44 | double(release_file: 'release_file', 45 | url: 'http://website.com/files/content.stuffit', 46 | creates: 'creates', 47 | path: 'path', 48 | strip_components: 1, 49 | extension: 'stuffit') 50 | end 51 | 52 | it 'generates a failure' do 53 | expect { subject.unpack }.to raise_error("Don't know how to expand http://website.com/files/content.stuffit (extension: stuffit)") 54 | end 55 | end 56 | end 57 | 58 | describe '#dump' do 59 | it 'generates the correct command' do 60 | expected_command = 'tar -mxf "release_file" -C "path"' 61 | expect(subject.dump).to eq(expected_command) 62 | end 63 | end 64 | 65 | describe '#cherry_pick' do 66 | it 'generates the correct command' do 67 | expected_command = '/bin/tar xzf release_file -C path --strip-components=1 creates' 68 | expect(subject.cherry_pick).to eq(expected_command) 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /spec/libraries/unzip_command_builder_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe Ark::UnzipCommandBuilder do 5 | let(:subject) { described_class.new(resource) } 6 | 7 | let(:resource) do 8 | double(release_file: 'release_file', 9 | creates: 'creates', 10 | path: 'path', 11 | strip_components: 0) 12 | end 13 | 14 | describe '#unpack' do 15 | context 'when the resource does not strip components' do 16 | it 'generates the correct command' do 17 | expected_command = 'unzip -q -o release_file -d path' 18 | expect(subject.unpack).to eq(expected_command) 19 | end 20 | end 21 | 22 | context 'when the resource does strip components' do 23 | let(:resource) do 24 | double(release_file: 'release_file', 25 | creates: 'creates', 26 | path: 'path', 27 | strip_components: 1) 28 | end 29 | 30 | it 'generates the correct command' do 31 | expected_command = 'unzip -q -o release_file -d temp_directory && rsync -a temp_directory/*/ path && rm -rf temp_directory' 32 | allow(subject).to receive(:make_temp_directory) { 'temp_directory' } 33 | expect(subject.unpack).to eq(expected_command) 34 | end 35 | end 36 | end 37 | 38 | describe '#dump' do 39 | it 'generates the correct command' do 40 | expected_command = 'unzip -j -q -o "release_file" -d "path"' 41 | expect(subject.dump).to eq(expected_command) 42 | end 43 | end 44 | 45 | describe '#cherry_pick' do 46 | it 'generates the correct command' do 47 | expected_command = 'unzip -t release_file "*/creates" ; stat=$? ;if [ $stat -eq 11 ] ; then unzip -j -o release_file "creates" -d path ;elif [ $stat -ne 0 ] ; then false ;else unzip -j -o release_file "*/creates" -d path ;fi' 48 | expect(subject.cherry_pick).to eq(expected_command) 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /spec/libraries/windows_owner_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe Ark::WindowsOwner do 5 | let(:subject) { described_class.new(resource) } 6 | 7 | let(:resource) { double(path: 'c:\\resource with spaces\\path', owner: 'the new owner') } 8 | 9 | before(:each) do 10 | allow(ENV).to receive(:fetch).and_call_original 11 | allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows') 12 | end 13 | 14 | it 'generates the correct command for windows file ownership' do 15 | expect(subject.command).to eq('C:\\Windows\\System32\\icacls "c:\\resource with spaces\\path\\*" /setowner "the new owner"') 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/recipes/centos/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'centos', version: '6' } 6 | end 7 | 8 | it 'installs core packages' do 9 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc xz-lzma-compat bzip2 tar)) 10 | end 11 | end 12 | 13 | describe_recipe 'ark::default' do 14 | def node_attributes 15 | { platform: 'centos', version: '7' } 16 | end 17 | 18 | it 'installs core packages' do 19 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc xz bzip2 tar)) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/recipes/debian/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'debian' } 6 | end 7 | 8 | it 'installs core packages' do 9 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc autogen shtool pkg-config)) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | platform 'ubuntu' 5 | 6 | it 'installs core packages' do 7 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc autogen shtool pkg-config)) 8 | end 9 | 10 | it 'does not install the gcc-c++ package' do 11 | expect(chef_run).not_to install_package('gcc-c++') 12 | end 13 | 14 | it do 15 | expect(chef_run).not_to install_seven_zip_tool 'ark' 16 | end 17 | 18 | context 'sets default attributes' do 19 | it 'apache mirror' do 20 | expect(default_cookbook_attribute('apache_mirror')).to eq 'http://apache.mirrors.tds.net' 21 | end 22 | 23 | it 'prefix root' do 24 | expect(default_cookbook_attribute('prefix_root')).to eq '/usr/local' 25 | end 26 | 27 | it 'prefix bin' do 28 | expect(default_cookbook_attribute('prefix_bin')).to eq '/usr/local/bin' 29 | end 30 | 31 | it 'prefix home' do 32 | expect(default_cookbook_attribute('prefix_home')).to eq '/usr/local' 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/recipes/fedora/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'fedora' } 6 | end 7 | 8 | it 'installs core packages' do 9 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc xz-lzma-compat bzip2 tar)) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/freebsd/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'freebsd' } 6 | end 7 | 8 | it 'installs core packages' do 9 | expect(chef_run).to install_package(%w(libtool autoconf unzip rsync gcc autogen gtar gmake)) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/suse/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'opensuse' } 6 | end 7 | 8 | it 'installs core packages' do 9 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc xz bzip2 tar)) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/ubuntu/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'ubuntu' } 6 | end 7 | 8 | it 'installs core packages' do 9 | expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc autogen shtool pkg-config)) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/windows/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe_recipe 'ark::default' do 4 | def node_attributes 5 | { platform: 'windows' } 6 | end 7 | 8 | it do 9 | expect(chef_run).to install_seven_zip_tool 'ark' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/resources/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require './libraries/default' 3 | 4 | describe_resource 'ark' do 5 | describe 'install' do 6 | let(:example_recipe) { 'ark_spec::install' } 7 | 8 | it 'installs' do 9 | expect(chef_run).to install_ark('test_install') 10 | 11 | expect(chef_run).to create_directory('/usr/local/test_install-2') 12 | resource = chef_run.directory('/usr/local/test_install-2') 13 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install-2.tar.gz]').to(:run) 14 | 15 | expect(chef_run).to create_remote_file('/var/chef/cache/test_install-2.tar.gz') 16 | resource = chef_run.remote_file('/var/chef/cache/test_install-2.tar.gz') 17 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install-2.tar.gz]').to(:run) 18 | 19 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_install-2.tar.gz') 20 | resource = chef_run.execute('unpack /var/chef/cache/test_install-2.tar.gz') 21 | expect(resource).to notify('execute[set owner on /usr/local/test_install-2]').to(:run) 22 | 23 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_install-2') 24 | 25 | expect(chef_run).not_to create_template('/etc/profile.d/test_install.sh') 26 | expect(chef_run).not_to run_ruby_block("adding '/usr/local/test_install-2/bin' to chef-client ENV['PATH']") 27 | end 28 | end 29 | 30 | describe 'install with binaries' do 31 | let(:example_recipe) { 'ark_spec::install_with_binaries' } 32 | 33 | it 'installs' do 34 | expect(chef_run).to install_ark('test_install') 35 | 36 | expect(chef_run).to create_directory('/usr/local/test_install-2') 37 | resource = chef_run.directory('/usr/local/test_install-2') 38 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install-2.tar.gz]').to(:run) 39 | 40 | expect(chef_run).to create_remote_file('/var/chef/cache/test_install-2.tar.gz') 41 | resource = chef_run.remote_file('/var/chef/cache/test_install-2.tar.gz') 42 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install-2.tar.gz]').to(:run) 43 | 44 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_install-2.tar.gz') 45 | resource = chef_run.execute('unpack /var/chef/cache/test_install-2.tar.gz') 46 | expect(resource).to notify('execute[set owner on /usr/local/test_install-2]').to(:run) 47 | 48 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_install-2') 49 | 50 | expect(chef_run).to create_link('/usr/local/bin/do_foo') 51 | expect(chef_run).to create_link('/usr/local/bin/do_more_foo') 52 | expect(chef_run).to create_link('/usr/local/test_install') 53 | 54 | expect(chef_run).not_to create_template('/etc/profile.d/test_install.sh') 55 | expect(chef_run).not_to run_ruby_block("adding '/usr/local/test_install-2/bin' to chef-client ENV['PATH']") 56 | end 57 | end 58 | 59 | describe 'install with append_env_path' do 60 | context 'binary is not already in the environment path' do 61 | let(:example_recipe) { 'ark_spec::install_with_append_env_path' } 62 | 63 | it 'installs' do 64 | expect(chef_run).to install_ark('test_install_with_append_env_path') 65 | 66 | expect(chef_run).to create_directory('/usr/local/test_install_with_append_env_path-7.0.26') 67 | resource = chef_run.directory('/usr/local/test_install_with_append_env_path-7.0.26') 68 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz]').to(:run) 69 | 70 | expect(chef_run).to create_remote_file('/var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 71 | resource = chef_run.remote_file('/var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 72 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz]').to(:run) 73 | 74 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 75 | resource = chef_run.execute('unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 76 | expect(resource).to notify('execute[set owner on /usr/local/test_install_with_append_env_path-7.0.26]').to(:run) 77 | 78 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_install_with_append_env_path-7.0.26') 79 | 80 | expect(chef_run).to create_link('/usr/local/test_install_with_append_env_path') 81 | 82 | expect(chef_run).to create_template('/etc/profile.d/test_install_with_append_env_path.sh') 83 | expect(chef_run).to run_ruby_block("adding '/usr/local/test_install_with_append_env_path-7.0.26/bin' to chef-client ENV['PATH']") 84 | end 85 | end 86 | 87 | context 'binary is already in the environment path' do 88 | let(:example_recipe) { 'ark_spec::install_with_append_env_path' } 89 | 90 | # TODO: Using the ENV is terrible -- attempts to replace it with a helper 91 | # method did not work or a class with a method. Explore different ways 92 | # to inject the value instead of using this way. 93 | 94 | before do 95 | @old_paths = ENV['PATH'] 96 | ENV['PATH'] = '/usr/local/test_install_with_append_env_path-7.0.26/bin' 97 | end 98 | 99 | after do 100 | ENV['PATH'] = @old_paths 101 | end 102 | 103 | it 'installs' do 104 | expect(chef_run).to install_ark('test_install_with_append_env_path') 105 | 106 | expect(chef_run).to create_directory('/usr/local/test_install_with_append_env_path-7.0.26') 107 | resource = chef_run.directory('/usr/local/test_install_with_append_env_path-7.0.26') 108 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz]').to(:run) 109 | 110 | expect(chef_run).to create_remote_file('/var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 111 | resource = chef_run.remote_file('/var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 112 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz]').to(:run) 113 | 114 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 115 | resource = chef_run.execute('unpack /var/chef/cache/test_install_with_append_env_path-7.0.26.tar.gz') 116 | expect(resource).to notify('execute[set owner on /usr/local/test_install_with_append_env_path-7.0.26]').to(:run) 117 | 118 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_install_with_append_env_path-7.0.26') 119 | 120 | expect(chef_run).to create_link('/usr/local/test_install_with_append_env_path') 121 | 122 | expect(chef_run).to create_template('/etc/profile.d/test_install_with_append_env_path.sh') 123 | expect(chef_run).not_to run_ruby_block("adding '/usr/local/test_install_with_append_env_path-7.0.26/bin' to chef-client ENV['PATH']") 124 | end 125 | end 126 | end 127 | 128 | describe 'install on windows' do 129 | include_context('seven zip installed') 130 | 131 | let(:example_recipe) { 'ark_spec::install_windows' } 132 | 133 | before(:each) do 134 | allow(ENV).to receive(:fetch).and_call_original 135 | allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows') 136 | end 137 | 138 | def node_attributes 139 | { platform: 'windows', version: '10' } 140 | end 141 | 142 | it 'installs' do 143 | expect(chef_run).to install_ark('test_install') 144 | 145 | expect(chef_run).to create_directory('C:\\install') 146 | resource = chef_run.directory('C:\\install') 147 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install-2.tar.gz]').to(:run) 148 | 149 | expect(chef_run).to create_remote_file('/var/chef/cache/test_install-2.tar.gz') 150 | resource = chef_run.remote_file('/var/chef/cache/test_install-2.tar.gz') 151 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install-2.tar.gz]').to(:run) 152 | 153 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_install-2.tar.gz') 154 | resource = chef_run.execute('unpack /var/chef/cache/test_install-2.tar.gz') 155 | expect(resource).to notify('execute[set owner on C:\\install]').to(:run) 156 | 157 | expect(chef_run).not_to run_execute('set owner on C:\\install') 158 | 159 | expect(chef_run).not_to create_link('/usr/local/bin/do_foo') 160 | expect(chef_run).not_to create_link('/usr/local/bin/do_more_foo') 161 | expect(chef_run).not_to create_link('/usr/local/test_install') 162 | 163 | expect(chef_run).not_to create_template('/etc/profile.d/test_install.sh') 164 | expect(chef_run).not_to run_ruby_block("adding 'C:\\install/bin' to chef-client ENV['PATH']") 165 | end 166 | end 167 | 168 | describe 'put' do 169 | let(:example_recipe) { 'ark_spec::put' } 170 | 171 | it 'puts' do 172 | expect(chef_run).to put_ark('test_put') 173 | 174 | expect(chef_run).to create_directory('/usr/local/test_put') 175 | resource = chef_run.directory('/usr/local/test_put') 176 | expect(resource).to notify('execute[unpack /var/chef/cache/test_put.tar.gz]').to(:run) 177 | 178 | expect(chef_run).to create_remote_file('/var/chef/cache/test_put.tar.gz') 179 | resource = chef_run.remote_file('/var/chef/cache/test_put.tar.gz') 180 | expect(resource).to notify('execute[unpack /var/chef/cache/test_put.tar.gz]').to(:run) 181 | 182 | expect(chef_run).to_not run_execute('unpack /var/chef/cache/test_put.tar.gz') 183 | expect(chef_run).to_not run_execute('set owner on /usr/local/test_put') 184 | end 185 | end 186 | 187 | describe 'dump' do 188 | let(:example_recipe) { 'ark_spec::dump' } 189 | 190 | it 'dumps' do 191 | expect(chef_run).to dump_ark('test_dump') 192 | 193 | expect(chef_run).to create_directory('/usr/local/foo_dump') 194 | resource = chef_run.directory('/usr/local/foo_dump') 195 | expect(resource).to notify('execute[unpack /var/chef/cache/test_dump.zip]').to(:run) 196 | 197 | expect(chef_run).to create_remote_file('/var/chef/cache/test_dump.zip') 198 | resource = chef_run.remote_file('/var/chef/cache/test_dump.zip') 199 | expect(resource).to notify('execute[unpack /var/chef/cache/test_dump.zip]').to(:run) 200 | 201 | expect(chef_run).to_not run_execute('unpack /var/chef/cache/test_dump.zip') 202 | expect(chef_run).to_not run_execute('set owner on /usr/local/foo_dump') 203 | end 204 | end 205 | 206 | describe 'unzip' do 207 | let(:example_recipe) { 'ark_spec::unzip' } 208 | 209 | it 'unzips' do 210 | expect(chef_run).to unzip_ark('test_unzip') 211 | 212 | expect(chef_run).to create_directory('/usr/local/foo_dump') 213 | resource = chef_run.directory('/usr/local/foo_dump') 214 | expect(resource).to notify('execute[unpack /var/chef/cache/test_unzip.zip]').to(:run) 215 | 216 | expect(chef_run).to create_remote_file('/var/chef/cache/test_unzip.zip') 217 | resource = chef_run.remote_file('/var/chef/cache/test_unzip.zip') 218 | expect(resource).to notify('execute[unpack /var/chef/cache/test_unzip.zip]').to(:run) 219 | 220 | expect(chef_run).to_not run_execute('unpack /var/chef/cache/test_unzip.zip') 221 | expect(chef_run).to_not run_execute('set owner on /usr/local/foo_dump') 222 | end 223 | end 224 | 225 | describe 'cherry_pick' do 226 | let(:example_recipe) { 'ark_spec::cherry_pick' } 227 | 228 | it 'cherry picks' do 229 | expect(chef_run).to cherry_pick_ark('test_cherry_pick') 230 | 231 | expect(chef_run).to create_directory('/usr/local/foo_cherry_pick') 232 | resource = chef_run.directory('/usr/local/foo_cherry_pick') 233 | expect(resource).to notify('execute[cherry_pick foo_sub/foo1.txt from /var/chef/cache/test_cherry_pick.tar.gz]').to(:run) 234 | 235 | expect(chef_run).to create_remote_file('/var/chef/cache/test_cherry_pick.tar.gz') 236 | resource = chef_run.remote_file('/var/chef/cache/test_cherry_pick.tar.gz') 237 | expect(resource).to notify('execute[cherry_pick foo_sub/foo1.txt from /var/chef/cache/test_cherry_pick.tar.gz]').to(:run) 238 | 239 | resource = chef_run.execute('cherry_pick foo_sub/foo1.txt from /var/chef/cache/test_cherry_pick.tar.gz') 240 | expect(resource).to notify('execute[set owner on /usr/local/foo_cherry_pick]').to(:run) 241 | 242 | expect(chef_run).to_not run_execute('cherry_pick foo_sub/foo1.txt from /var/chef/cache/test_cherry_pick.tar.gz') 243 | expect(chef_run).to_not run_execute('set owner on /usr/local/foo_cherry_pick') 244 | end 245 | end 246 | 247 | describe 'setup_py_build' do 248 | let(:example_recipe) { 'ark_spec::setup_py_build' } 249 | 250 | it 'builds with python setup.py' do 251 | expect(chef_run).to setup_py_build_ark('test_setup_py_build') 252 | 253 | expect(chef_run).to create_directory('/usr/local/test_setup_py_build-1') 254 | resource = chef_run.directory('/usr/local/test_setup_py_build-1') 255 | expect(resource).to notify('execute[unpack /var/chef/cache/test_setup_py_build-1.tar.gz]').to(:run) 256 | 257 | expect(chef_run).to create_remote_file('/var/chef/cache/test_setup_py_build-1.tar.gz') 258 | resource = chef_run.remote_file('/var/chef/cache/test_setup_py_build-1.tar.gz') 259 | expect(resource).to notify('execute[unpack /var/chef/cache/test_setup_py_build-1.tar.gz]').to(:run) 260 | 261 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_setup_py_build-1.tar.gz') 262 | resource = chef_run.execute('unpack /var/chef/cache/test_setup_py_build-1.tar.gz') 263 | expect(resource).to notify('execute[set owner on /usr/local/test_setup_py_build-1]') 264 | expect(resource).to notify('execute[python setup.py build /usr/local/test_setup_py_build-1]') 265 | 266 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_setup_py_build-1') 267 | expect(chef_run).not_to run_execute('python setup.py build /usr/local/test_setup_py_build-1') 268 | end 269 | end 270 | 271 | describe 'setup_py_install' do 272 | let(:example_recipe) { 'ark_spec::setup_py_install' } 273 | 274 | it 'installs with python setup.py' do 275 | expect(chef_run).to setup_py_install_ark('test_setup_py_install') 276 | 277 | expect(chef_run).to create_directory('/usr/local/test_setup_py_install-1') 278 | expect(chef_run).to create_remote_file('/var/chef/cache/test_setup_py_install-1.tar.gz') 279 | resource = chef_run.remote_file('/var/chef/cache/test_setup_py_install-1.tar.gz') 280 | expect(resource).to notify('execute[unpack /var/chef/cache/test_setup_py_install-1.tar.gz]').to(:run) 281 | 282 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_setup_py_install-1.tar.gz') 283 | resource = chef_run.execute('unpack /var/chef/cache/test_setup_py_install-1.tar.gz') 284 | expect(resource).to notify('execute[set owner on /usr/local/test_setup_py_install-1]') 285 | expect(resource).to notify('execute[python setup.py install /usr/local/test_setup_py_install-1]') 286 | 287 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_setup_py_install-1') 288 | expect(chef_run).not_to run_execute('python setup.py install /usr/local/test_setup_py_install-1') 289 | end 290 | end 291 | 292 | describe 'setup_py' do 293 | let(:example_recipe) { 'ark_spec::setup_py' } 294 | 295 | it 'runs with python setup.py' do 296 | expect(chef_run).to setup_py_ark('test_setup_py') 297 | 298 | expect(chef_run).to create_directory('/usr/local/test_setup_py-1') 299 | expect(chef_run).to create_remote_file('/var/chef/cache/test_setup_py-1.tar.gz') 300 | resource = chef_run.remote_file('/var/chef/cache/test_setup_py-1.tar.gz') 301 | expect(resource).to notify('execute[unpack /var/chef/cache/test_setup_py-1.tar.gz]').to(:run) 302 | 303 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_setup_py-1.tar.gz') 304 | resource = chef_run.execute('unpack /var/chef/cache/test_setup_py-1.tar.gz') 305 | expect(resource).to notify('execute[set owner on /usr/local/test_setup_py-1]') 306 | expect(resource).to notify('execute[python setup.py /usr/local/test_setup_py-1]') 307 | 308 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_setup_py') 309 | expect(chef_run).not_to run_execute('python setup.py /usr/local/test_setup_py') 310 | end 311 | end 312 | 313 | describe 'install_with_make' do 314 | let(:example_recipe) { 'ark_spec::install_with_make' } 315 | 316 | it 'installs with make' do 317 | expect(chef_run).to install_with_make_ark('test_install_with_make') 318 | 319 | expect(chef_run).to create_directory('/usr/local/test_install_with_make-1.5') 320 | resource = chef_run.directory('/usr/local/test_install_with_make-1.5') 321 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install_with_make-1.5.tar.gz]').to(:run) 322 | 323 | expect(chef_run).to create_remote_file('/var/chef/cache/test_install_with_make-1.5.tar.gz') 324 | resource = chef_run.remote_file('/var/chef/cache/test_install_with_make-1.5.tar.gz') 325 | expect(resource).to notify('execute[unpack /var/chef/cache/test_install_with_make-1.5.tar.gz]').to(:run) 326 | 327 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_install_with_make-1.5.tar.gz') 328 | resource = chef_run.execute('unpack /var/chef/cache/test_install_with_make-1.5.tar.gz') 329 | expect(resource).to notify('execute[set owner on /usr/local/test_install_with_make-1.5]') 330 | expect(resource).to notify('execute[autogen /usr/local/test_install_with_make-1.5]') 331 | expect(resource).to notify('execute[configure /usr/local/test_install_with_make-1.5]') 332 | expect(resource).to notify('execute[make /usr/local/test_install_with_make-1.5]') 333 | expect(resource).to notify('execute[make install /usr/local/test_install_with_make-1.5]') 334 | 335 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_install_with_make-1.5') 336 | expect(chef_run).not_to run_execute('autogen /usr/local/test_install_with_make-1.5') 337 | expect(chef_run).not_to run_execute('configure /usr/local/test_install_with_make-1.5') 338 | expect(chef_run).not_to run_execute('make /usr/local/test_install_with_make-1.5') 339 | expect(chef_run).not_to run_execute('make install /usr/local/test_install_with_make-1.5') 340 | end 341 | end 342 | 343 | describe 'configure' do 344 | let(:example_recipe) { 'ark_spec::configure' } 345 | 346 | it 'configures' do 347 | expect(chef_run).to configure_ark('test_configure') 348 | 349 | expect(chef_run).to create_directory('/usr/local/test_configure-1') 350 | resource = chef_run.directory('/usr/local/test_configure-1') 351 | expect(resource).to notify('execute[unpack /var/chef/cache/test_configure-1.tar.gz]').to(:run) 352 | 353 | expect(chef_run).to create_remote_file('/var/chef/cache/test_configure-1.tar.gz') 354 | resource = chef_run.remote_file('/var/chef/cache/test_configure-1.tar.gz') 355 | expect(resource).to notify('execute[unpack /var/chef/cache/test_configure-1.tar.gz]').to(:run) 356 | 357 | expect(chef_run).not_to run_execute('unpack /var/chef/cache/test_configure-1.tar.gz') 358 | resource = chef_run.execute('unpack /var/chef/cache/test_configure-1.tar.gz') 359 | expect(resource).to notify('execute[set owner on /usr/local/test_configure-1]') 360 | expect(resource).to notify('execute[autogen /usr/local/test_configure-1]') 361 | expect(resource).to notify('execute[configure /usr/local/test_configure-1]') 362 | 363 | expect(chef_run).not_to run_execute('set owner on /usr/local/test_configure-1') 364 | expect(chef_run).not_to run_execute('autogen /usr/local/test_configure-1') 365 | expect(chef_run).not_to run_execute('configure /usr/local/test_configure-1') 366 | end 367 | end 368 | end 369 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | RSpec.configure do |config| 5 | config.color = true 6 | config.alias_example_group_to :describe_recipe, type: :recipe 7 | config.alias_example_group_to :describe_helpers, type: :helpers 8 | config.alias_example_group_to :describe_resource, type: :resource 9 | config.file_cache_path = '/var/chef/cache' 10 | config.log_level = :warn 11 | config.platform = 'ubuntu' 12 | end 13 | 14 | def stringify_keys(hash) 15 | hash.each_with_object({}) do |(k, v), base| 16 | v = stringify_keys(v) if v.is_a? Hash 17 | base[k.to_s] = v 18 | base 19 | end 20 | end 21 | 22 | RSpec.shared_context 'recipe tests', type: :recipe do 23 | let(:chef_run) { ChefSpec::SoloRunner.new(node_attributes).converge(described_recipe) } 24 | 25 | let(:node) { chef_run.node } 26 | 27 | def node_attributes 28 | {} 29 | end 30 | 31 | def cookbook_recipe_names 32 | described_recipe.split('::', 2) 33 | end 34 | 35 | def cookbook_name 36 | cookbook_recipe_names.first 37 | end 38 | 39 | def recipe_name 40 | cookbook_recipe_names.last 41 | end 42 | 43 | def default_cookbook_attribute(attribute_name) 44 | node[cookbook_name][attribute_name] 45 | end 46 | end 47 | 48 | RSpec.shared_context 'helpers tests', type: :helpers do 49 | include described_class 50 | 51 | let(:new_resource) { OpenStruct.new(resource_properties) } 52 | 53 | def resource_properties 54 | @resource_properties || {} 55 | end 56 | 57 | def with_resource_properties(properties) 58 | @resource_properties = properties 59 | end 60 | 61 | let(:node) do 62 | Fauxhai.mock { |node| node.merge!(node_attributes) }.data 63 | end 64 | 65 | def node_attributes 66 | stringify_keys(@node_attributes || {}) 67 | end 68 | 69 | def with_node_attributes(attributes) 70 | @node_attributes = attributes 71 | end 72 | end 73 | 74 | RSpec.shared_context 'resource tests', type: :resource do 75 | let(:chef_run) do 76 | ChefSpec::SoloRunner.new(node_attributes.merge(step_into)).converge(example_recipe) 77 | end 78 | 79 | let(:example_recipe) do 80 | raise %( 81 | Please specify the name of the test recipe that executes your recipe: 82 | 83 | let(:example_recipe) do 84 | "ark_spec::put" 85 | end 86 | 87 | ) 88 | end 89 | 90 | let(:node) { chef_run.node } 91 | 92 | def node_attributes 93 | {} 94 | end 95 | 96 | let(:step_into) do 97 | { step_into: [cookbook_name] } 98 | end 99 | 100 | def cookbook_recipe_names 101 | described_recipe.split('::', 2) 102 | end 103 | 104 | def cookbook_name 105 | cookbook_recipe_names.first 106 | end 107 | 108 | def recipe_name 109 | cookbook_recipe_names.last 110 | end 111 | end 112 | 113 | shared_context 'seven zip installed' do 114 | let(:fake_hkey_local_machine) do 115 | fake_hkey_local_machine = double('fake_hkey_local_machine') 116 | seven_zip_win32_registry = double('seven_zip_registry') 117 | allow(seven_zip_win32_registry).to receive(:read_s).with('Path').and_return('C:\\Program Files\\7-Zip') 118 | allow(fake_hkey_local_machine).to receive(:open).with('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').and_return(seven_zip_win32_registry) 119 | fake_hkey_local_machine 120 | end 121 | 122 | before(:each) do 123 | unless defined? ::Win32 124 | module Win32 125 | class Registry 126 | end 127 | end 128 | end 129 | stub_const('::Win32::Registry::HKEY_LOCAL_MACHINE', fake_hkey_local_machine) 130 | stub_const('::Win32::Registry::Error', double('win32_registry_error')) unless defined? ::Win32::Registry::Error 131 | end 132 | end 133 | -------------------------------------------------------------------------------- /templates/add_to_path.sh.erb: -------------------------------------------------------------------------------- 1 | export PATH=<%= @directory -%>:$PATH 2 | --------------------------------------------------------------------------------