├── .chef └── config.rb ├── .gitignore ├── LICENSE ├── Policyfile.rb ├── README.md ├── bin ├── pantry └── pantry.ps1 └── dna.json /.chef/config.rb: -------------------------------------------------------------------------------- 1 | current_dir = File.dirname(__FILE__) 2 | # https://github.com/chef/chef/issues/2449 3 | chef_repo_path File.join(current_dir, '..', 'zero-repo') 4 | 5 | # We'll use policyfiles with local mode. 6 | use_policyfile true 7 | policy_group 'local' 8 | policy_name 'pantry' 9 | versioned_cookbooks true 10 | policy_document_native_api true 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .autotest 2 | coverage 3 | .DS_Store 4 | pkg 5 | */tags 6 | *~ 7 | 8 | # you should check in your Gemfile.lock in applications, and not in gems 9 | Gemfile.lock 10 | Gemfile.local 11 | 12 | # Do not check in the .bundle directory, or any of the files inside it. Those files are specific to each particular machine, and are used to persist installation options between runs of the bundle install command. 13 | .bundle 14 | 15 | # ignore some common Bundler 'binstubs' directory names 16 | # http://gembundler.com/man/bundle-exec.1.html 17 | b/ 18 | binstubs/ 19 | 20 | # RVM and RBENV ruby version files 21 | .rbenv-version 22 | .rvmrc 23 | .ruby-version 24 | .ruby-gemset 25 | 26 | # IDE files 27 | .project 28 | 29 | # Test Kitchen and Berkshelf 30 | .kitchen/ 31 | Berksfile.lock 32 | berks-cookbooks 33 | .chef/local-mode-cache/ 34 | dna.json 35 | 36 | # Vagrant 37 | Vagrantfile 38 | .vagrant/ 39 | 40 | # Policyfile 41 | Policyfile.lock.json 42 | zero-repo 43 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Policyfile.rb: -------------------------------------------------------------------------------- 1 | # Policyfile.rb - Describe how you want Chef to configure your workstation. 2 | # 3 | # For more information on the Policyfile feature, visit 4 | # https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md 5 | 6 | name 'pantry' 7 | # Get cookbooks from supermarket.chef.io 8 | default_source :community 9 | 10 | ########## 11 | # Run List 12 | # chef-client will run these recipes in the order specified. 13 | # Modify this to include other cookbooks you wish to use, separating 14 | # each recipe name with commas. For example: 15 | # 16 | # run_list( 17 | # 'pantry', 18 | # 'mycookbook' 19 | # ) 20 | # 21 | # Add `cookbook` entries for cookbooks that are not found on 22 | # supermarket. See the POLICYFILE_README.md for more information. 23 | 24 | run_list( 25 | 'pantry' 26 | ) 27 | 28 | ############ 29 | # Attributes 30 | # Feel free to modify these values, or add your own attributes for 31 | # other cookbooks. 32 | # Specify values as a space separated list of words. For example, 33 | # %w(git go packer tree) 34 | # 35 | # packages for OS X 36 | default['homebrew']['casks'] = %w() 37 | default['homebrew']['formula'] = %w() 38 | default['homebrew']['taps'] = %w() 39 | # packages for Windows 40 | default['chocolatey']['packages'] = %w() 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chef Pantry 2 | 3 | Welcome to the Pantry! 4 | 5 | Pantry is a workstation automation cookbook and Chef repository. The cookbook itself is shared on the [Supermarket community site](https://supermarket.chef.io/cookbooks/pantry), and has its own [git repository](https://github.com/opscode-cookbooks/pantry). 6 | 7 | ## TL;DR: 8 | 9 | ``` 10 | git clone https://github.com/chef/pantry-chef-repo 11 | cd pantry-chef-repo 12 | sudo ./bin/pantry -c 13 | ``` 14 | 15 | ## Getting Started 16 | 17 | Get this repository on your system. You can clone it if you have `git` installed, or you can download the `zip archive`. 18 | 19 | Once you have the `pantry-chef-repo` on your system, open a [terminal](http://iterm2.com/), and run the pantry script with `sudo`. 20 | 21 | To just perform the installation: 22 | 23 | ``` 24 | sudo ./bin/pantry 25 | ``` 26 | 27 | To perform the installation and run Chef with the default Policyfile.rb, use the `-c` option. 28 | 29 | ``` 30 | sudo ./bin/pantry -c 31 | ``` 32 | 33 | ### Installing Packages 34 | 35 | Packages are installed by populating attribute arrays with a list of names to install. For OS X, these are handled by the `homebrew` cookbook's formulas and casks attributes. For Windows, these are handled by Chocolatey. 36 | 37 | Update the Policyfile.rb attributes to modify the package lists you want to install. 38 | 39 | ```ruby 40 | default['homebrew']['formulas'] = %w(coreutils go postgresql) 41 | default['homebrew']['casks'] = %w(google-chrome skype vagrant) 42 | ``` 43 | 44 | `./bin/pantry` will use the Policyfile.rb to add these attributes to the node. Then update the Policyfile.lock.json and export the repository. 45 | 46 | ``` 47 | chef update 48 | chef export --force zero-repo 49 | sudo chef-client -z 50 | ``` 51 | 52 | ### Using a Chef Server 53 | 54 | **This is optional**. 55 | 56 | Pantry can be used with a Chef Server. Since this isn't the default, it does require a little more work on your part. For this example, I'll use Hosted Chef as my server. 57 | 58 | **Note** Don't use `-c` with the `bin/pantry` script. It assumes running `chef-client` with local mode. 59 | 60 | Before running `chef-client`, do the following: 61 | 62 | Create `/etc/chef/client.rb` with at least the following content, and copy your organization's validation client key (`ORGNAME-validator.pem`) to `/etc/chef/validation.pem`. 63 | 64 | ```ruby 65 | chef_server_url 'https://api.opscode.com/organizations/ORGNAME' 66 | validation_client_name 'ORGNAME-validator' 67 | ``` 68 | 69 | Create `.chef/knife.rb` or `~/.chef/knife.rb` with the following content. Replace ORGNAME and HOSTED_USERNAME with your values. 70 | 71 | ```ruby 72 | chef_server_url 'https://api.opscode.com/organizations/ORGNAME' 73 | node_name 'HOSTED_USERNAME' 74 | client_key 'path/to/your/HOSTED_USERNAME.pem' 75 | use_policyfile true 76 | deployment_group 'pantry-chef-server' 77 | versioned_cookbooks true 78 | ``` 79 | 80 | Obtain the validation client key from your Chef Server. For example, I downloaded mine from the Hosted Chef starter kit. Copy it to `/etc/chef`. 81 | 82 | Upload the cookbooks from this repository. 83 | 84 | ``` 85 | chef install 86 | chef push 87 | ``` 88 | 89 | Run Chef! 90 | 91 | ``` 92 | sudo chef-client 93 | ``` 94 | 95 | ## bin/pantry 96 | 97 | The `pantry` script takes 0 or 1 argument. It does the following: 98 | 99 | 1. Install ChefDK using CHEF's installation script that downloads the package with the [Omnitruck API](https://docs.chef.io/api_omnitruck.html). 100 | 1. "Vendors" the required cookbooks into `zero-repo` using Chef Policyfiles. 101 | 1. Optionally runs `chef-client` (using "local mode") with the `base` role in this repository if the `-c` argument is used. 102 | 103 | For more information about Policyfiles, see its [README](https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md). 104 | 105 | ## Scope 106 | 107 | Workstations are personalized work environments. Pantry is opinionated where it needs to be and tries to stay out of the way of the user. It is not in the scope to support every possible use case on all workstation operating systems. The primary purpose is to get the base OS environment setup to be able to install packages and software commonly desired for workstation systems, and provide a framework to build upon with other cookbooks. 108 | 109 | ## Requirements 110 | 111 | **ChefDK**: As this is intended to run on a workstation that is presumably also used for Chef development, the default and supported method of installing Chef is using [the ChefDK](https://downloads.chef.io/chef-dk/). This is performed by the `bin/pantry` script. 112 | 113 | **Administrative/privileged access**: Some of the things required to setup a workstation involve root/administrative privileges. As such, `chef-client` should be invoked using `sudo`, or otherwise in an administrative shell. Note that this can have interesting interactions with software such as Homebrew, and we've tried to accommodate that. If you encounter any problems, please open an [issue](https://github.com/opscode/pantry-chef-repo/issues). 114 | 115 | ### Platform: 116 | 117 | * OS X 10.9, 10.10 118 | * Windows 8.1 119 | 120 | It may work on other versions of these platforms with or without modification. 121 | 122 | **Future (planned)**: Linux (Debian and RHEL families). See [Bugs](#bugs), below. 123 | 124 | ## Bugs 125 | 126 | [Report issues in this repository](https://github.com/opscode/pantry-chef-repo/issues). We may close your issue and open it elsewhere if appropriate. For example, supporting other platforms is deferred to the [pantry cookbook](https://github.com/opscode-cookbooks/pantry) 127 | 128 | * [Linux support is not yet implemented](https://github.com/opscode-cookbooks/pantry/issues/2). 129 | 130 | Homebrew cask prior to version 0.50.0 has [an issue](https://github.com/caskroom/homebrew-cask/issues/7946) fixed in 0.50.0+ that requires upgrading `brew-cask`. TL;DR: 131 | 132 | ``` 133 | brew update && brew upgrade brew-cask && brew cleanup 134 | ``` 135 | 136 | ## License and Author 137 | 138 | - Author: Joshua Timberman 139 | - Copyright (C) 2014-2015, Chef Software, Inc. 140 | 141 | ```text 142 | Licensed under the Apache License, Version 2.0 (the "License"); 143 | you may not use this file except in compliance with the License. 144 | You may obtain a copy of the License at 145 | 146 | http://www.apache.org/licenses/LICENSE-2.0 147 | 148 | Unless required by applicable law or agreed to in writing, software 149 | distributed under the License is distributed on an "AS IS" BASIS, 150 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 151 | See the License for the specific language governing permissions and 152 | limitations under the License. 153 | ``` 154 | -------------------------------------------------------------------------------- /bin/pantry: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Author:: Joshua Timberman 4 | # Copyright (c) 2014, Chef Software, Inc. 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 | # This is written in Bash instead of Ruby because we don't know what 19 | # kind of local Ruby environment an end-user will have. Presumably, 20 | # none, or not a "sane" one. We won't have a "sane" Ruby until ChefDK is 21 | # installed, which is handled by this script. 22 | # 23 | # This script exits 100 if it isn't executed as root or with sudo. 24 | # This script exits 110 if `install.sh` fails to install ChefDK. 25 | # This script exits 120 if `berks vendor` fails for any reason. 26 | # 27 | # Any failing command run by this script may cause it to exit (or not) 28 | # and return its own exit code (or 0). 29 | if [ $USER != 'root' ]; then 30 | echo 'You must execute this script as root.' 31 | echo "sudo ${0}" 32 | exit 100 33 | fi 34 | 35 | while getopts cup opt 36 | do 37 | case "$opt" in 38 | c) run_chef=true;; 39 | u) upgrade=true;; 40 | p) prerelease=true;; 41 | esac 42 | done 43 | shift `expr $OPTIND - 1` 44 | 45 | if [ "x$prerelease" = "xtrue" ] 46 | then 47 | preopt='-p' 48 | else 49 | preopt=' ' 50 | fi 51 | 52 | if [ "x$upgrade" = "xtrue" ] 53 | then 54 | if [ `which pkgutil` ] 55 | then 56 | echo 'Removing existing ChefDK installation' 57 | # this is the part of the show where we wish pkgutil had an 58 | # uninstall option. Also, we assume reinstall down yonder, so 59 | # we don't bother with the links in `/usr/bin`. 60 | pkgutil --forget com.getchef.pkg.chefdk && rm -rf /opt/chefdk 61 | fi 62 | echo 'Removing Policyfile.lock.json so cookbooks are upgraded too' 63 | rm -f Policyfile.lock.json 64 | fi 65 | 66 | if [ ! -f /opt/chefdk/version-manifest.txt ]; then 67 | echo '' 68 | echo 'Downloading ChefDK.' 69 | curl -L https://www.chef.io/chef/install.sh | bash -s -- $preopt -P chefdk 70 | 71 | if [ $? -ne 0 ]; then 72 | echo 'Failed to install ChefDK. Exiting!' 73 | exit 110 74 | fi 75 | fi 76 | 77 | # We check that the Policyfile.rb exists first because someone might 78 | # download this script and run it without having the full repository. 79 | if [ -f Policyfile.rb ] && [ ! -f Policyfile.lock.json ] 80 | then 81 | echo 'Installing Policy to ChefDK cookbook cache and exporting repository to zero-repo.' 82 | chef install && chmod 0644 Policyfile.lock.json 83 | chef export zero-repo --force 84 | 85 | [ ! -z $SUDO_USER ] && chown -R $SUDO_USER Policyfile.lock.json zero-repo 86 | 87 | if [ $? -ne 0 ] 88 | then 89 | echo '' 90 | echo 'Chef Policyfile failed to install and export cookbooks!' 91 | exit 120 92 | fi 93 | echo '' 94 | fi 95 | 96 | if [ "x$run_chef" = "xtrue" ] 97 | then 98 | echo 'Running `chef-client` with the default Policyfile.rb.' 99 | /opt/chefdk/embedded/bin/chef-client -z 100 | echo 'In the future, you can modify the Policyfile.rb, then run' 101 | echo '`chef update` and `chef export zero-repo`, then rerun chef client with' 102 | echo '`sudo /opt/chefdk/embedded/bin/chef-client -z` from this directory.' 103 | else 104 | echo 'To have this script automatically run Chef with the default Policyfile.rb, run:' 105 | echo "$0 -c" 106 | exit 0 107 | fi 108 | 109 | exit 0 110 | -------------------------------------------------------------------------------- /bin/pantry.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, Chef Software, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # TODO: Support option for installing ChefDK prerelease, and upgrading. 16 | param ( 17 | [switch]$RunChef 18 | ) 19 | 20 | Import-Module BitsTransfer 21 | 22 | function Get-ChefDK { 23 | Try { 24 | Write-Host "Downloading ChefDK" 25 | Start-BitsTransfer "https://www.chef.io/chef/download-chefdk?p=windows&pv=2008r2&m=x86_64&v=latest" "chefdk.msi" 26 | } Catch { 27 | Write-Error $_.Exception 28 | Exit 110 29 | } 30 | } 31 | 32 | function Install-ChefDK { 33 | $ProcMsi = Start-Process -FilePath 'msiexec.exe' -ArgumentList "/qn /i chefdk.msi" -Passthru 34 | $i = 0 35 | while (-Not $ProcMsi.HasExited) { 36 | $StatusMsg = "Please Wait" + "." * ($i + 1) 37 | Write-Progress -Activity "Installing ChefDK" -Status $StatusMsg 38 | $i = ($i+1) % 3 39 | Start-Sleep 1 40 | } 41 | Write-Progress -Activity "Installing ChefDK" -Completed 42 | 43 | if ($ProcMsi.ExitCode -ne 0) { 44 | Write-Error "Failed to install ChefDK" 45 | exit 110 46 | } 47 | 48 | $env:PATH = $env:PATH + ";" + "C:\opscode\chefdk\bin" 49 | } 50 | 51 | function Test-ChefDK { 52 | Test-Path "C:\opscode\chefdk\version-manifest.txt" 53 | } 54 | 55 | function Get-Cookbooks { 56 | $PolicyfileExists = Test-Path "Policyfile.rb" 57 | $LockExists = Test-Path "Policyfile.lock.json" 58 | if ($PolicyfileExists -And -Not $LockExists) { 59 | Write-Host "Installing Policy to ChefDK cookbook cache and exporting repository to zero-repo." 60 | chef install 61 | chef export zero-repo --force 62 | if ($LASTEXITCODE -ne 0) { 63 | Write-Error "Chef Policyfile failed to install and export cookbooks!" 64 | Exit 120 65 | } 66 | } 67 | } 68 | 69 | function Invoke-ChefClient 70 | { 71 | Write-Host "Running chef-client with the pantry default recipe." 72 | chef-client -z 73 | if ($LASTEXITCODE -ne 0) { 74 | Write-Error "chef-client run failed" 75 | Exit 130 76 | } 77 | } 78 | 79 | if ((Test-ChefDK) -eq $False) { 80 | Get-ChefDK 81 | Install-ChefDK 82 | rm "chefdk.msi" 83 | } 84 | 85 | Get-Cookbooks 86 | 87 | if ($RunChef) { 88 | Invoke-ChefClient 89 | Write-Host "In the future, you can modify the Policyfile.rb, then run" 90 | Write-Host "`chef update` and `chef export zero-repo`, then rerun chef client with" 91 | Write-Host "`chef-client -z` from this directory." 92 | }else { 93 | Write-Host 'To have this script automatically run Chef with the "pantry::default" recipe, run with -RunChef' 94 | } 95 | -------------------------------------------------------------------------------- /dna.json: -------------------------------------------------------------------------------- 1 | { 2 | "homebrew": { 3 | "formulas": [], 4 | "casks": [] 5 | }, 6 | "chocolatey": { 7 | "packages": [] 8 | }, 9 | "packages": [] 10 | } 11 | --------------------------------------------------------------------------------