Skip to content

Commit

Permalink
Merge pull request #2 from RoboticCheese/jdh-add-deb-support
Browse files Browse the repository at this point in the history
Add Ubuntu/Debian support
  • Loading branch information
hartmantis committed Jun 3, 2015
2 parents 0f6f2f5 + 539913a commit f633877
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .kitchen.travis.yml
@@ -1,8 +1,17 @@
---
driver:
name: digitalocean
# debian-8 image doesn't exist in nyc2
region: nyc3

platforms:
- name: macosx
driver:
name: localhost
- name: ubuntu-14-04-x64
# The Debian 8 image doesn't have sudo installed
- name: debian-8-x64
provisioner:
sudo_command:
verifier:
sudo_command:
4 changes: 4 additions & 0 deletions .kitchen.yml
Expand Up @@ -14,6 +14,10 @@ platforms:
- name: windows-8
driver:
box: roboticcheese/windows-8
- name: ubuntu-14.04
- name: debian-8
driver:
box: boxcutter/debian80

suites:
- name: default
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -10,7 +10,7 @@ before_script:
- echo -e $DIGITALOCEAN_SSH_KEY_BODY > ~/.ssh/id_rsa

script:
- chef exec rake && chef exec kitchen test macosx
- chef exec rake && chef exec kitchen test -c 6

after_script:

Expand Down
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -15,7 +15,8 @@ A Chef cookbook for installing Steam.
Requirements
============

This cookbook currently supports OS X and Windows. Ubuntu support is coming.
This cookbook currently supports each of Steam's platforms: OS X, Windows, and
Ubuntu/Debian.

Usage
=====
Expand Down Expand Up @@ -67,6 +68,10 @@ Provider for Mac OS X platforms.

Provider for Windows platforms.

***Chef::Provider::SteamApp::Debian***

Provider for Ubuntu/Debian platforms.

***Chef::Provider::SteamApp***

A parent provider for all the platform-specific providers to subclass.
Expand Down
8 changes: 8 additions & 0 deletions files/default/steam.seed
@@ -0,0 +1,8 @@
# Accept the Steam license agreement:
# $ sudo debconf-show steam
# * steam/license:
# * steam/question: I AGREE
# steam/purge:
steam steam/question select I AGREE
#steam/license steam/license note
#steam steam/purge none
12 changes: 6 additions & 6 deletions libraries/provider_mapping.rb
Expand Up @@ -28,9 +28,9 @@
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)
Chef::Platform.set(platform: :ubuntu,
resource: :steam_app,
provider: Chef::Provider::SteamApp::Debian)
Chef::Platform.set(platform: :debian,
resource: :steam_app,
provider: Chef::Provider::SteamApp::Debian)
2 changes: 1 addition & 1 deletion libraries/provider_steam_app.rb
Expand Up @@ -22,7 +22,7 @@
require_relative 'resource_steam_app'
require_relative 'provider_steam_app_mac_os_x'
require_relative 'provider_steam_app_windows'
# TODO: require_relative 'provider_steam_app_debian'
require_relative 'provider_steam_app_debian'

class Chef
class Provider
Expand Down
118 changes: 118 additions & 0 deletions libraries/provider_steam_app_debian.rb
@@ -0,0 +1,118 @@
# Encoding: UTF-8
#
# Cookbook Name:: steam
# Library:: provider_steam_app_debian
#
# 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 'chef/dsl/include_recipe'
require_relative 'provider_steam_app'

class Chef
class Provider
class SteamApp < Provider::LWRPBase
# An provider for Steam on Ubuntu/Debian.
#
# @author Jonathan Hartman <j@p4nt5.com>
class Debian < SteamApp
URL ||= 'https://steamcdn-a.akamaihd.net/client/installer/steam.deb'
PATH ||= '/usr/bin/steam'

include Chef::DSL::IncludeRecipe

private

#
# Install dependencies, download the Steam package, and install it.
#
# (see SteamApp#install!)
#
def install!
resolve_dependencies
download_package
install_package
end

#
# Use a dpkg_package resource to uninstall Steam.
#
# (see SteamApp#remove!)
#
def remove!
dpkg_package 'steam-launcher' do
action :remove
end
end

#
# Use a dpkg_package resource to install the .deb file.
#
def install_package
s = download_path
dpkg_package 'steam-launcher' do
source s
action :install
end
end

#
# Use a remote_file resource to download the .deb 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

