Skip to content

Commit

Permalink
Merge pull request #6 from RoboticCheese/roboticcheese/additional-pla…
Browse files Browse the repository at this point in the history
…tform-support

Robustify platform support
  • Loading branch information
hartmantis committed May 2, 2015
2 parents 7ed029a + ad46d47 commit 8d1ab85
Show file tree
Hide file tree
Showing 33 changed files with 748 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .kitchen.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ driver:

platforms:
- name: macosx
driver:
name: localhost

suites:
- name: mac_direct_download
run_list:
- recipe[divvy_test::mac_direct_download]
attributes:
13 changes: 11 additions & 2 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ provisioner:
name: chef_zero

platforms:
- name: macosx
- name: macosx-10.10
driver:
box: roboticcheese/macosx
box: roboticcheese/macosx-10.10
ssh:
insert_key: false
gui: true
- name: windows-2012
driver:
box: roboticcheese/windows-2012

suites:
- name: default
Expand All @@ -21,3 +24,9 @@ suites:
mac_app_store:
username: <%= ENV['APPLE_ID_USERNAME'] %>
password: <%= ENV['APPLE_ID_PASSWORD'] %>
- name: mac_direct_download
run_list:
- recipe[divvy_test::mac_direct_download]
attributes:
excludes:
- windows-2012
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_script:
- cp .kitchen.travis.yml .kitchen.local.yml

script:
- chef exec rake
- chef exec rake && chef exec rake kitchen:all

after_script:

Expand Down
2 changes: 2 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
source 'https://supermarket.chef.io'

metadata

cookbook 'divvy_test', path: 'test/fixtures/cookbooks/divvy_test'
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Divvy Cookbook CHANGELOG

v?.?.? (????-??-??)
-------------------
- Add support for non-App Store direct downloads for OS X
- Add support for Windows
- Grant required Accessibility privileges automatically on OS X
- Add a `:run` action and start Divvy after it's installed

v0.1.0 (2015-04-25)
-------------------
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ group :test do
gem 'test-kitchen'
gem 'kitchen-localhost'
gem 'kitchen-vagrant'
gem 'winrm-transport'
end

group :integration do
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Recipes

***default***

Opens the Mac App Store and performs a simple install of the app.
Installs Divvy (from the Mac App Store or a Windows direct download by
default) and starts it.

Resources
=========
Expand All @@ -44,20 +45,37 @@ Used to perform installation of the app.
Syntax:

divvy_app 'default' do
action :install
action [:install, :run]
end

Actions:

| Action | Description |
|------------|-----------------|
| `:install` | Install the app |
| `:run` | Run the app |

Attributes:

| Attribute | Default | Description |
|------------|----------------|----------------------|
| action | `:install` | Action(s) to perform |
| Attribute | Default | Description |
|------------|--------------------|----------------------|
| action | `[:install, :run]` | Action(s) to perform |

Providers
=========

***Chef::Provider::DivvyApp::MacOsX::AppStore***

Provider for installing Divvy from the Mac App Store (default for OS X).

***Chef::Provider::DivvyApp::MacOsX::Direct***

Provider to do a direct download and install for OS X from the vendor's site.

***Chef::Provider::DivvyApp::Windows***

Provider to do a direct download and install from the vendor's site (default
for Windows).

Contributing
============
Expand Down
6 changes: 4 additions & 2 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
if defined?(ChefSpec)
ChefSpec.define_matcher(:divvy_app)

def install_divvy_app(name)
ChefSpec::Matchers::ResourceMatcher.new(:divvy_app, :install, name)
[:install, :run].each do |a|
define_method("#{a}_divvy_app") do |name|
ChefSpec::Matchers::ResourceMatcher.new(:divvy_app, a, name)
end
end
end
23 changes: 23 additions & 0 deletions libraries/provider_divvy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require 'chef/provider/lwrp_base'
require_relative 'resource_divvy_app'
require_relative 'provider_divvy_app_mac_os_x'
require_relative 'provider_divvy_app_windows'

