├── .editorconfig ├── .envrc ├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ ├── ci.yml │ └── stale.yml ├── .gitignore ├── .markdownlint-cli2.yaml ├── .mdlrc ├── .overcommit.yml ├── .vscode └── extensions.json ├── .yamllint ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dangerfile ├── LICENSE ├── Policyfile.rb ├── README.md ├── TESTING.md ├── attributes └── default.rb ├── chefignore ├── documentation └── .gitkeep ├── kitchen.dokken.yml ├── kitchen.exec.yml ├── kitchen.global.yml ├── kitchen.yml ├── libraries └── helpers.rb ├── metadata.rb ├── recipes ├── cask.rb ├── default.rb ├── install_casks.rb ├── install_formulas.rb └── install_taps.rb ├── renovate.json ├── resources ├── cask.rb └── tap.rb ├── spec ├── spec_helper.rb └── unit │ └── libraries │ └── homebrew_helpers_spec.rb └── test ├── cookbooks └── test │ ├── metadata.rb │ └── recipes │ └── default.rb └── integration └── default └── default_spec.rb /.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 | with: 14 | platform: macos-latest 15 | permissions: 16 | actions: write 17 | checks: write 18 | pull-requests: write 19 | statuses: write 20 | issues: write 21 | 22 | integration: 23 | needs: "lint-unit" 24 | runs-on: macos-latest 25 | strategy: 26 | matrix: 27 | os: [macos-latest] 28 | suite: ["default"] 29 | fail-fast: false 30 | steps: 31 | - name: Check out code 32 | uses: actions/checkout@v4 33 | - name: Install Chef 34 | uses: actionshub/chef-install@3.0.1 35 | - name: test-kitchen 36 | uses: actionshub/test-kitchen@3.0.0 37 | env: 38 | CHEF_LICENSE: accept-no-persist 39 | KITCHEN_LOCAL_YAML: kitchen.exec.yml 40 | with: 41 | suite: ${{ matrix.suite }} 42 | os: ${{ matrix.os }} 43 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # homebrew Cookbook CHANGELOG 2 | 3 | This file is used to list changes made in each version of the homebrew cookbook. 4 | 5 | ## Unreleased 6 | 7 | ## 6.0.1 - *2025-03-24* 8 | 9 | ## 6.0.0 - *2025-03-17* 10 | 11 | - Updated library call for new homebrew class name found in chef-client 18.6.2+ releases 12 | 13 | ## 5.4.9 - *2024-11-18* 14 | 15 | Standardise files with files in sous-chefs/repo-management 16 | 17 | Standardise files with files in sous-chefs/repo-management 18 | 19 | Standardise files with files in sous-chefs/repo-management 20 | 21 | Standardise files with files in sous-chefs/repo-management 22 | 23 | Standardise files with files in sous-chefs/repo-management 24 | 25 | ## 5.4.8 - *2024-05-07* 26 | 27 | ## 5.4.7 - *2024-05-06* 28 | 29 | - Explicitly include `Which` module from `Chef` which fixes runs on 18.x clients. 30 | 31 | ## 5.4.6 - *2024-05-06* 32 | 33 | ## 5.4.5 - *2023-11-01* 34 | 35 | Standardise files with files in sous-chefs/repo-management 36 | 37 | ## 5.4.4 - *2023-09-28* 38 | 39 | ## 5.4.3 - *2023-09-04* 40 | 41 | ## 5.4.2 - *2023-07-10* 42 | 43 | ## 5.4.1 - *2023-06-01* 44 | 45 | ## 5.4.0 - *2023-04-24* 46 | 47 | - Add temporary sudoers entry to fix homebrew installation 48 | 49 | ## 5.3.8 - *2023-04-16* 50 | 51 | Standardise files with files in sous-chefs/repo-management 52 | 53 | ## 5.3.7 - *2023-04-04* 54 | 55 | - Sous Chefs adoption 56 | - Update lint-unit workflow to 2.0.2 57 | - Set unified_mode for all resources 58 | - Require Chef 15.3+ for unified_mode 59 | - Standardise files with files in sous-chefs/repo-management 60 | 61 | ## 5.3.6 - *2023-04-01* 62 | 63 | - Standardise files with files in sous-chefs/repo-management 64 | 65 | ## 5.3.5 - *2023-03-02* 66 | 67 | - Standardise files with files in sous-chefs/repo-management 68 | 69 | ## 5.3.4 - *2023-02-20* 70 | 71 | - Standardise files with files in sous-chefs/repo-management 72 | 73 | ## 5.3.4 - *2023-02-20* 74 | 75 | - Standardise files with files in sous-chefs/repo-management 76 | 77 | ## 5.3.3 - *2023-02-14* 78 | 79 | - Standardise files with files in sous-chefs/repo-management 80 | 81 | ## 5.3.2 - *2022-12-15* 82 | 83 | - Standardise files with files in sous-chefs/repo-management 84 | - Fix workflow CI 85 | 86 | ## 5.3.1 - *2022-02-10* 87 | 88 | - Standardise files with files in sous-chefs/repo-management 89 | - Remove delivery folder 90 | 91 | ## 5.3.0 - *2021-12-21* 92 | 93 | - Update to support Apple M1 silicon (arm64) Homebrew install location (`/opt/homebrew`) 94 | - Add HomebrewWrapper.repository_path() for homebrew_tap resource idempotency 95 | - Add HomebrewWrapper.repository_path() helper for Apple M1 silicon (arm64) 96 | - Remove deprecated `--full` option for Homebrew (Breaking upstream CLI change!) 97 | - Add chefspec tests for Apple M1 silicon Homebrew path helper 98 | - Add InSpec tests for macOS M1 / arm64 and x86_64 99 | - Set `use_sudo: false` for InSpec tests to work properly 100 | - Convert hardcoded /usr/local to use install_path() for M1 /opt/homebrew support 101 | - Add Homebrew.install_path() helper for Apple M1 silicon (arm64) 102 | 103 | ## 5.2.2 - *2021-08-30* 104 | 105 | - Standardise files with files in sous-chefs/repo-management 106 | 107 | ## 5.2.1 - *2021-06-01* 108 | 109 | - Standardise files with files in sous-chefs/repo-management 110 | 111 | ## 5.2.0 - *2021-01-24* 112 | 113 | - Sous Chefs Adoption 114 | - Standardise files with files in sous-chefs/repo-management 115 | 116 | ## 5.1.1 (2021-01-04) 117 | 118 | - Update to use --cask instead of cask command for compatibility with newer homebrew releases- [@tas50](https://github.com/tas50) 119 | - resolved cookstyle error: resources/cask.rb:23:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` 120 | - resolved cookstyle error: resources/tap.rb:23:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` 121 | 122 | ## 5.1.0 (2020-05-15) 123 | 124 | - Rename the kitchen config - [@tas50](https://github.com/tas50) 125 | - Cookstyle fixes - [@tas50](https://github.com/tas50) 126 | - OS X -> macOS in the readme - [@tas50](https://github.com/tas50) 127 | - Require Chef 12.15+ - [@tas50](https://github.com/tas50) 128 | - Update default install script from ruby to bash - [@bbros-dev](https://github.com/bbros-dev) 129 | - Resole chefspec failures - [@tas50](https://github.com/tas50) 130 | 131 | ## 5.0.8 (2018-10-04) 132 | 133 | - Updates homebrew cask tap to homebrew/cask 134 | - Updates URLs to the homebrew cask repository 135 | 136 | ## 5.0.7 (2018-09-26) 137 | 138 | - Fix cask resource running each chef-client run 139 | 140 | ## 5.0.6 (2018-09-26) 141 | 142 | - Avoid CHEF-25 Deprecation warnings by making the tap/cask resources no-ops on modern chef-client releases 143 | 144 | ## 5.0.5 (2018-09-04) 145 | 146 | - Update name of macos in kitchen config 147 | - Add deprecation notice for the homebrew_tap and homebrew_cask resources. These resources are now built into Chef 14 and they will be removed from this cookbook when Chef 13 goes EOL, April 2019. 148 | 149 | ## 5.0.4 (2018-03-16) 150 | 151 | - Fix backwards logic in the cask install action 152 | 153 | ## 5.0.3 (2018-03-09) 154 | 155 | - Resolve method missing errors in the library 156 | 157 | ## 5.0.2 (2018-03-09) 158 | 159 | - Remove some legacy logic around the Chef Homebrew user module 160 | - Use lazy to prevent compilation failures on non-macOS platforms 161 | 162 | ## 5.0.1 (2018-03-08) 163 | 164 | - Added a cask_name and tap_name property to the cask/tap resources. These are name_properties which allow you to set the tap/cask name to something other than the resources name. Handy for avoiding resource cloning. 165 | 166 | ## 5.0.0 (2018-03-08) 167 | 168 | - Added a new homebrew_path property to cask/tap for the homebrew binary 169 | - Added a new owner property to cash/tap for setting the homebrew owner 170 | - Converted execute resources in the resources to converge_by and shellout to provide better converge messaging in line with other core Chef resources= 171 | - Renamed the :uninstall action in the cask resource to :remove. This aligns with other chef package resources. The previous action will continue to function. 172 | - Fully documented the resource actions and properties in the readme 173 | - Removed deprecated taps out of the test recipe 174 | - Removed the ChefSpec matchers that are now autogenerated by ChefSpec in modern releases of ChefDK. If this causes failures you need to upgrade ChefDK 175 | 176 | ## 4.3.0 (2018-01-13) 177 | 178 | - Allow Cask name to be scoped to tap 179 | - Disable Foodcrtiic's FC108 since it doesn't apply here 180 | - Automatically install caskroom/cask in the cask resource. This eliminates the need for the cask recipe. 181 | - Resolve Chef 14 deprecation warnings 182 | 183 | ## 4.2.2 (2018-01-13) 184 | 185 | - Fix failures in the cask resource 186 | - Improve inspec output for file mode test 187 | 188 | ## 4.2.1 (2018-01-13) 189 | 190 | - Remove double shellout from a bad merge 191 | - Test on modern macOS releases 192 | - Use full file modes throughout the recipes 193 | - Add 2 retries for downloading the homebrew script in case it fails 194 | 195 | ## 4.2.0 (2017-05-30) 196 | 197 | - Remove class_eval and require Chef 12.7+ 198 | 199 | ## 4.1.0 (2017-04-25) 200 | 201 | - Extend the tap resource to use the --full option. See the readme for details and examples 202 | 203 | ## 4.0.0 (2017-04-19) 204 | 205 | - Convert the tap and cask resources from LWRPs to custom resources which simplifies the code and fixes an incompatibility with Chef 13 206 | - Uses the homebrew_owner as the user to check if a cask has been casked 207 | - Fixed the location of the tap dir to properly prevent trying to install a tap twice 208 | - Refactor the mixin to be a simpler helper that is easier to test 209 | - Resolved failures in the Chefspecs on Travis 210 | - Test with Local Delivery and not Rake 211 | - Use standardize Apache 2 license string 212 | - Only check if homebrew exists once in the default recipe 213 | 214 | ## 3.0.0 (2016-12-19) 215 | 216 | - The homebrew package provider has been removed from this cookbook. It ships with Chef 12.0+. This cookbook now requires a minimum of Chef 12.1 or later. 217 | - This cookbook no longer depends on build-essential as it wasn't using it directly 218 | - Properly define the chefspec matchers 219 | - Add chef_version metadata and remove OS X server which isn't an actual platform from ohai 220 | - Don't grab homebrew_go script if homebrew is already installed. 221 | - Add ability to disable sending analytics data via a new attribute 222 | - Move testing to a test cookbook to make it easier to expand in the future. Also convert integration tests to InSpec from ServerSpec 223 | 224 | ## 2.1.2 (2016-09-07) 225 | 226 | - Allow passing custom options to brew packages 227 | 228 | ## 2.1.1 (2016-09-06) 229 | 230 | - Run chefspecs as OS X 231 | - Update cask recipe to not create /opt/homebrew-cask and /opt/homebrew-cask/Caskroom 232 | - Update tests 233 | 234 | ## v2.1.0 (2016-03-29) 235 | 236 | - Make homebrew install script url configurable 237 | - Make package_info more efficient 238 | 239 | ## v2.0.5 (2016-01-25) 240 | 241 | - Updated execute resources to pass in the HOME/USER environmental variables so homebrew commands are properly executed 242 | - Removed redundant code from recipes and providers 243 | - Removed brew-cask installation and the upgade execute that are no longer necessary 244 | - Added directory creation of /Library/Caches/Homebrew/Casks in case it's not present 245 | - Updated creation of /opt/homebrew-cask to be recursive in case /opt hasn't been created yet 246 | 247 | ## v2.0.4 (2016-01-20) 248 | 249 | - Use the officially supported method of querying homebrew data vs. unsupported internal APIs 250 | - Fixed environmental variables in the homebrew command execution 251 | 252 | ## v2.0.3 (2015-12-09) 253 | 254 | - Fixed poor name matching in determining if a cask had been installed already, which prevented some casks from installing 255 | 256 | ## v2.0.2 (2015-12-04) 257 | 258 | - Prevents casks from installing on every chef run 259 | 260 | ## v2.0.1 (2015-12-03) 261 | 262 | - Fixed already-installed casks breaking builds 263 | 264 | ## v2.0.0 (2015-12-01) 265 | 266 | - Removed all Chef 10 compatibility code 267 | - 77 Update the tap provider to properly notify on changes 268 | - 73 Allow specifying versions (or HEAD) of formulas (see readme for usage) 269 | - Updated contributing, testing, and maintainers docs 270 | - Updated contents of chefignore and .gitignore files 271 | - Updated development dependencies in the Gemfile 272 | - Added Travis CI and supermarket version badges to the readme 273 | - Added Chef standard rubocop file and resolved all warnings 274 | - Added super metadata for Supermarket 275 | - Added testing in Travis CI 276 | - 75 Fix Chefspecs to properly run on Linux hosts (like Travis) 277 | - Add Rakefile for simplified testing 278 | - Resolved all foodcritic warnings 279 | 280 | ## v1.13.0 (2015-06-23) 281 | 282 | - 72 Massage Chef12HomebrewUser.find_homebrew_uid into username 283 | - 69 Add options to cask 284 | 285 | ## v1.12.0 (2015-01-29) 286 | 287 | - 67 Add attribute and recipe for installing homebrew taps 288 | 289 | ## v1.11.0 (2015-01-12) 290 | 291 | - 59 Update Homebrew Cask if auto-update attribute is true 292 | - 52 Manage Homebrew Cask's install directories 293 | - 56 Fix check for existing casks 294 | - 61 Fix owner class for Chef 12 295 | - Depend on build-essential cookbook 2.1.2+ to support OS X 10.10 296 | - 64, #66 add and fix ChefSpec tests for default recipe 297 | 298 | ## v1.10.0 (2014-12-09) 299 | 300 | - 55 This cookbook no longer sets its `homebrew_package` as the 301 | - `package` provider for OS X when running under Chef 12 302 | - List CHEF as the maintainer instead of Chef. 303 | 304 | ## v1.9.2 (2014-10-09) 305 | 306 | Bug Fixes: 307 | 308 | - 57 Update url per homebrew error: Upstream, the homebrew project 309 | - has changed the URL for the installation script. All users of this 310 | - cookbook are advised to update to this version. 311 | 312 | ## v1.9.0 (2014-07-29) 313 | 314 | Improvements: 315 | 316 | - 35 Modernize the cask provider (use why run mode, inline resources) 317 | - 43 Use `brew cask list` to determine if casks are installed 318 | - 45 Add `default_action` and print warning messages on earlier 319 | - versions of Chef (10.10) 320 | 321 | New Features: 322 | 323 | - 44 Add `:install` and `:uninstall` actions and alias previous `:cask`, 324 | - `:uncask` actions to them 325 | 326 | Bug Fixes: 327 | 328 | - 27 Fix name for taps adding the `/homebrew` prefix 329 | - 28 Set `RUBYOPT` to `nil` so Chef can execute in a bundle (bundler 330 | - sets `RUBYOPT` and this can cause issues when running the 331 | - underlying `brew` commands) 332 | - 40 Fix regex for cask to match current homebrew conventions 333 | - 42 Fix attribute for list of formulas to match the README and 334 | - maintain backward compat for 6 day old version 335 | 336 | ## v1.8.0 (2014-07-23) 337 | 338 | - Add recipes to install an array of formulas/casks 339 | 340 | ## v1.7.2 (2014-06-26) 341 | 342 | - Implement attribute to control auto-update 343 | 344 | ## v1.7.0 (2014-06-26) 345 | 346 | - Add homebrew::cask recipe (#38) 347 | 348 | ## v1.6.6 (2014-05-29) 349 | 350 | - [COOK-3283] Use homebrew_owner for cask and tap 351 | - [COOK-4670] homebrew_tap provider is not idempotent 352 | - [COOK-4671] Syntax Error in README 353 | 354 | ## v1.6.4 (2014-05-08) 355 | 356 | - Fixing cask provider correctly this time. "brew cask list" 357 | 358 | ## v1.6.2 (2014-05-08) 359 | 360 | - Fixing typo in cask provider: 's/brew brew/brew/' 361 | 362 | ## v1.6.0 (2014-04-23) 363 | 364 | - [COOK-3960] Added LWRP for brew cask 365 | - [COOK-4508] Add ChefSpec matchers for homebrew_tap 366 | - [COOK-4566] Guard against "HEAD only" formulae 367 | 368 | ## v1.5.4 369 | 370 | - [COOK-4023] Fix installer script's URL. 371 | - Fixing up style for rubocop 372 | 373 | ## v1.5.2 374 | 375 | - [COOK-3825] setting $HOME on homebrew_package 376 | 377 | ## v1.5.0 378 | 379 | ### Bug 380 | 381 | - [COOK-3589] - Add homebrew as the default package manager on OS X Server 382 | 383 | ## v1.4.0 384 | 385 | ### Bug 386 | 387 | - [COOK-3283] - Support running homebrew cookbook as root user, with sudo, or a non-privileged user 388 | 389 | ## v1.3.2 390 | 391 | - [COOK-1793] - use homebrew "go" script to install homebrew 392 | - [COOK-1821] - Discovered version using Homebrew Formula factory fails check that verifies that version is a String 393 | - [COOK-1843] - Homebrew README.md contains non-ASCII characters, triggering same issue as COOK-522 394 | 395 | ## v1.3.0 396 | 397 | - [COOK-1425] - use new json output format for formula 398 | - [COOK-1578] - Use shell_out! instead of popen4 399 | 400 | ## v1.2.0 401 | 402 | Chef Software has taken maintenance of this cookbook as the original author has other commitments. This is the initial release with Chef Software as maintainer. 403 | 404 | Changes in this release: 405 | 406 | - [pull/2] - support for option passing to brew 407 | - [pull/3] - add brew upgrade and control return value from command 408 | - [pull/9] - added LWRP for "brew tap" 409 | - README is now markdown, not rdoc. 410 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Policyfile.rb: -------------------------------------------------------------------------------- 1 | # Policyfile.rb - Describe how you want Chef Infra Client to build your system. 2 | 3 | name 'homebrew' 4 | 5 | # Where to find external cookbooks: 6 | default_source :supermarket 7 | 8 | # run_list: chef-client will run these recipes in the order specified. 9 | run_list 'test::default' 10 | 11 | # Specify a custom source for a single cookbook: 12 | cookbook 'homebrew', path: '.' 13 | cookbook 'test', path: './test/cookbooks/test' 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Homebrew Cookbook 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/homebrew.svg)](https://supermarket.chef.io/cookbooks/homebrew) 4 | [![CI State](https://github.com/sous-chefs/homebrew/workflows/ci/badge.svg)](https://github.com/sous-chefs/homebrew/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 | This cookbook installs [Homebrew](http://brew.sh/) and provides resources for working with taps and casks 10 | 11 | Note: The `homebrew_tap` and `homebrew_cask` resources shipped in Chef 14.0. When Chef 15.0 is released in April 2019 these resources will be removed from this cookbook as all users should be on 14.0 or later. 12 | 13 | ## Maintainers 14 | 15 | 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). 16 | 17 | ## Requirements 18 | 19 | ### Platforms 20 | 21 | - macOS 22 | 23 | ### Chef 24 | 25 | - Chef 12.7+ 26 | 27 | ### Cookbooks 28 | 29 | - none 30 | 31 | ## Resources 32 | 33 | ### homebrew_tap 34 | 35 | Resource for `brew tap`, a Homebrew command used to add additional formula repositories. From the `brew` man page: 36 | 37 | ```text 38 | brew tap [--full] user/repo [URL] 39 | Tap a formula repository. 40 | 41 | With URL unspecified, taps a formula repository from GitHub using HTTPS. 42 | Since so many taps are hosted on GitHub, this command is a shortcut for 43 | tap user/repo https://github.com/user/homebrew-repo. 44 | 45 | With URL specified, taps a formula repository from anywhere, using 46 | any transport protocol that git handles. The one-argument form of tap 47 | simplifies but also limits. This two-argument command makes no 48 | assumptions, so taps can be cloned from places other than GitHub and 49 | using protocols other than HTTPS, e.g., SSH, GIT, HTTP, FTP(S), RSYNC. 50 | 51 | By default, the repository is cloned as a shallow copy (--depth=1), but 52 | if --full is passed, a full clone will be used. To convert a shallow copy 53 | to a full copy, you can retap passing --full without first untapping. 54 | ``` 55 | 56 | Default action is `:tap` which enables the repository. Use `:untap` to disable a tapped repository. 57 | 58 | #### Actions 59 | 60 | - `:tap` (default) - Add a tap 61 | - `:untap` - Remove a tap 62 | 63 | #### Properties 64 | 65 | - `:tap_name` - Optional name property to override the resource name value 66 | - `:url` - Optional URL to the tap 67 | - `:full` - Perform a full clone rather than a shallow clone on the tap (default: false) 68 | - `:homebrew_path` - the path to the homebrew binary (default: '/opt/homebrew/bin/brew') 69 | - `:owner` - the owner of the homebrew installation (default: calculated based on existing files) 70 | 71 | #### Examples 72 | 73 | ```ruby 74 | homebrew_tap 'homebrew/dupes' 75 | 76 | homebrew_tap 'homebrew/dupes' do 77 | action :untap 78 | end 79 | 80 | homebrew_tap "Let's install homebrew/dupes" do 81 | tap_name 'homebrew/dupes' 82 | url 'https://github.com/homebrew/homebrew-dupes.git' 83 | full true 84 | end 85 | ``` 86 | 87 | ### homebrew_cask 88 | 89 | Resource for `brew cask`, a Homebrew-style CLI workflow for the administration of Mac applications distributed as binaries. It's implemented as a homebrew "external command" called cask. 90 | 91 | [homebrew-cask on GitHub](https://github.com/Homebrew/homebrew-cask) 92 | 93 | #### Actions 94 | 95 | - `:install` (default) - install an Application 96 | - `:remove` - remove an Application. 97 | 98 | #### Properties 99 | 100 | - `:cask_name` - Optional name property to override the resource name value 101 | - `:options` - options to pass to the brew CLI during installation 102 | - `:install_cask` - auto install cask tap if necessary (default: true) 103 | - `:homebrew_path` - the path to the homebrew binary (default: '/opt/homebrew/bin/brew') 104 | - `:owner` - the owner of the homebrew installation (default: calculated based on existing files) 105 | 106 | #### Examples 107 | 108 | ```ruby 109 | homebrew_cask 'google-chrome' 110 | 111 | homebrew_cask "Let's remove google-chrome" do 112 | cask_name 'google-chrome' 113 | install_cask false 114 | action :remove 115 | end 116 | ``` 117 | 118 | [View the list of available Casks](https://github.com/Homebrew/homebrew-cask/tree/master/Casks) 119 | 120 | ## Attributes 121 | 122 | - `node['homebrew']['owner']` - The user that will own the Homebrew installation and packages. Setting this will override the default behavior which is to use the non-privileged user that has invoked the Chef run (or the `SUDO_USER` if invoked with sudo). The default is `nil`. 123 | - `node['homebrew']['auto-update']` - Whether the default recipe should automatically update Homebrew each run or not. The default is `true` to maintain compatibility. Set to false or nil to disable. Note that disabling this feature may cause formula to not work. 124 | - `node['homebrew']['formulas']` - An Array of formula that should be installed using Homebrew by default, used only in the `homebrew::install_formulas` recipe. 125 | 126 | - To install the most recent version, include just the recipe name: `- simple_formula` 127 | - To install a specific version, specify both its name and version: 128 | 129 | ```yaml 130 | - name: special-version-formula 131 | version: 1.2.3 132 | ``` 133 | 134 | - To install the HEAD of a formula, specify both its name and `head: true`: 135 | 136 | ```yaml 137 | - name: head-tracking-formula 138 | head: true 139 | ``` 140 | 141 | - To provide other options, specify both its name and options 142 | 143 | ```yaml 144 | - name: formula-with-options 145 | options: --with-option-1 --with-other-option 146 | ``` 147 | 148 | - `node['homebrew']['casks']` - An Array of casks that should be installed using brew cask by default, used only in the `homebrew::install_casks` recipe. 149 | 150 | - `node['homebrew']['taps']` - An Array of taps that should be installed using brew tap by default, used only in the `homebrew::install_taps` recipe. For example: 151 | 152 | ```ruby 153 | [ 154 | 'homebrew/science', 155 | # 'tap' is the only required key for the Hash 156 | { 'tap' => 'homebrew/dupes', 'url' => 'https://github.com', 'full' => true } 157 | ] 158 | ``` 159 | 160 | ## Usage 161 | 162 | We strongly recommend that you put "recipe[homebrew]" in your node's run list, to ensure that it is available on the system and that Homebrew itself gets installed. Putting an explicit dependency in the metadata will cause the cookbook to be downloaded and the library loaded, thus resulting in changing the package provider on macOS, so if you have systems you want to use the default (Mac Ports), they would be changed to Homebrew. 163 | 164 | The default recipe also ensures that Homebrew is installed and up to date if the auto-update attribute (above) is true (default). 165 | 166 | ## Contributors 167 | 168 | This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) 169 | 170 | ### Backers 171 | 172 | Thank you to all our backers! 173 | 174 | ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) 175 | 176 | ### Sponsors 177 | 178 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. 179 | 180 | ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) 181 | ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) 182 | ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) 183 | ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) 184 | ![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) 185 | ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) 186 | ![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) 187 | ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) 188 | ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) 189 | ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) 190 | -------------------------------------------------------------------------------- /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 | # Author:: Joshua Timberman () 3 | # Author:: Graeme Mathieson () 4 | # Cookbook:: homebrew 5 | # Attributes:: default 6 | # 7 | # Copyright:: 2011-2019, 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 | # only used if auto detection fails 22 | default['homebrew']['owner'] = nil # only used if auto detection fails 23 | default['homebrew']['auto-update'] = true 24 | default['homebrew']['casks'] = [] 25 | default['homebrew']['formulas'] = node['homebrew']['formula'] || [] 26 | default['homebrew']['taps'] = [] 27 | default['homebrew']['installer']['url'] = 'https://raw.githubusercontent.com/Homebrew/install/master/install.sh' 28 | default['homebrew']['installer']['checksum'] = nil 29 | default['homebrew']['enable-analytics'] = true 30 | -------------------------------------------------------------------------------- /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/homebrew/251b3c29b2f6e8724d233f7921389b54265698f0/documentation/.gitkeep -------------------------------------------------------------------------------- /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 | provider: vmware_fusion 4 | 5 | provisioner: 6 | name: chef_zero 7 | 8 | verifier: 9 | name: inspec 10 | sudo: false 11 | 12 | platforms: 13 | - name: macos-10.12 14 | driver: 15 | box: chef/macos-10.12 # private box in Chef's Atlas account 16 | 17 | suites: 18 | - name: default 19 | run_list: test::default 20 | -------------------------------------------------------------------------------- /libraries/helpers.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Joshua Timberman () 3 | # Author:: Graeme Mathieson () 4 | # Cookbook:: homebrew 5 | # Library:: helpers 6 | # 7 | # Copyright:: 2011-2019, 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 | class HomebrewUserWrapper 23 | require 'chef/mixin/homebrew' 24 | include Chef::Mixin::Homebrew 25 | include Chef::Mixin::Which 26 | end 27 | 28 | module Homebrew 29 | extend self 30 | 31 | require 'mixlib/shellout' 32 | include Chef::Mixin::ShellOut 33 | 34 | def self.included(base) 35 | base.extend(Homebrew) 36 | end 37 | 38 | def install_path 39 | arm64_test = shell_out('sysctl -n hw.optional.arm64') 40 | if arm64_test.stdout.chomp == '1' 41 | '/opt/homebrew' 42 | else 43 | '/usr/local' 44 | end 45 | end 46 | 47 | def repository_path 48 | arm64_test = shell_out('sysctl -n hw.optional.arm64') 49 | if arm64_test.stdout.chomp == '1' 50 | '/opt/homebrew' 51 | else 52 | '/usr/local/Homebrew' 53 | end 54 | end 55 | 56 | def exist? 57 | Chef::Log.debug('Checking to see if the homebrew binary exists') 58 | ::File.exist?("#{HomebrewWrapper.new.install_path}/bin/brew") 59 | end 60 | 61 | def owner 62 | @owner ||= begin 63 | HomebrewUserWrapper.new.find_homebrew_username 64 | rescue 65 | Chef::Exceptions::CannotDetermineHomebrewPath 66 | end.tap do |owner| 67 | Chef::Log.debug("Homebrew owner is #{owner}") 68 | end 69 | end 70 | end unless defined?(Homebrew) 71 | 72 | class HomebrewWrapper 73 | include Homebrew 74 | end 75 | 76 | Chef::Mixin::Homebrew.include(Homebrew) 77 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'homebrew' 2 | maintainer 'Sous Chefs' 3 | maintainer_email 'help@sous-chefs.org' 4 | license 'Apache-2.0' 5 | description 'Install Homebrew and includes resources for working with taps and casks' 6 | version '6.0.1' 7 | supports 'mac_os_x' 8 | 9 | source_url 'https://github.com/sous-chefs/homebrew' 10 | issues_url 'https://github.com/sous-chefs/homebrew/issues' 11 | chef_version '>= 18.6.2' 12 | -------------------------------------------------------------------------------- /recipes/cask.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: homebrew 3 | # Recipes:: cask 4 | # 5 | # Copyright:: 2014-2019, Chef Software, Inc 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | homebrew_tap 'homebrew/cask' 21 | 22 | directory '/Library/Caches/Homebrew/Casks' do 23 | owner Homebrew.owner 24 | mode '0775' 25 | only_if { ::Dir.exist?('/Library/Caches/Homebrew') } 26 | end 27 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Joshua Timberman () 3 | # Author:: Graeme Mathieson () 4 | # Cookbook:: homebrew 5 | # Recipe:: default 6 | # 7 | # Copyright:: 2011-2019, 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 | unless Homebrew.exist? 23 | homebrew_go = "#{Chef::Config[:file_cache_path]}/homebrew_go" 24 | 25 | # Grant Homebrew install script permission to execute 26 | # without passing a sudo password. Deletes itself at 27 | # the end of a successful run. 28 | sudo 'nopasswd_homebrew_installer' do 29 | user Homebrew.owner 30 | commands [ 31 | homebrew_go, 32 | '/bin/chmod', 33 | '/bin/mkdir', 34 | '/bin/rm', 35 | '/usr/bin/chgrp', 36 | '/usr/bin/install', 37 | '/usr/bin/touch', 38 | '/usr/bin/xcode-select', 39 | '/usr/sbin/chown', 40 | '/usr/sbin/softwareupdate', 41 | ] 42 | nopasswd true 43 | action :create 44 | notifies :delete, 'sudo[nopasswd_homebrew_installer]', :delayed 45 | end 46 | 47 | remote_file homebrew_go do 48 | source node['homebrew']['installer']['url'] 49 | checksum node['homebrew']['installer']['checksum'] unless node['homebrew']['installer']['checksum'].nil? 50 | mode '0755' 51 | retries 2 52 | end 53 | 54 | execute 'install homebrew' do 55 | command homebrew_go 56 | environment lazy { { 'HOME' => ::Dir.home(Homebrew.owner), 'USER' => Homebrew.owner, 'NONINTERACTIVE' => '1' } } 57 | user Homebrew.owner 58 | end 59 | end 60 | 61 | execute 'set analytics' do 62 | environment lazy { { 'HOME' => ::Dir.home(Homebrew.owner), 'USER' => Homebrew.owner } } 63 | user Homebrew.owner 64 | command lazy { "#{HomebrewWrapper.new.install_path}/bin/brew analytics #{node['homebrew']['enable-analytics'] ? 'on' : 'off'}" } 65 | only_if { shell_out("#{HomebrewWrapper.new.install_path}/bin/brew analytics state", user: Homebrew.owner).stdout.include?('enabled') != node['homebrew']['enable-analytics'] } 66 | end 67 | 68 | if node['homebrew']['auto-update'] 69 | package 'git' do 70 | not_if 'which git' 71 | end 72 | 73 | execute 'update homebrew from github' do 74 | environment lazy { { 'HOME' => ::Dir.home(Homebrew.owner), 'USER' => Homebrew.owner } } 75 | user Homebrew.owner 76 | command lazy { "#{HomebrewWrapper.new.install_path}/bin/brew update || true" } 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /recipes/install_casks.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: homebrew 3 | # Recipe:: install_casks 4 | # 5 | # Copyright:: 2014-2019, Chef Software, Inc 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | node['homebrew']['casks'].each do |cask| 21 | homebrew_cask cask 22 | end 23 | -------------------------------------------------------------------------------- /recipes/install_formulas.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: homebrew 3 | # Recipes:: install_casks 4 | # 5 | # Copyright:: 2014-2019, Chef Software, Inc 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'homebrew' 21 | 22 | node['homebrew']['formulas'].each do |formula| 23 | if formula.class == Chef::Node::ImmutableMash 24 | formula_options = formula.fetch(:options, '') 25 | formula_options += ' --HEAD' if formula.fetch(:head, false) 26 | package formula.fetch(:name) do 27 | options formula_options.strip 28 | version formula['version'] if formula.fetch(:version, false) 29 | end 30 | else 31 | package formula 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /recipes/install_taps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: homebrew 3 | # Recipes:: install_taps 4 | # 5 | # Copyright:: 2015-2019, Chef Software, Inc 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | include_recipe 'homebrew' 21 | 22 | node['homebrew']['taps'].each do |tap| 23 | if tap.is_a?(String) 24 | homebrew_tap tap 25 | elsif tap.is_a?(Hash) 26 | raise unless tap.key?('tap') 27 | homebrew_tap tap['tap'] do 28 | url tap['url'] if tap.key?('url') 29 | end 30 | else 31 | raise 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended" 5 | ], 6 | "packageRules": [ 7 | { 8 | "groupName": "Actions", 9 | "matchUpdateTypes": [ 10 | "minor", 11 | "patch", 12 | "pin" 13 | ], 14 | "automerge": true, 15 | "addLabels": [ 16 | "Release: Patch", 17 | "Skip: Announcements" 18 | ] 19 | }, 20 | { 21 | "groupName": "Actions", 22 | "matchUpdateTypes": [ 23 | "major" 24 | ], 25 | "automerge": false, 26 | "addLabels": [ 27 | "Release: Patch", 28 | "Skip: Announcements" 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /resources/cask.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Joshua Timberman () 3 | # Author:: Graeme Mathieson () 4 | # Cookbook:: homebrew 5 | # Resources:: cask 6 | # 7 | # Copyright:: 2011-2019, 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 | unified_mode true 23 | chef_version_for_provides '< 14.0' if respond_to?(:chef_version_for_provides) 24 | 25 | property :cask_name, String, regex: %r{^[\w/-]+$}, name_property: true 26 | property :options, String 27 | property :install_cask, [true, false], default: true 28 | property :homebrew_path, String, default: lazy { "#{HomebrewWrapper.new.install_path}/bin/brew" } 29 | property :owner, String, default: lazy { Homebrew.owner } # lazy to prevent breaking compilation on non-macOS platforms 30 | 31 | action :install do 32 | homebrew_tap 'homebrew/cask' if new_resource.install_cask 33 | 34 | unless casked? 35 | converge_by("install cask #{new_resource.name} #{new_resource.options}") do 36 | shell_out!("#{new_resource.homebrew_path} install --cask #{new_resource.name} #{new_resource.options}", 37 | user: new_resource.owner, 38 | env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, 39 | cwd: ::Dir.home(new_resource.owner)) 40 | end 41 | end 42 | end 43 | 44 | action :remove do 45 | homebrew_tap 'homebrew/cask' if new_resource.install_cask 46 | 47 | if casked? 48 | converge_by("uninstall cask #{new_resource.name}") do 49 | shell_out!("#{new_resource.homebrew_path} uninstall --cask #{new_resource.name}", 50 | user: new_resource.owner, 51 | env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, 52 | cwd: ::Dir.home(new_resource.owner)) 53 | end 54 | end 55 | end 56 | 57 | action_class do 58 | alias_method :action_cask, :action_install 59 | alias_method :action_uncask, :action_remove 60 | alias_method :action_uninstall, :action_remove 61 | 62 | def casked? 63 | unscoped_name = new_resource.name.split('/').last 64 | shell_out!("#{new_resource.homebrew_path} list --cask 2>/dev/null", 65 | user: new_resource.owner, 66 | env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, 67 | cwd: ::Dir.home(new_resource.owner)).stdout.split.include?(unscoped_name) 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /resources/tap.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Joshua Timberman () 3 | # Author:: Graeme Mathieson () 4 | # Cookbook:: homebrew 5 | # Resources:: tap 6 | # 7 | # Copyright:: 2011-2019, 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 | unified_mode true 23 | chef_version_for_provides '< 14.0' if respond_to?(:chef_version_for_provides) 24 | 25 | property :tap_name, String, name_property: true, regex: %r{^[\w-]+(?:\/[\w-]+)+$} 26 | property :url, String 27 | property :full, [true, false], default: false 28 | property :homebrew_path, String, default: lazy { "#{HomebrewWrapper.new.install_path}/bin/brew" } 29 | property :owner, String, default: lazy { Homebrew.owner } # lazy to prevent breaking compilation on non-macOS platforms 30 | 31 | action :tap do 32 | unless tapped?(new_resource.name) 33 | converge_by("tap #{new_resource.name}") do 34 | shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? '--full' : ''} #{new_resource.name} #{new_resource.url || ''}", 35 | user: new_resource.owner, 36 | env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, 37 | cwd: ::Dir.home(new_resource.owner)) 38 | end 39 | end 40 | end 41 | 42 | action :untap do 43 | if tapped?(new_resource.name) 44 | converge_by("untap #{new_resource.name}") do 45 | shell_out!("#{new_resource.homebrew_path} untap #{new_resource.name}", 46 | user: new_resource.owner, 47 | env: { 'HOME' => ::Dir.home(new_resource.owner), 'USER' => new_resource.owner }, 48 | cwd: ::Dir.home(new_resource.owner)) 49 | end 50 | end 51 | end 52 | 53 | def tapped?(name) 54 | tap_dir = name.gsub('/', '/homebrew-') 55 | ::File.directory?("#{HomebrewWrapper.new.repository_path}/Library/Taps/#{tap_dir}") 56 | end 57 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/policyfile' 3 | 4 | require_relative '../libraries/helpers' 5 | 6 | RSpec.configure do |config| 7 | config.color = true # Use color in STDOUT 8 | config.formatter = :documentation # Use the specified formatter 9 | config.log_level = :error # Avoid deprecation notice SPAM 10 | config.platform = 'mac_os_x' 11 | end 12 | -------------------------------------------------------------------------------- /spec/unit/libraries/homebrew_helpers_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | require 'chef/mixin/shell_out' 5 | 6 | RSpec.describe Homebrew do 7 | let(:homebrew) { HomebrewWrapper.new } 8 | 9 | describe '#install_path' do 10 | it 'returns /opt/homebrew for ARM-based systems' do 11 | allow(homebrew).to receive(:shell_out).with('sysctl -n hw.optional.arm64').and_return(double(stdout: "1\n")) 12 | expect(homebrew.install_path).to eq('/opt/homebrew') 13 | end 14 | 15 | it 'returns /usr/local for non-ARM systems' do 16 | allow(homebrew).to receive(:shell_out).with('sysctl -n hw.optional.arm64').and_return(double(stdout: "0\n")) 17 | expect(homebrew.install_path).to eq('/usr/local') 18 | end 19 | end 20 | 21 | describe '#repository_path' do 22 | it 'returns /opt/homebrew for ARM-based systems' do 23 | allow(homebrew).to receive(:shell_out).with('sysctl -n hw.optional.arm64').and_return(double(stdout: "1\n")) 24 | expect(homebrew.repository_path).to eq('/opt/homebrew') 25 | end 26 | 27 | it 'returns /usr/local/Homebrew for non-ARM systems' do 28 | allow(homebrew).to receive(:shell_out).with('sysctl -n hw.optional.arm64').and_return(double(stdout: "0\n")) 29 | expect(homebrew.repository_path).to eq('/usr/local/Homebrew') 30 | end 31 | end 32 | 33 | describe '#owner' do 34 | it 'returns the homebrew owner' do 35 | user_wrapper = double('HomebrewUserWrapper', find_homebrew_username: 'testuser') 36 | allow(HomebrewUserWrapper).to receive(:new).and_return(user_wrapper) 37 | expect(homebrew.owner).to eq('testuser') 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /test/cookbooks/test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'test' 2 | license 'Apache-2.0' 3 | description 'Tests homebrew' 4 | version '0.1.0' 5 | 6 | depends 'homebrew' 7 | depends 'ssh_known_hosts' 8 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: test 3 | # Recipe:: default 4 | # 5 | # Copyright:: 2016-2019, Chef Software, Inc. 6 | 7 | node.default['homebrew']['formulas'] = %w(redis jq) 8 | node.default['homebrew']['casks'] = %w(caffeine) 9 | node.default['homebrew']['taps'] = [ 10 | { 11 | 'tap' => 'homebrew/bundle', 12 | 'full' => true, 13 | }, 14 | { 15 | 'tap' => 'homebrew/services', 16 | 'url' => 'https://github.com/homebrew/homebrew-services.git', 17 | 'full' => true, 18 | }, 19 | ] 20 | node.default['homebrew']['enable-analytics'] = false 21 | 22 | ssh_known_hosts_entry 'github.com' do 23 | group 'wheel' 24 | end 25 | 26 | build_essential 'Install compilation tools' 27 | include_recipe 'homebrew::install_formulas' 28 | include_recipe 'homebrew::install_casks' 29 | include_recipe 'homebrew::install_taps' 30 | -------------------------------------------------------------------------------- /test/integration/default/default_spec.rb: -------------------------------------------------------------------------------- 1 | # Check both x86_64 and arm64 locations for brew 2 | # Depending on shell setup in the box: 3 | # InSpec commands want a full path, but this depends on arch + platform_version 4 | # macOS default shell may be /bin/bash or /bin/zsh ... back to basics: /bin/sh 5 | describe command('/bin/sh -c "PATH=/opt/homebrew/bin:/usr/local/bin:$PATH brew --version"') do 6 | its('stdout') { should match('^Homebrew.*$') } 7 | end 8 | 9 | brew_prefix = command('/bin/sh -c "PATH=/opt/homebrew/bin:/usr/local/bin:$PATH brew --prefix"').stdout.chomp 10 | describe brew_prefix do 11 | it { should match('^(\/usr\/local|\/opt\/homebrew)$') } 12 | end 13 | 14 | describe file(brew_prefix) do 15 | it { should be_directory } 16 | end 17 | 18 | brew_caskroom = command('/bin/sh -c "PATH=/opt/homebrew/bin:/usr/local/bin:$PATH brew --caskroom"').stdout.chomp 19 | describe brew_caskroom do 20 | it { should match('^(\/usr\/local|\/opt\/homebrew)/Caskroom$') } 21 | end 22 | 23 | describe file(brew_caskroom) do 24 | it { should be_directory } 25 | end 26 | 27 | describe package('redis') do 28 | it { should be_installed } 29 | end 30 | 31 | describe package('jq') do 32 | it { should be_installed } 33 | end 34 | 35 | # CI agnostic caskroom owner check 36 | # InSpec may be running commands w/sudo 37 | ci_user = command('whoami').stdout.chomp 38 | if ci_user == 'root' 39 | ci_user = command("/bin/sh -c 'echo $SUDO_USER'").stdout.chomp 40 | end 41 | describe file("#{brew_caskroom}/caffeine") do 42 | it { should be_directory } 43 | its('mode') { should cmp '0755' } 44 | it { should be_owned_by ci_user } 45 | end 46 | --------------------------------------------------------------------------------