Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reimplement as a puppet-defined custom type

  • Loading branch information...
commit a28d3937c77ea7d16f7a005778e787f2d3eba92f 1 parent 8ee5632
@wfarr authored
View
17 README.md
@@ -8,23 +8,18 @@ boolean, integer, or string types.
## Requirements
* Ruby 1.8 or 1.9
-* Puppet 2.7.0 or later
+* Puppet 2.6.0 or later
* OS X
## Usage
```
-defaults { 'translucent_dock_icons':
- domain => 'com.apple.dock',
- key => 'showhidden',
- value => true,
+osx_defaults { "require pass at screensaver":
ensure => present,
- notify => Exec['restart_dock']
-}
-
-exec { 'restart_dock':
- command => 'killall Dock',
- refreshonly => true
+ domain => 'com.apple.screensaver',
+ key => 'askForPassword',
+ value => 1,
+ user => 'dummy'
}
```
View
46 lib/puppet/provider/defaults/osx.rb
@@ -1,46 +0,0 @@
-require 'rubygems'
-
-Puppet::Type.type(:defaults).provide(:osx) do
- desc "Manage OSX defaults"
-
- confine :operatingsystem => :darwin
-
- commands :defaults => "/usr/bin/defaults"
-
- def create
- type_and_val = self.class.get_type_val_string(resource[:value])
- defaults(:write, resource[:domain], resource[:key], type_and_val)
- end
-
- def defaults(command)
- if resource[:user]
- asuser(resource[:user]) { super }
- end
- end
-
- def destroy
- defaults(:delete, resource[:domain], resource[:key])
- end
-
- def exists?
- su_str = "su - #{resource[:user]}" if resource[:user]
- `#{su_str} /usr/bin/defaults read #{resource[:domain]} | grep '#{resource[:key]}'`
- if $? == 0
- defaults(:read, resource[:domain], resource[:key]).split(' ')[1] == resource[:value].to_s
- else
- false
- end
- end
-
- def self.get_type_val_string(val)
- if val.kind_of? Numeric
- "-int #{val}"
- elsif val.kind_of? String
- "-string '#{val}'"
- elsif val.kind_of?(TrueClass) || val.kind_of?(FalseClass)
- "-bool #{val}"
- else
- raise ArgumentError, "The type of #{val} is not supported"
- end
- end
-end
View
8 lib/puppet/type/defaults.rb
@@ -1,8 +0,0 @@
-Puppet::Type.newtype(:defaults) do
- ensurable
-
- newparam(:name, :namevar => true)
- newparam(:domain)
- newparam(:key)
- newparam(:value)
-end
View
27 manifests/osx_defaults.pp
@@ -0,0 +1,27 @@
+define osx_defaults(
+ $ensure = 'present',
+ $domain = undef,
+ $key = undef,
+ $value = undef,
+ $user = undef,
+) {
+ $defaults_cmd = "/usr/bin/defaults"
+
+ if $ensure == 'present' {
+ if ($domain != undef) and ($key != undef) and ($value != undef) {
+ exec { "osx_defaults write ${domain}:${key}=>${value}":
+ command => "${defaults_cmd} write ${domain} ${key} ${value}",
+ unless => "${defaults_cmd} read ${domain} ${key}|egrep '^${value}$'",
+ user => $user
+ }
+ } else {
+ warn("Cannot ensure present without domain, key, and value attributes")
+ }
+ } else {
+ exec { "osx_defaults delete ${domain}:${key}":
+ command => "${defaults_cmd} delete ${domain} ${key}",
+ onlyif => "${defaults_cmd} read ${domain} | grep ${key}",
+ user => $user
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.