#
# Ensure the steam package's dependencies are satisfied since we're
# installing a .deb directly with dpkg. The package depends on one of
# xterm, gnome-terminal, konsole, so only install xterm if neither of
# the others is present.
#
# TODO: The hardcoded package list is pretty ugly. Should either pull
# dependencies from the package file at runtime or wait for the APT
# repo maintainers to fix the bug that prevents us from using that
# (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=772598)
#
def resolve_dependencies
include_recipe 'apt'
%w(python libc6 python-apt xz-utils curl zenity).each do |p|
package p do
action :install
end
end
package 'xterm' do
action :install
not_if 'dpkg -s gnome-terminal || dpkg -s konsole'
end
end
end
end
end
end
3 changes: 3 additions & 0 deletions metadata.rb
Expand Up @@ -11,7 +11,10 @@

depends 'dmg', '~> 2.2'
depends 'windows', '~> 1.37'
depends 'apt', '~> 2.7'

supports 'mac_os_x'
supports 'windows'
supports 'ubuntu'
supports 'debian', '>= 8.0'
# rubocop:enable SingleSpaceBeforeFirstArg
2 changes: 0 additions & 2 deletions spec/libraries/provider_mapping_spec.rb
Expand Up @@ -30,7 +30,6 @@
let(:platform) { :ubuntu }

it 'uses the Debian app provider' do
pending
expect(app_provider).to eq(Chef::Provider::SteamApp::Debian)
end
end
Expand All @@ -39,7 +38,6 @@
let(:platform) { :debian }

it 'uses the Debian app provider' do
pending
expect(app_provider).to eq(Chef::Provider::SteamApp::Debian)
end
end
Expand Down
94 changes: 94 additions & 0 deletions spec/libraries/provider_steam_app_debian_spec.rb
@@ -0,0 +1,94 @@
# Encoding: UTF-8

require_relative '../spec_helper'
require_relative '../../libraries/provider_steam_app_debian'

describe Chef::Provider::SteamApp::Debian 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 'installs dependencies, downloads and installs the package' do
p = provider
expect(p).to receive(:resolve_dependencies)
expect(p).to receive(:download_package)
expect(p).to receive(:install_package)
p.send(:install!)
end
end

describe '#remove!' do
it 'uses a dpkg_package to uninstall the package' do
p = provider
expect(p).to receive(:dpkg_package).with('steam-launcher').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/steam.deb')
end

it 'uses a dpkg_package to install the package' do
p = provider
expect(p).to receive(:dpkg_package).with('steam-launcher').and_yield
expect(p).to receive(:source).with('/tmp/steam.deb')
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/steam.deb')
end

it 'uses a remote_file to download the package' do
p = provider
expect(p).to receive(:remote_file).with('/tmp/steam.deb').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]}/steam.deb"
expect(provider.send(:download_path)).to eq(expected)
end
end

describe '#resolve_dependencies' do
before(:each) do
allow_any_instance_of(described_class).to receive(:include_recipe)
allow_any_instance_of(described_class).to receive(:package)
end

it 'ensures the APT cache is up to date' do
p = provider
expect(p).to receive(:include_recipe).with('apt')
p.send(:resolve_dependencies)
end

it 'installs all the hard requirements and, conditonally, xterm' do
p = provider
%w(python libc6 python-apt xz-utils curl zenity).each do |pkg|
expect(p).to receive(:package).with(pkg).and_yield
expect(p).to receive(:action).with(:install)
end
expect(p).to receive(:package).with('xterm').and_yield
expect(p).to receive(:action).with(:install)
expect(p).to receive(:not_if)
.with('dpkg -s gnome-terminal || dpkg -s konsole')
p.send(:resolve_dependencies)
end
end
end
7 changes: 7 additions & 0 deletions test/integration/default/serverspec/localhost/app_spec.rb
Expand Up @@ -14,4 +14,11 @@
expect(subject).to be_installed
end
end

describe package('steam-launcher'),
if: %w(ubuntu debian).include?(os[:family]) do
it 'is installed' do
expect(subject).to be_installed
end
end
end
16 changes: 15 additions & 1 deletion test/integration/uninstall/serverspec/localhost/app_spec.rb
Expand Up @@ -11,7 +11,21 @@

describe package('Steam'), if: os[:family] == 'windows' do
it 'is not installed' do
expect(subject).to be_installed
expect(subject).not_to be_installed
end
end

describe package('steam-launcher'),
if: %w(ubuntu debian).include?(os[:family]) do
it 'is not installed' do
expect(subject).not_to be_installed
end
end

# Just in case, check both package names it might be going by
describe package('steam'), if: %w(ubuntu debian).include?(os[:family]) do
it 'is not installed' do
expect(subject).not_to be_installed
end
end
end

0 comments on commit f633877

Please sign in to comment.