Skip to content

Commit

Permalink
group verification code with the installers
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Apr 6, 2013
1 parent 9d1e558 commit 51efb09
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 179 deletions.
8 changes: 7 additions & 1 deletion lib/sprinkle/installers/apt.rb
Expand Up @@ -11,8 +11,8 @@ module Installers
# First, a simple installation of the magic_beans package:
#
# package :magic_beans do
# description "Beans beans they're good for your heart..."
# apt 'magic_beans_package'
# verify { has_apt 'magic_beans_package' }
# end
#
# Second, only build the magic_beans dependencies:
Expand All @@ -31,6 +31,12 @@ def initialize(parent, *packages, &block) #:nodoc:
super parent, *packages, &block
@options.reverse_merge!(:dependencies_only => false)
end

verify_api do
def has_apt(package)
@commands << "dpkg --status #{package} | grep \"ok installed\""
end
end

protected

Expand Down
11 changes: 10 additions & 1 deletion lib/sprinkle/installers/brew.rb
Expand Up @@ -9,7 +9,10 @@ module Installers
#
# package :magic_beans do
# description "Beans beans they're good for your heart..."
# brew 'magic_beans_package'
# brew 'ntp'
#
# verify { has_brew 'ntp' }
#
# end
#
class Brew < PackageInstaller
Expand All @@ -20,6 +23,12 @@ def brew(*names, &block)
install Sprinkle::Installers::Brew.new(self, *names, &block)
end
end

verify_api do
def has_brew(package)
@commands << "brew list | grep #{package}"
end
end

protected

Expand Down
21 changes: 19 additions & 2 deletions lib/sprinkle/installers/group.rb
@@ -1,20 +1,37 @@
module Sprinkle
module Installers
class Group < Installer
# The user installer helps add groups. You may pass flags as an option.
#
# == Example Usage
#
# package :users do
# add_group 'webguys', :flags => "--shell /usr/bin/zsh"
#
# verify do
# has_group 'webguys'
# end
# end

api do
def add_group(group, options={}, &block)
install Sprinkle::Installers::Group.new(self, group, options, &block)
end
end

def initialize(package, groupname, options, &block)
verify_api do
def has_group(group)
@commands << "id -g #{group}"
end
end

def initialize(package, groupname, options, &block) #:nodoc:
super package, options, &block
@groupname = groupname
end

protected
def install_commands
def install_commands #:nodoc:
"addgroup #{@options[:flags]} #{@groupname}"
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/sprinkle/installers/installer.rb
Expand Up @@ -69,6 +69,10 @@ def subclasses
def api(&block)
Sprinkle::Package::Package.class_eval &block
end

def verify_api(&block)
Sprinkle::Verify.class_eval &block
end

def inherited(base)
subclasses << base
Expand Down
19 changes: 18 additions & 1 deletion lib/sprinkle/installers/npm.rb
@@ -1,14 +1,31 @@
module Sprinkle
module Installers

# = Npm package Installed
#
# Installs an npm module
#
# == Example Usage
#
# package :magic_beans do
# npm 'grunt'
# end
#
# verify { has_npm 'grunt' }
class Npm < Installer

attr_accessor :package_name

api do
def npm(package, &block)
install Sprinkle::Installers::Npm.new(self, package, &block)
end
end

verify_api do
def has_npm(package)
@commands << "npm --global list | grep \"#{package}@\""
end
end

def initialize(parent, package_name, &block) #:nodoc:
super parent, &block
Expand Down
17 changes: 16 additions & 1 deletion lib/sprinkle/installers/pear.rb
@@ -1,6 +1,15 @@
module Sprinkle
module Installers

# = Pear package installed
#
# Installs the specified pear package
#
# == Example Usage
#
# package :php_stuff do
# pear 'PHP_Compat'
# verify { has_pear 'PHP_Compat' }
# end
class Pear < Installer
attr_accessor :package_name

