Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add everything for a basic app resource and OS X provider
- Loading branch information
1 parent
4269667
commit 352819a
Showing
25 changed files
with
573 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
--- | ||
driver: | ||
name: digitalocean | ||
|
||
platforms: | ||
- name: macosx | ||
driver: | ||
name: localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
source 'https://supermarket.chef.io' | ||
|
||
metadata | ||
|
||
cookbook 'steam_test', path: 'test/fixtures/cookbooks/steam_test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# Cookbook Name:: steam | ||
# Library:: matchers | ||
# | ||
# 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. | ||
# | ||
|
||
if defined?(ChefSpec) | ||
ChefSpec.define_matcher(:steam_app) | ||
|
||
[:install, :remove].each do |a| | ||
define_method("#{a}_steam_app") do |name| | ||
ChefSpec::Matchers::ResourceMatcher.new(:steam_app, a, name) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# Cookbook Name:: steam | ||
# Library:: provider_mapping | ||
# | ||
# 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/dsl' | ||
require 'chef/platform/provider_mapping' | ||
require_relative 'provider_steam_app' | ||
|
||
Chef::Platform.set(platform: :mac_os_x, | ||
resource: :steam_app, | ||
provider: Chef::Provider::SteamApp::MacOsX) | ||
# TODO: Chef::Platform.set(platform: :windows, | ||
# resource: :steam_app, | ||
# provider: Chef::Provider::SteamApp::Windows) | ||
# TODO: Chef::Platform.set(platform: :ubuntu, | ||
# resource: :steam_app, | ||
# provider: Chef::Provider::SteamApp::Debian) | ||
# TODO: Chef::Platform.set(platform: :debian, | ||
# resource: :steam_app, | ||
# provider: Chef::Provider::SteamApp::Debian) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# Cookbook Name:: steam | ||
# Library:: provider_steam_app | ||
# | ||
# 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 'resource_steam_app' | ||
require_relative 'provider_steam_app_mac_os_x' | ||
# TODO: require_relative 'provider_steam_app_windows' | ||
# TODO: require_relative 'provider_steam_app_debian' | ||
|
||
class Chef | ||
class Provider | ||
# A Chef provider for the Steam app. | ||
# | ||
# @author Jonathan Hartman <j@p4nt5.com> | ||
class SteamApp < Provider::LWRPBase | ||
use_inline_resources | ||
|
||
# | ||
# WhyRun is supported by this provider. | ||
# | ||
# @return [TrueClass, FalseClass] | ||
# | ||
def whyrun_supported? | ||
true | ||
end | ||
|
||
# | ||
# Install the app if it's not already and set the new_resource installed | ||
# status to true. | ||
# | ||
action :install do | ||
install! | ||
new_resource.installed(true) | ||
end | ||
|
||
# | ||
# Remove the app if it's installed and set the new_resource installed | ||
# status to false. | ||
# | ||
action :remove do | ||
remove! | ||
new_resource.installed(false) | ||
end | ||
|
||
private | ||
|
||
# | ||
# Do the actual app installation. | ||
# | ||
# @raise [NotImplementedError] if not defined for this provider. | ||
# | ||
def install! | ||
fail(NotImplementedError, | ||
"`install!` method not implemented for #{self.class} provider") | ||
end | ||
|
||
# | ||
# Do the actual app removal. | ||
# | ||
# @raise [NotImplementedError] if not defined for this provider. | ||
# | ||
def remove! | ||
fail(NotImplementedError, | ||
"`remove!` method not implemented for #{self.class} provider") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# Cookbook Name:: steam | ||
# Library:: provider_steam_app_mac_os_x | ||
# | ||
# 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_steam_app' | ||
|
||
class Chef | ||
class Provider | ||
class SteamApp < Provider::LWRPBase | ||
# An provider for Steam on Mac OS X. | ||
# | ||
# @author Jonathan Hartman <j@p4nt5.com> | ||
class MacOsX < SteamApp | ||
URL ||= 'https://steamcdn-a.akamaihd.net/client/installer/steam.dmg' | ||
PATH ||= '/Applications/Steam.app' | ||
|
||
private | ||
|
||
# | ||
# Use a dmg_package resource to download and install the package. The | ||
# dmg_resource creates an inline remote_file, so this is all that's | ||
# needed. | ||
# | ||
# (see SteamApp#install!) | ||
# | ||
def install! | ||
dmg_package 'Steam' do | ||
source URL | ||
accept_eula true | ||
action :install | ||
end | ||
end | ||
|
||
# | ||
# (see SteamApp#remove!) | ||
# | ||
def remove! | ||
[ | ||
PATH, | ||
::File.expand_path('~/Library/Application Support/Steam'), | ||
::File.expand_path('~/Library/Logs/Steam') | ||
].each do |d| | ||
directory d do | ||
recursive true | ||
action :delete | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.