Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RoboticCheese/jdh-add-windows-support
Add Windows support
- Loading branch information
Showing
15 changed files
with
227 additions
and
35 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
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
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,93 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# Cookbook Name:: steam | ||
# Library:: provider_steam_app_windows | ||
# | ||
# 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 Windows. | ||
# | ||
# @author Jonathan Hartman <j@p4nt5.com> | ||
class Windows < SteamApp | ||
URL ||= 'https://steamcdn-a.akamaihd.net/client/installer/' \ | ||
'SteamSetup.exe' | ||
PATH ||= ::File.expand_path('/Program Files (x86)/Steam') | ||
|
||
private | ||
|
||
# | ||
# Download and install the remote package. | ||
# | ||
# (see SteamApp#install!) | ||
# | ||
def install! | ||
download_package | ||
install_package | ||
end | ||
|
||
# | ||
# Use a windows_package resource to uninstall Steam. | ||
# | ||
# (see SteamApp#remove!) | ||
# | ||
def remove! | ||
windows_package 'Steam' do | ||
action :remove | ||
end | ||
end | ||
|
||
# | ||
# Use a windows_package resource to install the .exe file. | ||
# | ||
def install_package | ||
s = download_path | ||
windows_package 'Steam' do | ||
source s | ||
installer_type :nsis | ||
action :install | ||
end | ||
end | ||
|
||
# | ||
# Use a remote_file resource to download the .exe file to Chef's cache | ||
# dir. | ||
# | ||
def download_package | ||
remote_file download_path do | ||
source URL | ||
action :create | ||
only_if { !::File.exist?(PATH) } | ||
end | ||
end | ||
|
||
# | ||
# Construct a download destination under Chef's cache dir. | ||
# | ||
# @return [String] | ||
# | ||
def download_path | ||
::File.join(Chef::Config[:file_cache_path], ::File.basename(URL)) | ||
end | ||
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
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,68 @@ | ||
# Encoding: UTF-8 | ||
|
||
require_relative '../spec_helper' | ||
require_relative '../../libraries/provider_steam_app_windows' | ||
|
||
describe Chef::Provider::SteamApp::Windows do | ||
let(:name) { 'default' } | ||
let(:new_resource) { Chef::Resource::SteamApp.new(name, nil) } | ||
let(:provider) { described_class.new(new_resource, nil) } | ||
|
||
describe '#install!' do | ||
it 'downloads and installs the package' do | ||
p = provider | ||
expect(p).to receive(:download_package) | ||
expect(p).to receive(:install_package) | ||
p.send(:install!) | ||
end | ||
end | ||
|
||
describe '#remove!' do | ||
it 'uses a windows_package to uninstall the package' do | ||
p = provider | ||
expect(p).to receive(:windows_package).with('Steam').and_yield | ||
expect(p).to receive(:action).with(:remove) | ||
p.send(:remove!) | ||
end | ||
end | ||
|
||
describe '#install_package' do | ||
before(:each) do | ||
allow_any_instance_of(described_class).to receive(:download_path) | ||
.and_return('/tmp/SteamSetup.exe') | ||
end | ||
|
||
it 'uses a windows_package to install the package' do | ||
p = provider | ||
expect(p).to receive(:windows_package).with('Steam').and_yield | ||
expect(p).to receive(:source).with('/tmp/SteamSetup.exe') | ||
expect(p).to receive(:installer_type).with(:nsis) | ||
expect(p).to receive(:action).with(:install) | ||
p.send(:install_package) | ||
end | ||
end | ||
|
||
describe '#download_package' do | ||
before(:each) do | ||
allow_any_instance_of(described_class).to receive(:download_path) | ||
.and_return('/tmp/SteamSetup.exe') | ||
end | ||
|
||
it 'uses a remote_file to download the package' do | ||
p = provider | ||
expect(p).to receive(:remote_file).with('/tmp/SteamSetup.exe').and_yield | ||
expect(p).to receive(:source).with(described_class::URL) | ||
expect(p).to receive(:action).with(:create) | ||
expect(p).to receive(:only_if).and_yield | ||
expect(File).to receive(:exist?).with(described_class::PATH) | ||
p.send(:download_package) | ||
end | ||
end | ||
|
||
describe '#download_path' do | ||
it 'returns a path under the Chef cache dir' do | ||
expected = "#{Chef::Config[:file_cache_path]}/SteamSetup.exe" | ||
expect(provider.send(:download_path)).to eq(expected) | ||
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
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,11 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# rubocop:disable SingleSpaceBeforeFirstArg | ||
name 'apt' | ||
maintainer 'test' | ||
maintainer_email 'example@example.com' | ||
license 'apache2' | ||
description 'apt' | ||
long_description 'apt' | ||
version '0.0.1' | ||
# rubocop:enable SingleSpaceBeforeFirstArg |
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,11 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# rubocop:disable SingleSpaceBeforeFirstArg | ||
name 'dmg' | ||
maintainer 'test' | ||
maintainer_email 'example@example.com' | ||
license 'apache2' | ||
description 'dmg' | ||
long_description 'dmg' | ||
version '0.0.1' | ||
# rubocop:enable SingleSpaceBeforeFirstArg |
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,11 @@ | ||
# Encoding: UTF-8 | ||
# | ||
# rubocop:disable SingleSpaceBeforeFirstArg | ||
name 'windows' | ||
maintainer 'test' | ||
maintainer_email 'example@example.com' | ||
license 'apache2' | ||
description 'windows' | ||
long_description 'windows' | ||
version '0.0.1' | ||
# rubocop:enable SingleSpaceBeforeFirstArg |
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