Expand All @@ -9,6 +18,12 @@ def pear(package, &block)
install Sprinkle::Installers::Pear.new(self, package, &block)
end
end

verify_api do
def has_pear(package)
@commands << "pear list | grep \"#{package}\" | grep \"stable\""
end
end

def initialize(parent, package_name, &block) #:nodoc:
super parent, &block
Expand Down
7 changes: 7 additions & 0 deletions lib/sprinkle/installers/rpm.rb
Expand Up @@ -10,6 +10,7 @@ module Installers
#
# package :magic_beans do
# rpm 'magic_beans'
# verify { has_rpm 'magic_beans' }
# end
#
# You may also specify multiple rpms as an array:
Expand All @@ -18,6 +19,12 @@ module Installers
# rpm %w(magic_beans magic_sauce)
# end
class Rpm < PackageInstaller

verify_api do
def has_rpm(package)
@commands << "rpm -qa | grep #{package}"
end
end

protected

Expand Down
17 changes: 16 additions & 1 deletion lib/sprinkle/installers/user.rb
Expand Up @@ -5,8 +5,13 @@ module Installers
# == Example Usage
#
# package :users do
# adduser 'admin', :flags => "--disabled-password"
# add_user 'admin', :flags => "--disabled-password"
#
# verify do
# has_user 'admin', :in_group = "root"
# end
# end

class User < Installer

api do
Expand All @@ -15,6 +20,16 @@ def add_user(username, options={}, &block)
end
end

verify_api do
def has_user(user, opts = {})
if opts[:in_group]
@commands << "id -G #{user} | xargs -n1 echo | grep #{opts[:in_group]}"
else
@commands << "id #{user}"
end
end
end

def initialize(package, username, options = {}, &block) #:nodoc:
super package, options, &block
@username = username
Expand Down
7 changes: 7 additions & 0 deletions lib/sprinkle/installers/yum.rb
Expand Up @@ -8,6 +8,7 @@ module Installers
#
# package :magic_beans do
# yum 'magic_beans'
# verify { has_yum 'magic_beans' }
# end
#
# You may also specify multiple rpms as arguments or an array:
Expand All @@ -17,6 +18,12 @@ module Installers
# end
class Yum < PackageInstaller

verify_api do
def has_yum(package)
@commands << "yum list installed #{package} | grep ^#{package}"
end
end

protected

def install_commands #:nodoc:
Expand Down
21 changes: 0 additions & 21 deletions lib/sprinkle/verifiers/apt.rb

This file was deleted.

21 changes: 0 additions & 21 deletions lib/sprinkle/verifiers/brew.rb

This file was deleted.

21 changes: 0 additions & 21 deletions lib/sprinkle/verifiers/npm.rb

This file was deleted.

16 changes: 2 additions & 14 deletions lib/sprinkle/verifiers/package.rb
Expand Up @@ -4,20 +4,8 @@ module Package
Sprinkle::Verify.register(Sprinkle::Verifiers::Package)

def has_package(*packages)
if packages.is_a?(Array) && packages.first.is_a?(Array)
packages = packages.first
else
packages = [packages] unless packages.is_a? Array
end

packages.each do |pak|
case Sprinkle::Installers::InstallPackage.installer
when :yum
@commands << "[ -n \"`yum list installed #{pak} 2> /dev/null | egrep -e \\\"#{pak}\\\"`\" ]"
else
raise "Unknown InstallPackage.installer"
end
end
puts "has_package and has_packages are depreciated"
raise "plase use has_yum and friends instead"
end

alias_method :has_packages, :has_package
Expand Down
21 changes: 0 additions & 21 deletions lib/sprinkle/verifiers/pear.rb

This file was deleted.

21 changes: 0 additions & 21 deletions lib/sprinkle/verifiers/rpm.rb

This file was deleted.

0 comments on commit 51efb09

Please sign in to comment.