Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 693915f3f4e1541c00850ebb449e74f310799d96 @wfarr committed Mar 31, 2012
Showing with 103 additions and 0 deletions.
  1. +8 −0 Modulefile
  2. +35 −0 README.md
  3. +40 −0 lib/puppet/provider/defaults/osx.rb
  4. +8 −0 lib/puppet/type/defaults.rb
  5. +12 −0 metadata.json
@@ -0,0 +1,8 @@
+name 'wfarr-osx_defaults'
+version '0.1.0'
+source 'https://github.com/wfarr/wfarr-osx_defaults'
+author 'wfarr'
+license 'APACHE2'
+summary 'Puppet provider for OS X defaults'
+description 'Puppet module for managing OS X defaults system'
+project_page 'https://github.com/wfarr/wfarr-osx_defaults'
@@ -0,0 +1,35 @@
+# Defaults
+
+This is a simple puppet module for managing the defaults system in OS X.
+
+It currently has support for defaults domain keys whose values are
+boolean, integer, or string types.
+
+## Requirements
+
+* Ruby 1.8 or 1.9
+* Puppet 2.7.0 or later
+* OS X
+
+## Usage
+
+```
+defaults { 'translucent_dock_icons':
+ domain => 'com.apple.dock',
+ key => 'showhidden',
+ value => true,
+ ensure => present,
+ notify => Exec['restart_dock']
+}
+
+exec { 'restart_dock':
+ command => 'killall Dock',
+ refreshonly => true
+}
+```
+
+## Contributing
+
+* Fork It
+* Fix It
+* Send a Pull Request
@@ -0,0 +1,40 @@
+require 'rubygems'
+require 'pry'
+
+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 destroy
+ defaults(:delete, resource[:domain], resource[:key])
+ end
+
+ def exists?
+ `/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
@@ -0,0 +1,8 @@
+Puppet::Type.newtype(:defaults) do
+ ensurable
+
+ newparam(:name, :namevar => true)
+ newparam(:domain)
+ newparam(:key)
+ newparam(:value)
+end
@@ -0,0 +1,12 @@
+/*
++-----------------------------------------------------------------------+
+| |
+| ==> DO NOT EDIT THIS FILE! <== |
+| |
+| You should edit the `Modulefile` and run `puppet-module build` |
+| to generate the `metadata.json` file for your releases. |
+| |
++-----------------------------------------------------------------------+
+*/
+
+{}

0 comments on commit 693915f

Please sign in to comment.