class Chef
class Provider
Expand All @@ -45,10 +46,32 @@ def whyrun_supported?
action :install do
install!
new_resource.installed(true)
Chef::Log.info(
'If you have a Divvy license, don\'t forget to enter it in the app!'
)
end

#
# Start the app.
#
action :run do
start!
new_resource.running(true)
end

private

#
# Start the Divvy app running using whatever command is appropriate for
# the current platform.
#
# @raise [NotImplementedError] if not defined for this provider.
#
def start!
fail(NotImplementedError,
"`start` method not implemented for #{self.class} provider")
end

#
# Do the actual app installation.
#
Expand Down
51 changes: 51 additions & 0 deletions libraries/provider_divvy_app_mac_os_x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
# limitations under the License.
#

require 'etc'
require 'chef/provider/lwrp_base'
require_relative 'provider_divvy_app'
require_relative 'provider_divvy_app_mac_os_x_app_store'
require_relative 'provider_divvy_app_mac_os_x_direct'

class Chef
class Provider
Expand All @@ -29,6 +31,55 @@ class DivvyApp < Provider::LWRPBase
#
# @author Jonathan Hartman <j@p4nt5.com>
class MacOsX < DivvyApp
# `URL` varies by sub-provider
PATH ||= '/Applications/Divvy.app'

private

#
# (see DivvyApp#start!)
#
def start!
execute 'start divvy' do
command "open #{PATH}"
user Etc.getlogin
action :run
only_if do
cmd = 'ps -A -c -o command | grep ^Divvy$'
Mixlib::ShellOut.new(cmd).run_command.stdout.empty?
end
end
end

#
# Authorize the Divvy app.
#
# (see DivvyApp#install!)
#
def install!
authorize_app!
end

#
# Declare a trusted_app resource and grant Accessibility to the app.
#
def authorize_app!
mac_app_store_trusted_app app_id do
action :create
end
end

#
# Return the ID the Accessibility database needs for this provider.
#
# @return [String]
#
# @raise [NotImplementedError] if not overloaded for this provider
#
def app_id
fail(NotImplementedError,
"`app_id` method not implemented for #{self.class} provider")
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions libraries/provider_divvy_app_mac_os_x_app_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def install!
bundle_id 'com.mizage.divvy'
action :install
end
super
end

#
# (see MacOsX#app_id)
#
def app_id
'com.mizage.Divvy'
end
end
end
Expand Down
88 changes: 88 additions & 0 deletions libraries/provider_divvy_app_mac_os_x_direct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Encoding: UTF-8
#
# Cookbook Name:: divvy
# Library:: provider_divvy_app_mac_os_x_direct
#
# Copyright 2015 Jonathan Hartman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/provider/lwrp_base'
require_relative 'provider_divvy_app'
require_relative 'provider_divvy_app_mac_os_x'

class Chef
class Provider
class DivvyApp < Provider::LWRPBase
class MacOsX < DivvyApp
# A Chef provider for OS X installs via direct download.
#
# @author Jonathan Hartman <j@p4nt5.com>
class Direct < MacOsX
URL ||= 'http://mizage.com/downloads/Divvy.zip'

private

#
# (see DivvyApp#install!)
#
def install!
download_package
install_package
super
end

#
# Declare a remote_file resource for downloading the file.
#
def download_package
remote_file download_path do
source URL
action :create
only_if { !::File.exist?(PATH) }
end
end

#
# Declare an execute resource for extracting the downloaded file.
#
def install_package
path = download_path
execute 'unzip divvy' do
command "unzip -d /Applications #{path}"
action :run
creates PATH
end
end

#
# Construct a path to download the app file to.
#
# @return [String]
#
def download_path
::File.join(Chef::Config[:file_cache_path], ::File.basename(URL))
end

#
# (see MacOsx#app_id)
#
def app_id
'com.mizage.direct.Divvy'
end
end
end
end
end
end
Loading

0 comments on commit 8d1ab85

Please sign in to comment.