workup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a21e976ad08e80ca3a977f51abe15daf1922e3f2
4
+ data.tar.gz: 3dce7a5ee6854154584e45cd8732d41a11b73ac8
5
+ SHA512:
6
+ metadata.gz: 5fc72d12ea0ead4eeaf430b22f7061fb28370e5b451316203f43f22ee91b64315e4837f76fff07e1488b9ca283199a50797593d38a21e2d677a20deda1ff4b8d
7
+ data.tar.gz: 5076845c08335ba145ac9a38be3de21e5ea4ca086ea18a163be6952da6ff229c7f04ad25acadd8c7d316460d37f86aa2213788640aa86c6d10b9f147ffce8648
@@ -0,0 +1,12 @@
1
+ branches:
2
+ only:
3
+ - master
4
+
5
+ init:
6
+ - ps: $PSVersionTable
7
+
8
+ build_script:
9
+ - ps: ./bootstrap.ps1
10
+
11
+ test_script:
12
+ - ps: chef exec inspec exec test/integration/**/*.rb --format documentation
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - '.rubocop_todo.yml'
@@ -0,0 +1,43 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-09-01 17:25:53 -0400 using RuboCop version 0.42.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/ParenthesesAsGroupedExpression:
11
+ Exclude:
12
+ - 'client.rb'
13
+
14
+ # Offense count: 2
15
+ Metrics/AbcSize:
16
+ Max: 27
17
+
18
+ # Offense count: 9
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
20
+ # URISchemes: http, https
21
+ Metrics/LineLength:
22
+ Max: 104
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: CountComments.
26
+ Metrics/MethodLength:
27
+ Max: 12
28
+
29
+ # Offense count: 4
30
+ Style/Documentation:
31
+ Exclude:
32
+ - 'spec/**/*'
33
+ - 'test/**/*'
34
+ - 'lib/workup.rb'
35
+ - 'lib/workup/application.rb'
36
+ - 'lib/workup/helpers.rb'
37
+ - 'lib/workup/logging.rb'
38
+
39
+ # Offense count: 1
40
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
41
+ Style/FileName:
42
+ Exclude:
43
+ - 'Policyfile.rb'
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in workup.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
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.
@@ -0,0 +1,10 @@
1
+ name 'workup'
2
+
3
+ default_source :community
4
+
5
+ cookbook 'no_op', github: 'livinginthepast/windows-noop-cookbook'
6
+
7
+ run_list(
8
+ # This stops the Policyfile from complaining
9
+ 'no_op'
10
+ )
@@ -0,0 +1,82 @@
1
+ # Workup
2
+
3
+ [![Build status](https://ci.appveyor.com/api/projects/status/hu0nygm28cbs040s/branch/master?svg=true)](https://ci.appveyor.com/project/jonathanmorley/workup-pn3lv/branch/master)
4
+ [![Build Status](https://travis-ci.org/cvent/workup.svg?branch=master)](https://travis-ci.org/cvent/workup)
5
+
6
+ Workup is a workstation provisioning tool that focuses on cross-compatibility
7
+ and minimal assumptions about the initial state of the machine.
8
+
9
+ All data is stored in `~/.workup`
10
+
11
+ ## What does it do?
12
+
13
+ Workup uses Chef Policyfiles to run cookbooks
14
+
15
+ ## Installation
16
+
17
+ ### As a gem
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'workup'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install workup
32
+
33
+ ### As a command
34
+
35
+ #### UNIX, Linux and MacOS
36
+ On UNIX, Linux and MacOS systems the install script is invoked with:
37
+
38
+ curl -L 'https://raw.githubusercontent.com/cvent/workup/master/bootstrap.sh' | sudo bash
39
+
40
+ #### Microsoft Windows
41
+ On Microsoft Windows systems the install script is invoked using Windows
42
+ PowerShell as an Administrator (The first command should not produce
43
+ any output):
44
+
45
+ Set-ExecutionPolicy -Force RemoteSigned # Enable remote scripts
46
+ (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/cvent/workup/master/bootstrap.ps1') | iex
47
+
48
+ ## Usage
49
+
50
+ ### Upgrading workup
51
+
52
+ Re-run the installation script above
53
+
54
+ ### Uninstall workup
55
+
56
+ * Remove `~/.workup`
57
+ * `sudo rm /usr/local/bin/workup` (Non-windows operating systems only)
58
+
59
+ ### Converging your workstation
60
+ On Microsoft Windows systems, you may find that your machine restarts during the execution of this command. Please re-issue this command to continue the setup.
61
+
62
+ workup
63
+
64
+ ### Customizing workup
65
+
66
+ You can modify the `~/.workup/Policyfile.rb` to use different chef cookbooks.
67
+ Note, these changes will currently be overwritten if you run the bootstrap script.
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cvent/workup.
78
+
79
+ # Thanks
80
+
81
+ This is based on the [pantry](https://github.com/chef/pantry-chef-repo) project
82
+ by Chef.
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ namespace :test do
6
+ RuboCop::RakeTask.new(:lint)
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ end
9
+
10
+ task test: ['test:lint', 'test:spec']
11
+
12
+ task default: :test
@@ -0,0 +1,106 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ If (!([Security.Principal.WindowsPrincipal] `
4
+ [Security.Principal.WindowsIdentity]::GetCurrent()
5
+ ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
6
+ Write-Error "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
7
+ }
8
+
9
+ Function Reset-Path {
10
+ $MachinePaths = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) -split ';'
11
+ $UserPaths = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User) -split ';'
12
+ $Env:Path = ($MachinePaths + $UserPaths) -join ';'
13
+ }
14
+
15
+ Function Add-ToPath {
16
+ Param([string]$Path)
17
+ $Path = $Path.TrimEnd('/')
18
+
19
+ Reset-Path
20
+ $Paths = $Env:Path -split ';'
21
+ If (!($Paths -contains $Path) -and !($Paths -contains "${Path}/")) {
22
+ $MachinePaths = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) -split ';'
23
+ $MachinePaths += $Path
24
+ [Environment]::SetEnvironmentVariable('Path', ($MachinePaths -join ';'), [System.EnvironmentVariableTarget]::Machine)
25
+ Reset-Path
26
+ }
27
+ }
28
+
29
+ Write-Host 'Bootstrapping workup'
30
+
31
+ $WORKUP_BRANCH = 'master' # Useful for testing
32
+ $WORKUP_URL = "https://raw.githubusercontent.com/cvent/workup/${WORKUP_BRANCH}"
33
+
34
+ $WORKUP_DIR = Join-Path ${HOME} '.workup'
35
+ $WORKUP_BINS = Join-Path ${WORKUP_DIR} 'bin'
36
+
37
+ $CHEFDK_URL = 'https://omnitruck.chef.io/install.ps1'
38
+ $CHEFDK_VERSION = '0.17.17'
39
+
40
+ $wc = New-Object System.Net.WebClient
41
+
42
+ Write-Host -NoNewLine "Checking for ChefDK >= v${CHEFDK_VERSION}... "
43
+ If (Get-Command chef -ErrorAction SilentlyContinue) {
44
+ $current_chef_version = (chef --version | select -first 1) -replace 'Chef Development Kit Version: ',''
45
+
46
+ $install_chef = (([System.Version] ${current_chef_version}) -lt ([System.Version] ${CHEFDK_VERSION}))
47
+
48
+ Write-Host -NoNewLine "v${current_chef_version} found "
49
+
50
+ If ($install_chef) {
51
+ Write-Host -ForegroundColor 'Yellow' 'Too old'
52
+ } Else {
53
+ Write-Host -ForegroundColor 'Green' 'OK'
54
+ }
55
+ } Else {
56
+ Write-Host -ForegroundColor 'Yellow' 'Not found'
57
+ $install_chef = $true
58
+ }
59
+
60
+ If (${install_chef}) {
61
+ Get-WmiObject `
62
+ -Class Win32_Product `
63
+ -Filter "Name LIKE 'Chef Development Kit%'" |% {
64
+ Write-Host -NoNewLine "Uninstalling ChefDK v$($_.Version)... "
65
+ $_.Uninstall() | Out-Null
66
+ Write-Host -ForegroundColor 'Green' 'OK'
67
+ }
68
+
69
+ Write-Host -NoNewLine "Installing ChefDK v${CHEFDK_VERSION}... "
70
+ . { $wc.DownloadString(${CHEFDK_URL}) } | iex | Out-Null
71
+ install -project 'chefdk' -version ${CHEFDK_VERSION} | Out-Null
72
+ Write-Host -ForegroundColor 'Green' 'OK'
73
+ }
74
+
75
+ Add-ToPath 'C:\opscode\chefdk\bin'
76
+
77
+ @(${WORKUP_DIR}, ${WORKUP_BINS}) |% {
78
+ $leaf_name = Split-Path ${_} -Leaf
79
+ If (Test-Path ${_} -PathType 'Container') {
80
+ Write-Host "${leaf_name} directory already exists"
81
+ } ElseIf (Test-Path ${_} -PathType 'Leaf') {
82
+ Throw "${_} is unexpectedly a file. Please resolve this and try again"
83
+ } Else {
84
+ Write-Host -NoNewLine "Creating ${leaf_name} directory... "
85
+ New-Item -Type Directory ${_} | Out-Null
86
+ Write-Host -ForegroundColor 'Green' 'OK'
87
+ }
88
+ }
89
+
90
+ @('Policyfile.rb', 'client.rb') |% {
91
+ Write-Host -NoNewLine "Fetching new ${_}... "
92
+ $wc.DownloadFile("${WORKUP_URL}/${_}", (Join-Path ${WORKUP_DIR} ${_}))
93
+ Write-Host -ForegroundColor 'Green' 'OK'
94
+ }
95
+
96
+ Write-Host -NoNewLine 'Fetching new workup script... '
97
+ $workup_bin = Join-Path ${WORKUP_BINS} 'workup'
98
+ $wc.DownloadFile("${WORKUP_URL}/workup.rb", "${workup_bin}.rb")
99
+ $wc.DownloadFile("${WORKUP_URL}/workup.ps1", "${workup_bin}.ps1")
100
+ If(!(Test-Path ${workup_bin})) { cmd /c mklink ${workup_bin} "${workup_bin}.ps1" | Out-Null }
101
+
102
+ Write-Host -ForegroundColor 'Green' 'OK'
103
+
104
+ Add-ToPath $WORKUP_BINS
105
+
106
+ Write-Host 'You are ready to run workup'
@@ -0,0 +1,116 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ # Make sure only root can run our script
6
+ if [[ $EUID -ne 0 ]]; then
7
+ echo "This script must be run as root" 1>&2
8
+ exit 1
9
+ fi
10
+
11
+ echo 'Bootstrapping workup'
12
+
13
+ WORKUP_BRANCH='master' # Useful for testing
14
+ WORKUP_URL="https://raw.githubusercontent.com/cvent/workup/${WORKUP_BRANCH}"
15
+
16
+ WORKUP_DIR="${HOME}/.workup"
17
+ WORKUP_BINS="${WORKUP_DIR}/bin"
18
+
19
+ CHEFDK_URL='https://omnitruck.chef.io/install.sh'
20
+ CHEFDK_VERSION='0.17.17'
21
+
22
+ printf "Checking for ChefDK >= v${CHEFDK_VERSION}... "
23
+ if command -v '/usr/local/bin/chef' > /dev/null; then
24
+ # From https://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format
25
+ vercomp () {
26
+ if [[ $1 == $2 ]]
27
+ then
28
+ return 0
29
+ fi
30
+ local IFS=.
31
+ local i ver1=($1) ver2=($2)
32
+ # fill empty fields in ver1 with zeros
33
+ for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
34
+ do
35
+ ver1[i]=0
36
+ done
37
+ for ((i=0; i<${#ver1[@]}; i++))
38
+ do
39
+ if [[ -z ${ver2[i]} ]]
40
+ then
41
+ # fill empty fields in ver2 with zeros
42
+ ver2[i]=0
43
+ fi
44
+ if ((10#${ver1[i]} > 10#${ver2[i]}))
45
+ then
46
+ return 1
47
+ fi
48
+ if ((10#${ver1[i]} < 10#${ver2[i]}))
49
+ then
50
+ return 2
51
+ fi
52
+ done
53
+ return 0
54
+ }
55
+
56
+ chefdk_version_regex="^Chef Development Kit Version: (.+)$"
57
+ if [[ "$(/usr/local/bin/chef env -v)" =~ $chefdk_version_regex ]]; then
58
+ vercomp "${BASH_REMATCH[1]}" "${CHEFDK_VERSION}"
59
+ if [[ "${?}" == '-1' ]]; then install_chef='true'; else install_chef='false'; fi
60
+
61
+ printf "v${BASH_REMATCH[1]} found "
62
+ else
63
+ install_chef=true
64
+ fi
65
+
66
+ if ${install_chef}; then
67
+ printf "\033[1;33mToo old\033[0m\n"
68
+ else
69
+ printf "\033[1;32mOK\033[0m\n"
70
+ fi
71
+ else
72
+ printf "\033[1;33mNot found\033[0m\n"
73
+ install_chef='true'
74
+ fi
75
+
76
+ if ${install_chef}; then
77
+ printf "Installing ChefDK v${CHEFDK_VERSION}... "
78
+ curl -Ls "${CHEFDK_URL}" | sudo bash -s -- -P 'chefdk' -v "${CHEFDK_VERSION}" > /dev/null
79
+ printf "\033[1;32mOK\033[0m\n"
80
+ fi
81
+
82
+ printf 'Creating workup directory... '
83
+ [ -d "${WORKUP_DIR}" ] || mkdir "${WORKUP_DIR}"
84
+ printf "\033[1;32mOK\033[0m\n"
85
+
86
+ printf 'Creating bin directory... '
87
+ [ -d "${WORKUP_BINS}" ] || mkdir "${WORKUP_BINS}"
88
+ printf "\033[1;32mOK\033[0m\n"
89
+
90
+ printf 'Fetching new Policyfile... '
91
+ curl -Lsko "${WORKUP_DIR}/Policyfile.rb" "${WORKUP_URL}/Policyfile.rb"
92
+ printf "\033[1;32mOK\033[0m\n"
93
+
94
+ printf 'Fetching new client.rb... '
95
+ curl -Lsko "${WORKUP_DIR}/client.rb" "${WORKUP_URL}/client.rb"
96
+ printf "\033[1;32mOK\033[0m\n"
97
+
98
+ printf 'Fetching workup... '
99
+ curl -Lsko "${WORKUP_BINS}/workup.rb" "${WORKUP_URL}/workup.rb"
100
+ curl -Lsko "${WORKUP_BINS}/workup" "${WORKUP_URL}/workup.sh"
101
+ chmod +x "${WORKUP_BINS}/workup"
102
+ printf "\033[1;32mOK\033[0m\n"
103
+
104
+ printf 'Installing workup... '
105
+ local_bin='/usr/local/bin/workup'
106
+ [[ -h ${local_bin} ]] || ln -s "${WORKUP_BINS}/workup" "${local_bin}"
107
+ printf "\033[1;32mOK\033[0m\n"
108
+
109
+ printf 'Checking PATH for /usr/local/bin... '
110
+ local_regex='(^|:)/usr/local/bin/?($|:)'
111
+ if [[ "${PATH}" =~ $local_regex ]]; then
112
+ printf "\033[1;32mOK\033[0m\n"
113
+ echo 'You are ready to run workup'
114
+ else
115
+ printf "\033[1;33mNot found\033[0m\n"
116
+ fi
@@ -0,0 +1,18 @@
1
+ chef_repo_path File.join __dir__, 'chef-zero'
2
+ file_cache_path File.join __dir__, 'local-cache'
3
+
4
+ ## Chef zero settings
5
+ local_mode true
6
+ chef_zero.enabled true
7
+ log_level :error
8
+ add_formatter 'doc'
9
+ node_name (ENV['SUDO_USER'] || ENV['USER'] || ENV['USERNAME']).downcase
10
+
11
+ ## Policyfile settings
12
+ policy_name 'workup'
13
+ policy_group 'local'
14
+ use_policyfile true
15
+ policy_document_native_api true
16
+
17
+ # This plugin causes OS X to hang for 5 minutes before every chef client run
18
+ ohai.disabled_plugins = [:Passwd]
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'workup'
4
+ require 'io/console'
5
+
6
+ def password
7
+ ENV['PASSWORD'] ||= begin
8
+ print 'Enter Password: '
9
+ password = STDIN.noecho(&:gets).chomp
10
+ puts
11
+ password
12
+ end
13
+ end
14
+
15
+ password
16
+
17
+ if Process.uid.zero? || Gem.win_platform?
18
+ Workup::Application.start(ARGV)
19
+ else
20
+ puts 'Auto-sudoing'
21
+ exec("sudo PASSWORD=#{password} -k -S -p '' -- #{$PROGRAM_NAME} #{ARGV.join(' ')} <<< #{password}")
22
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Cvent Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'workup/version'
19
+ require 'workup/application'
20
+ require 'workup/helpers'
21
+
22
+ module Workup
23
+ end
@@ -0,0 +1,102 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Cvent Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'thor'
19
+ require 'mixlib/shellout'
20
+
21
+ require 'workup/helpers'
22
+ require 'workup/logging'
23
+
24
+ module Workup
25
+ class Application < Thor
26
+ class_option :workup_dir, type: :string, default: File.join(Dir.home, '.workup')
27
+ class_option :dry_run, type: :boolean, default: false
28
+ class_option :verify_ssl, type: :boolean, default: true
29
+
30
+ attr_reader :log
31
+
32
+ def initialize(*args)
33
+ @log ||= begin
34
+ log = ::Logging.logger['workup']
35
+ log.add_appenders('stdout')
36
+ log.level = :debug
37
+ log
38
+ end
39
+
40
+ Workup::Helpers.check_user!
41
+
42
+ super(*args)
43
+ end
44
+
45
+ no_commands do
46
+ def execute(*cmd, **args)
47
+ command = Gem.win_platform? ? cmd.join(' ') : cmd
48
+
49
+ shell_out = Mixlib::ShellOut.new(command, **args)
50
+ shell_out.run_command
51
+
52
+ if shell_out.error?
53
+ log.error "Error\n"
54
+ log.error shell_out.inspect
55
+ log.error shell_out.stdout
56
+ log.error shell_out.stderr
57
+ exit shell_out.exitstatus
58
+ else
59
+ log.debug "OK\n"
60
+ end
61
+ end
62
+ end
63
+
64
+ desc 'default', 'Default task'
65
+ def default
66
+ log.info "Starting workup\n"
67
+ chef_zero
68
+ chef_client
69
+ end
70
+
71
+ desc 'chef_zero', 'Create the chef-zero directory'
72
+ def chef_zero
73
+ raise 'Workup directory does not exist' unless File.exist?(options[:workup_dir])
74
+ policy_path = File.join(options[:workup_dir], 'Policyfile.rb')
75
+ lock_path = File.join(options[:workup_dir], 'Policyfile.lock.json')
76
+ chefzero_path = File.join(options[:workup_dir], 'chef-zero')
77
+
78
+ log.info 'Updating lock file... '
79
+ execute('chef', (File.exist?(lock_path) ? 'update' : 'install'), policy_path,
80
+ env: { GIT_SSL_NO_VERIFY: options['verify_ssl'] ? '0' : '1' },
81
+ cwd: options[:workup_dir])
82
+
83
+ log.info 'Creating chef-zero directory... '
84
+ execute('chef', 'export', '--force', policy_path, chefzero_path,
85
+ env: { GIT_SSL_NO_VERIFY: options['verify_ssl'] ? '0' : '1' })
86
+ end
87
+
88
+ desc 'chef_client', 'Run chef-client'
89
+ def chef_client
90
+ raise 'Workup directory does not exist' unless File.exist?(options[:workup_dir])
91
+ clientrb_path = File.join(options[:workup_dir], 'client.rb')
92
+
93
+ client_cmd = ['chef-client', '--no-fork', '--config', clientrb_path]
94
+ client_cmd << '-A' if Gem.win_platform?
95
+ client_cmd << '--why-run' if options[:dry_run]
96
+
97
+ execute(*client_cmd, live_stdout: STDOUT, live_stderr: STDERR)
98
+ end
99
+
100
+ default_task :default
101
+ end
102
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Cvent Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module Workup
19
+ class Helpers
20
+ class << self
21
+ def check_user!
22
+ user = ENV['SUDO_USER'] || ENV['USER']
23
+ raise 'You cannot run workup as root directly' if user == 'root'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Cvent Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'logging'
19
+
20
+ module Workup
21
+ class Logging
22
+ ::Logging.color_scheme('bright', lines: { debug: :green, error: :red })
23
+
24
+ ::Logging.appenders.stdout(
25
+ 'stdout',
26
+ layout: ::Logging.layouts.pattern(pattern: '%m', color_scheme: 'bright')
27
+ )
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Cvent Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module Workup
19
+ VERSION = '0.1.0'.freeze
20
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'workup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'workup'
8
+ spec.version = Workup::VERSION
9
+ spec.authors = ['Morley, Jonathan']
10
+ spec.email = ['JMorley@cvent.com']
11
+
12
+ spec.summary = 'A workstation provisioner.'
13
+ spec.description = 'Workup is a workstation provisioning tool that focuses on cross-compatibility
14
+ and minimal assumptions about the initial state of the machine.'
15
+ spec.homepage = 'https://github.com/cvent/workup'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rubocop', '~> 0.42.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+
27
+ spec.add_dependency 'thor', '~> 0.19.1'
28
+ spec.add_dependency 'mixlib-shellout', '~> 2.2'
29
+ spec.add_dependency 'logging', '~> 2.1'
30
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Morley, Jonathan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.42.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.42.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.19.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.19.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: mixlib-shellout
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: logging
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.1'
111
+ description: |-
112
+ Workup is a workstation provisioning tool that focuses on cross-compatibility
113
+ and minimal assumptions about the initial state of the machine.
114
+ email:
115
+ - JMorley@cvent.com
116
+ executables:
117
+ - workup
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".appveyor.yml"
122
+ - ".gitignore"
123
+ - ".rspec"
124
+ - ".rubocop.yml"
125
+ - ".rubocop_todo.yml"
126
+ - ".travis.yml"
127
+ - Gemfile
128
+ - LICENSE
129
+ - Policyfile.rb
130
+ - README.md
131
+ - Rakefile
132
+ - bootstrap.ps1
133
+ - bootstrap.sh
134
+ - client.rb
135
+ - exe/workup
136
+ - lib/workup.rb
137
+ - lib/workup/application.rb
138
+ - lib/workup/helpers.rb
139
+ - lib/workup/logging.rb
140
+ - lib/workup/version.rb
141
+ - workup.gemspec
142
+ homepage: https://github.com/cvent/workup
143
+ licenses: []
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.5.1
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: A workstation provisioner.
165
+ test_files: []