Skip to content

Commit

Permalink
Initial commit w/ updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
heathtechnical committed May 13, 2015
0 parents commit 2faa1b6
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 0.3.2'
gem 'facter', '>= 1.7.0'
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# systemsetup

#### Table of Contents

1. [Overview](#overview)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Limitations - OS compatibility, etc.](#limitations)

## Overview

This Puppet module provides basic system configuration of a Mac OS X system using
the 'systemsetup' utility.

## Usage

class { 'systemsetup':
remote_login => true,
time_zone => 'Europe/London',
use_network_time => true,
network_time_server => 'time.apple.com',
computer_sleep_mins => 30,
display_sleep_mins => 5,
harddisk_sleep_mins => 20
}

Parameters are fairly self-explanatory and are documented in 'man systemsetup',
they are also all optional.

Computer/display/harddisk sleep minutes can be set to Never by setting the
relevant parameters to 0.

Puppet > 3.0 users can also pass in parameters using hiera variables:

systemsetup::remote_login: true

## Limitations

This module only implements a subset of configuration items provided by the
'systemsetup' command.
18 changes: 18 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
155 changes: 155 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# == Class: systemsetup
#
# Set basic System Preferences settings
#
# === Parameters
#
# [*remote_login*]
# Enable/disable remote login via SSH.
#
# [*time_zone*]
# Set the system timezone. See 'systemsetup -listtimezones' for available
# timezones.
#
# [*use_network_time*]
# Enable/disable NTP.
#
# [*network_time_server*]
# Set NTP server.
#
# [*computer_sleep_mins*]
# Set system sleep minutes, 0 for Never.
#
# [*display_sleep_mins*]
# Set display sleep minutes, 0 for Never.
#
# [*harddisk_sleep_mins*]
# Set hard disk spin down minutes, 0 for Never.
#
# === Examples
#
# class { 'systemsetup':
# remote_login => true,
# time_zone => 'Europe/London',
# use_network_time => true,
# network_time_server => 'time.apple.com',
# computer_sleep_mins => 30,
# display_sleep_mins => 5,
# harddisk_sleep_mins => 20
# }
#
# === Authors
#
# Author Name <[email protected]>
#
# === Copyright
#
# Copyright 2015 Dan Heath, unless otherwise noted.
#


class systemsetup(
$remote_login = undef,
$time_zone = undef,
$use_network_time = undef,
$network_time_server = undef,
$computer_sleep_mins = undef,
$display_sleep_mins = undef,
$hardddisk_sleep_mins = undef
){
# Remote login
if $remote_login {
if $remote_login == true {
systemsetup::run { 'remote_login':
key => 'remotelogin',
value => 'on',
when_match => 'Off$'
}
}else{
systemsetup::run { 'remote_login':
key => 'remotelogin',
value => 'off',
when_match => 'On$',
pre_pipe => '/usr/bin/yes yes'
}
}
}

# Time zone
if $time_zone {
systemsetup::run { 'time_zone':
key => 'timezone',
value => $time_zone,
when_match => "${time_zone}$",
invert_when_match => true
}
}

# Using NTP
if $use_network_time == true {
systemsetup::run { 'use_network_time':
key => 'usingnetworktime',
value => 'On',
when_match => 'Off$',
}
}

# NTP Server
if $network_time_server {
systemsetup::run { 'network_time_server':
key => 'networktimeserver',
value => $network_time_server,
when_match => "${network_time_server}$",
invert_when_match => true
}
}

# Computer Sleep Minutes
if $computer_sleep_mins != undef {
if $computer_sleep_mins == 0 {
$computer_sleep_mins_when_match = 'Never'
}else{
$computer_sleep_mins_when_match = "after ${computer_sleep_mins} minutes"
}

systemsetup::run { 'computer_sleep_mins':
key => 'computersleep',
value => $computer_sleep_mins,
when_match => $computer_sleep_mins_when_match,
invert_when_match => true
}
}

# Display Sleep Minutes
if $display_sleep_mins != undef {
if $display_sleep_mins == 0 {
$display_sleep_mins_when_match = 'Never'
}else{
$display_sleep_mins_when_match = "after ${display_sleep_mins} minutes"
}

systemsetup::run { 'display_sleep_mins':
key => 'displaysleep',
value => $display_sleep_mins,
when_match => $display_sleep_mins_when_match,
invert_when_match => true
}
}

# Hard Disk Sleep Minutes
if $harddisk_sleep_mins {
if $harddisk_sleep_mins == 0 {
$harddisk_sleep_mins_when_match = 'Never'
}else{
$harddisk_sleep_mins_when_match =
"after ${harddisk_sleep_mins} minutes"
}

systemsetup::run { 'harddisk_sleep_mins':
key => 'harddisksleep',
value => $harddisk_sleep_mins,
when_match => $harddisk_sleep_mins_when_match,
invert_when_match => true
}
}
}
55 changes: 55 additions & 0 deletions manifests/run.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# == Define: systemsetup::run
#
# Define to run set a limited set of OS X System Preferences
#
# == Parameters
#
# [*key*]
# The systemsetup parameter (without the get/set prefix).
#
# [*value*]
# Value to set.
#
# [*when_match*]
# The value will only be set if the output of the get command contains this
# pattern.
#
# [*value*]
# The value will only be set if the output of the get command does not
#  contain the when_match pattern.
#
# [*pre_pipe*]
# Some set operations require basic yes/no input, you can provide a command
# to pipe into the set command (usually something like /usr/bin/yes yes).
#
define systemsetup::run(
$key,
$value,
$when_match,
$invert_when_match = false,
$pre_pipe = ''
) {

if $::osfamily != 'Darwin' {
fail('systemsetup is only supported on Mac OS X')
}

if $pre_pipe {
$_pre_pipe = "${pre_pipe} | "
}else{
$_pre_pipe = $pre_pipe
}

if $invert_when_match {
$_invert_when_match = '-v '
}else{
$_invert_when_match = ''
}

$exec_cmd = "${_pre_pipe}/usr/sbin/systemsetup -set${key} ${value}"

exec { $exec_cmd:
onlyif =>
"/usr/sbin/systemsetup -get${key} | grep ${_invert_when_match}'${when_match}'"
}
}
14 changes: 14 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "heathtechnical-systemsetup",
"version": "0.0.1",
"author": "heathtechnical",
"summary": "Configure Mac OS X via systemsetup command",
"license": "Apache 2.0",
"source": "",
"project_page": null,
"issues_url": null,
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}
]
}

7 changes: 7 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'
describe 'systemsetup' do

context 'with defaults for all parameters' do
it { should contain_class('systemsetup') }
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper'
12 changes: 12 additions & 0 deletions tests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# The baseline for module testing used by Puppet Labs is that each manifest
# should have a corresponding test manifest that declares that class or defined
# type.
#
# Tests are then run by using puppet apply --noop (to check for compilation
# errors and view a log of events) or by fully applying the test in a virtual
# environment (to compare the resulting system state to the desired state).
#
# Learn more about module testing here:
# http://docs.puppetlabs.com/guides/tests_smoke.html
#
include systemsetup

0 comments on commit 2faa1b6

Please sign in to comment.