initial
This commit is contained in:
5
lib/.svn/all-wcprops
Normal file
5
lib/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 76
|
||||
/dav/ikwadmin/!svn/ver/3237/linux/puppetmaster/etc_puppet/modules/puppet/lib
|
||||
END
|
||||
5
lib/.svn/dir-prop-base
Normal file
5
lib/.svn/dir-prop-base
Normal file
@@ -0,0 +1,5 @@
|
||||
K 13
|
||||
svn:mergeinfo
|
||||
V 0
|
||||
|
||||
END
|
||||
31
lib/.svn/entries
Normal file
31
lib/.svn/entries
Normal file
@@ -0,0 +1,31 @@
|
||||
10
|
||||
|
||||
dir
|
||||
4547
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin/linux/puppetmaster/etc_puppet/modules/puppet/lib
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin
|
||||
|
||||
|
||||
|
||||
2010-03-16T19:29:02.716218Z
|
||||
3237
|
||||
uwaechte
|
||||
has-props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0e4a7186-e024-0410-a49b-aced43e0d94e
|
||||
|
||||
puppet
|
||||
dir
|
||||
|
||||
5
lib/puppet/.svn/all-wcprops
Normal file
5
lib/puppet/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 83
|
||||
/dav/ikwadmin/!svn/ver/3237/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet
|
||||
END
|
||||
31
lib/puppet/.svn/entries
Normal file
31
lib/puppet/.svn/entries
Normal file
@@ -0,0 +1,31 @@
|
||||
10
|
||||
|
||||
dir
|
||||
4547
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin
|
||||
|
||||
|
||||
|
||||
2010-03-16T19:29:02.716218Z
|
||||
3237
|
||||
uwaechte
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0e4a7186-e024-0410-a49b-aced43e0d94e
|
||||
|
||||
provider
|
||||
dir
|
||||
|
||||
5
lib/puppet/provider/.svn/all-wcprops
Normal file
5
lib/puppet/provider/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 92
|
||||
/dav/ikwadmin/!svn/ver/3237/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider
|
||||
END
|
||||
5
lib/puppet/provider/.svn/dir-prop-base
Normal file
5
lib/puppet/provider/.svn/dir-prop-base
Normal file
@@ -0,0 +1,5 @@
|
||||
K 13
|
||||
svn:mergeinfo
|
||||
V 0
|
||||
|
||||
END
|
||||
31
lib/puppet/provider/.svn/entries
Normal file
31
lib/puppet/provider/.svn/entries
Normal file
@@ -0,0 +1,31 @@
|
||||
10
|
||||
|
||||
dir
|
||||
4547
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin
|
||||
|
||||
|
||||
|
||||
2010-03-16T19:29:02.716218Z
|
||||
3237
|
||||
uwaechte
|
||||
has-props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0e4a7186-e024-0410-a49b-aced43e0d94e
|
||||
|
||||
package
|
||||
dir
|
||||
|
||||
29
lib/puppet/provider/package/.svn/all-wcprops
Normal file
29
lib/puppet/provider/package/.svn/all-wcprops
Normal file
@@ -0,0 +1,29 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 100
|
||||
/dav/ikwadmin/!svn/ver/3237/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider/package
|
||||
END
|
||||
appdmg.rb
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 110
|
||||
/dav/ikwadmin/!svn/ver/3225/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider/package/appdmg.rb
|
||||
END
|
||||
darwinport.rb
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 114
|
||||
/dav/ikwadmin/!svn/ver/3237/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider/package/darwinport.rb
|
||||
END
|
||||
pkgdmg.rb
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 110
|
||||
/dav/ikwadmin/!svn/ver/3225/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider/package/pkgdmg.rb
|
||||
END
|
||||
quicklookdmg.rb
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 116
|
||||
/dav/ikwadmin/!svn/ver/3225/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider/package/quicklookdmg.rb
|
||||
END
|
||||
164
lib/puppet/provider/package/.svn/entries
Normal file
164
lib/puppet/provider/package/.svn/entries
Normal file
@@ -0,0 +1,164 @@
|
||||
10
|
||||
|
||||
dir
|
||||
4547
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin/linux/puppetmaster/etc_puppet/modules/puppet/lib/puppet/provider/package
|
||||
https://uwaechte@svn.ikw.uni-osnabrueck.de/dav/ikwadmin
|
||||
|
||||
|
||||
|
||||
2010-03-16T19:29:02.716218Z
|
||||
3237
|
||||
uwaechte
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0e4a7186-e024-0410-a49b-aced43e0d94e
|
||||
|
||||
appdmg.rb
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2011-07-25T16:18:40.000000Z
|
||||
f269e8c848553074841c3c30c324e925
|
||||
2010-01-09T16:41:25.857914Z
|
||||
3088
|
||||
uwaechte
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
5400
|
||||
|
||||
darwinport.rb
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2011-07-25T16:18:40.000000Z
|
||||
a57b6d1d992da46eaec8bf3d4201a0a4
|
||||
2010-03-16T19:29:02.716218Z
|
||||
3237
|
||||
uwaechte
|
||||
has-props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2171
|
||||
|
||||
pkgdmg.rb
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2011-07-25T16:18:40.000000Z
|
||||
be3953165d2f4ee83733b928d4a3b5e1
|
||||
2009-11-20T14:38:14.959911Z
|
||||
2995
|
||||
uwaechte
|
||||
has-props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
5433
|
||||
|
||||
quicklookdmg.rb
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2011-07-25T16:18:40.000000Z
|
||||
75ba7bb1a662b468163d07d01c0e4644
|
||||
2009-11-20T14:38:14.959911Z
|
||||
2995
|
||||
uwaechte
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
5686
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
K 12
|
||||
svn:keywords
|
||||
V 2
|
||||
Id
|
||||
END
|
||||
@@ -0,0 +1,5 @@
|
||||
K 12
|
||||
svn:keywords
|
||||
V 2
|
||||
Id
|
||||
END
|
||||
155
lib/puppet/provider/package/.svn/text-base/appdmg.rb.svn-base
Normal file
155
lib/puppet/provider/package/.svn/text-base/appdmg.rb.svn-base
Normal file
@@ -0,0 +1,155 @@
|
||||
# Jeff McCune <mccune.jeff@gmail.com>
|
||||
# Changed to app.dmg by: Udo Waechter <udo.waechter@uni-osnabrueck.de>
|
||||
# Mac OS X Package Installer which handles application (.app)
|
||||
# bundles inside an Apple Disk Image.
|
||||
#
|
||||
# Motivation: DMG files provide a true HFS file system
|
||||
# and are easier to manage.
|
||||
#
|
||||
# Note: the 'apple' Provider checks for the package name
|
||||
# in /L/Receipts. Since we possibly install multiple apps's from
|
||||
# a single source, we treat the source .app.dmg file as the package name.
|
||||
# As a result, we store installed .app.dmg file names
|
||||
# in /var/db/.puppet_appdmg_installed_<name>
|
||||
|
||||
require 'puppet/provider/package'
|
||||
require 'yaml'
|
||||
require "fileutils"
|
||||
|
||||
Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Package) do
|
||||
desc "Package management which copies application bundles to a target."
|
||||
$appdmg_target = "/Applications/_IKW"
|
||||
confine :operatingsystem => :darwin
|
||||
|
||||
commands :hdiutil => "/usr/bin/hdiutil"
|
||||
commands :curl => "/usr/bin/curl"
|
||||
commands :rsync => "/usr/bin/rsync"
|
||||
commands :ditto => "/usr/bin/ditto"
|
||||
# JJM We store a cookie for each installed .app.dmg in /var/db
|
||||
def self.instances_by_name
|
||||
Dir.entries("/var/db").find_all { |f|
|
||||
f =~ /^\.puppet_appdmg_installed_/
|
||||
}.collect do |f|
|
||||
name = f.sub(/^\.puppet_appdmg_installed_/, '')
|
||||
yield name if block_given?
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def self.instances
|
||||
instances_by_name.collect do |name|
|
||||
new(:name => name, :provider => :appdmg, :ensure => :installed)
|
||||
end
|
||||
end
|
||||
|
||||
def self.installapp(source, name, orig_source)
|
||||
appname = File.basename(source);
|
||||
if Facter.value(:macosx_productversion_major).to_f < 10.4 #ditto for 10.3 and lower.
|
||||
#remove the .app first, it internal structure might have changed
|
||||
if File.exists?("#{appdpmg_target}/#{appname}")
|
||||
FileUtils.remove_entry_secure("#{$appdmg_target}/#{appname}")
|
||||
end
|
||||
ditto "--rsrc", source, "#{$appdmg_target}/#{appname}"
|
||||
else #rsync deletes files if the source has changed (good for >=10.4)
|
||||
rsync "--delete", "-a","-C", source, "#{$appdmg_target}/"
|
||||
end
|
||||
dbfile = "/var/db/.puppet_appdmg_installed_#{name}.yaml"
|
||||
receipthash = {}
|
||||
receipthash["files"] = []
|
||||
if File.exist?(dbfile)
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
end
|
||||
receipthash["name"] = name
|
||||
receipthash["source"] = orig_source
|
||||
receipthash["files"].include?(appname) or receipthash["files"].push(appname)
|
||||
f = File.open(dbfile,"w")
|
||||
f.print receipthash.to_yaml
|
||||
f.close
|
||||
end
|
||||
|
||||
def self.uninstallappdmg(name)
|
||||
dbfile = "/var/db/.puppet_appdmg_installed_#{name}.yaml"
|
||||
unless File.exist?(dbfile)
|
||||
raise Puppet::Error.new("App DMG Package #{name} not installed.")
|
||||
end
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
receipthash["files"].each do |appname|
|
||||
FileUtils.remove_entry_secure("#{$appdmg_target}/#{appname}")
|
||||
unless $? == 0
|
||||
raise Puppet::Error.new("App DMG could not remove \"#{$appdmg_target}/#{appname}\"")
|
||||
end
|
||||
end
|
||||
File.unlink(dbfile)
|
||||
end
|
||||
|
||||
def self.installappdmg(source, name)
|
||||
unless source =~ /\.dmg$/i
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specificy a source string ending in .dmg")
|
||||
end
|
||||
require 'open-uri'
|
||||
require 'facter/util/plist'
|
||||
cached_source = source
|
||||
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
|
||||
cached_source = "/tmp/#{name}"
|
||||
begin
|
||||
curl "-o", cached_source, "-C", "-", "-k", "-s", "--url", source
|
||||
Puppet.debug "Success: curl transfered [#{name}]"
|
||||
rescue Puppet::ExecutionFailure
|
||||
Puppet.debug "curl did not transfer [#{name}]. Falling back to slower open-uri transfer methods."
|
||||
cached_source = source
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
open(cached_source) do |dmg|
|
||||
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-mountrandom", "/tmp", dmg.path
|
||||
ptable = Plist::parse_xml xml_str
|
||||
# JJM Filter out all mount-paths into a single array, discard the rest.
|
||||
mounts = ptable['system-entities'].collect { |entity|
|
||||
entity['mount-point']
|
||||
}.select { |mountloc|; mountloc }
|
||||
begin
|
||||
mounts.each do |fspath|
|
||||
Dir.entries(fspath).select { |f|
|
||||
f =~ /\.app$/i
|
||||
}.each do |app|
|
||||
installapp("#{fspath}/#{app}", name, source)
|
||||
end
|
||||
end # mounts.each do
|
||||
ensure
|
||||
hdiutil "eject", mounts[0]
|
||||
end # begin
|
||||
end # open() do
|
||||
ensure
|
||||
# JJM Remove the file if open-uri didn't already do so.
|
||||
File.unlink(cached_source) if File.exist?(cached_source)
|
||||
end # begin
|
||||
end # def self.installappdmg
|
||||
|
||||
def query
|
||||
if FileTest.exists?("/var/db/.puppet_appdmg_installed_#{@resource[:name]}.yaml")
|
||||
return {:name => @resource[:name], :ensure => :present}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
source = nil
|
||||
unless source = @resource[:source]
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specify a package source.")
|
||||
end
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specify a package name.")
|
||||
end
|
||||
self.class.installappdmg(source,name)
|
||||
end
|
||||
|
||||
def uninstall
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specify a package name.")
|
||||
end
|
||||
self.class.uninstallappdmg(name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
require 'puppet/provider/package'
|
||||
|
||||
Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Package do
|
||||
desc "Package management using DarwinPorts on OS X."
|
||||
|
||||
confine :operatingsystem => :darwin
|
||||
commands :port => "/opt/local/bin/port"
|
||||
|
||||
def self.eachpkgashash
|
||||
# list out all of the packages
|
||||
open("| #{command(:port)} list installed") { |process|
|
||||
regex = %r{(\S+)\s+@(\S+)\s+(\S+)}
|
||||
fields = [:name, :ensure, :location]
|
||||
hash = {}
|
||||
|
||||
# now turn each returned line into a package object
|
||||
process.each { |line|
|
||||
hash.clear
|
||||
|
||||
if match = regex.match(line)
|
||||
fields.zip(match.captures) { |field,value|
|
||||
hash[field] = value
|
||||
}
|
||||
|
||||
hash.delete :location
|
||||
hash[:provider] = self.name
|
||||
yield hash.dup
|
||||
else
|
||||
raise Puppet::DevError,
|
||||
"Failed to match dpkg line %s" % line
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def self.instances
|
||||
packages = []
|
||||
|
||||
eachpkgashash do |hash|
|
||||
packages << new(hash)
|
||||
end
|
||||
|
||||
return packages
|
||||
end
|
||||
|
||||
def install
|
||||
should = @resource.should(:ensure)
|
||||
|
||||
# Seems like you can always say 'upgrade'
|
||||
output = port "install", @resource[:name]
|
||||
if output =~ /^Error: No port/
|
||||
raise Puppet::ExecutionFailure, "Could not find package %s" % @resource[:name]
|
||||
end
|
||||
end
|
||||
|
||||
def query
|
||||
version = nil
|
||||
self.class.eachpkgashash do |hash|
|
||||
if hash[:name] == @resource[:name]
|
||||
return hash
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
def latest
|
||||
info = port :search, "^#{@resource[:name]}$"
|
||||
|
||||
if $? != 0 or info =~ /^Error/
|
||||
return nil
|
||||
end
|
||||
|
||||
ary = info.split(/\s+/)
|
||||
version = ary[2].sub(/^@/, '')
|
||||
|
||||
return version
|
||||
end
|
||||
|
||||
def uninstall
|
||||
port :uninstall, @resource[:name]
|
||||
end
|
||||
|
||||
def update
|
||||
return install()
|
||||
end
|
||||
end
|
||||
|
||||
132
lib/puppet/provider/package/.svn/text-base/pkgdmg.rb.svn-base
Normal file
132
lib/puppet/provider/package/.svn/text-base/pkgdmg.rb.svn-base
Normal file
@@ -0,0 +1,132 @@
|
||||
#
|
||||
# pkgdmg.rb
|
||||
#
|
||||
# Install Installer.app packages wrapped up inside a DMG image file.
|
||||
#
|
||||
# Copyright (C) 2007 Jeff McCune Jeff McCune <jeff@northstarlabs.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation (version 2 of the License)
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
|
||||
#
|
||||
# Motivation: DMG files provide a true HFS file system
|
||||
# and are easier to manage and .pkg bundles.
|
||||
#
|
||||
# Note: the 'apple' Provider checks for the package name
|
||||
# in /L/Receipts. Since we install multiple pkg's from a single
|
||||
# source, we treat the source .pkg.dmg file as the package name.
|
||||
# As a result, we store installed .pkg.dmg file names
|
||||
# in /var/db/.puppet_pkgdmg_installed_<name>
|
||||
|
||||
require 'puppet/provider/package'
|
||||
|
||||
Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Package do
|
||||
desc "Package management based on Apple's Installer.app and DiskUtility.app. This package works by checking the contents of a DMG image for Apple pkg or mpkg files. Any number of pkg or mpkg files may exist in the root directory of the DMG file system. Sub directories are not checked for packages. See `the wiki docs </trac/puppet/wiki/DmgPackages>` for more detail."
|
||||
|
||||
confine :exists => "/Library/Receipts"
|
||||
commands :installer => "/usr/sbin/installer"
|
||||
commands :hdiutil => "/usr/bin/hdiutil"
|
||||
commands :curl => "/usr/bin/curl"
|
||||
# JJM We store a cookie for each installed .pkg.dmg in /var/db
|
||||
def self.instance_by_name
|
||||
Dir.entries("/var/db").find_all { |f|
|
||||
f =~ /^\.puppet_pkgdmg_installed_/
|
||||
}.collect do |f|
|
||||
name = f.sub(/^\.puppet_pkgdmg_installed_/, '')
|
||||
yield name if block_given?
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def self.instances
|
||||
instance_by_name.collect do |name|
|
||||
new(
|
||||
:name => name,
|
||||
:provider => :pkgdmg,
|
||||
:ensure => :installed
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def self.installpkg(source, name, orig_source)
|
||||
installer "-pkg", source, "-target", "/"
|
||||
# Non-zero exit status will throw an exception.
|
||||
File.open("/var/db/.puppet_pkgdmg_installed_#{name}", "w") do |t|
|
||||
t.print "name: '#{name}'\n"
|
||||
t.print "source: '#{orig_source}'\n"
|
||||
end
|
||||
end
|
||||
|
||||
def self.installpkgdmg(source, name)
|
||||
unless source =~ /\.dmg$/i
|
||||
self.fail "Mac OS X PKG DMG's must specificy a source string ending in .dmg"
|
||||
end
|
||||
require 'open-uri'
|
||||
require 'facter/util/plist'
|
||||
cached_source = source
|
||||
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
|
||||
cached_source = "/tmp/#{name}"
|
||||
begin
|
||||
curl "-o", cached_source, "-C", "-", "-k", "-s", "--url", source
|
||||
Puppet.debug "Success: curl transfered [#{name}]"
|
||||
rescue Puppet::ExecutionFailure
|
||||
Puppet.debug "curl did not transfer [#{name}]. Falling back to slower open-uri transfer methods."
|
||||
cached_source = source
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
open(cached_source) do |dmg|
|
||||
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path
|
||||
# JJM THIS IS A HORRIBLE HACK (Well, actually it's not so bad...)
|
||||
# mounts = xml_str.scan(/<string>(\/tmp.*?)<\/string>/)[0]
|
||||
ptable = Plist::parse_xml xml_str
|
||||
# JJM Filter out all mount-paths into a single array, discard the rest.
|
||||
mounts = ptable['system-entities'].collect { |entity|
|
||||
entity['mount-point']
|
||||
}.select { |mountloc|; mountloc }
|
||||
begin
|
||||
mounts.each do |fspath|
|
||||
Dir.entries(fspath).select { |f|
|
||||
f =~ /\.m{0,1}pkg$/i
|
||||
}.each do |pkg|
|
||||
installpkg("#{fspath}/#{pkg}", name, source)
|
||||
end
|
||||
end # mounts.each do
|
||||
ensure
|
||||
hdiutil "eject", mounts[0]
|
||||
end # begin
|
||||
end # open() do
|
||||
ensure
|
||||
# JJM Remove the file if open-uri didn't already do so.
|
||||
File.unlink(cached_source) if File.exist?(cached_source)
|
||||
end # begin
|
||||
end # def self.installpkgdmg
|
||||
|
||||
def query
|
||||
if FileTest.exists?("/var/db/.puppet_pkgdmg_installed_#{@resource[:name]}")
|
||||
return {:name => @resource[:name], :ensure => :present}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
source = nil
|
||||
unless source = @resource[:source]
|
||||
self.fail "Mac OS X PKG DMG's must specify a package source."
|
||||
end
|
||||
unless name = @resource[:name]
|
||||
self.fail "Mac OS X PKG DMG's must specify a package name."
|
||||
end
|
||||
self.class.installpkgdmg(source,name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
# Udo Waechter <root@zoide.net>
|
||||
# Mac OS X QuickLook plugin provider installes quicklook plugins
|
||||
#
|
||||
# Motivation: DMG files provide a true HFS file system
|
||||
# and are easier to manage.
|
||||
#
|
||||
# Note: the 'apple' Provider checks for the package name
|
||||
# in /L/Receipts. Since we possibly install multiple plugins from
|
||||
# a single source, we treat the source .dmg file as the package name.
|
||||
# As a result, we store installed .dmg file names
|
||||
# in /var/db/.puppet_quicklookdmg_installed_<name>
|
||||
|
||||
require 'puppet/provider/package'
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
|
||||
Puppet::Type.type(:package).provide(:quicklookdmg, :parent => Puppet::Provider::Package) do
|
||||
desc "Package management which copies application bundles to a target."
|
||||
$quicklookdmg_target = "/Library/QuickLook"
|
||||
confine :operatingsystem => :darwin
|
||||
|
||||
commands :hdiutil => "/usr/bin/hdiutil"
|
||||
commands :curl => "/usr/bin/curl"
|
||||
commands :ditto => "/usr/bin/ditto"
|
||||
commands :qlmanage => "/usr/bin/qlmanage"
|
||||
# Save information about installed plugins in /var/db
|
||||
def self.instances_by_name
|
||||
Dir.entries("/var/db").find_all { |f|
|
||||
f =~ /^\.puppet_quicklook_installed_/
|
||||
}.collect do |f|
|
||||
name = f.sub(/^\.puppet_quicklook_installed_/, '')
|
||||
yield name if block_given?
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def self.instances
|
||||
instances_by_name.collect do |name|
|
||||
new(:name => name, :provider => :quicklookdmg, :ensure => :installed)
|
||||
end
|
||||
end
|
||||
|
||||
def self.installapp(source, name, orig_source)
|
||||
appname = File.basename(source);
|
||||
FileUtils.rm_rf "#{$quicklookdmg_target}/#{appname}"
|
||||
ditto "--rsrc", source, "#{$quicklookdmg_target}/#{appname}"
|
||||
dbfile = "/var/db/.puppet_quicklook_installed_#{name}.yaml"
|
||||
receipthash = {}
|
||||
receipthash["files"] = []
|
||||
if File.exist?(dbfile)
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
end
|
||||
receipthash["name"] = name
|
||||
receipthash["source"] = orig_source
|
||||
receipthash["files"].include?(appname) or receipthash["files"].push(appname)
|
||||
f = File.open(dbfile,"w")
|
||||
f.print receipthash.to_yaml
|
||||
f.close
|
||||
# refresh plugins
|
||||
qlmanage "-r"
|
||||
end
|
||||
|
||||
def self.uninstallquicklookdmg(name)
|
||||
dbfile = "/var/db/.puppet_quicklook_installed_#{name}.yaml"
|
||||
unless File.exist?(dbfile)
|
||||
raise Puppet::Error.new("QuickLook DMG Package #{name} not installed.")
|
||||
end
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
receipthash["files"].each do |appname|
|
||||
FileUtils.remove_entry_secure("#{$quicklookdmg_target}/#{appname}")
|
||||
unless $? == 0
|
||||
raise Puppet::Error.new("QuickLook DMG could not remove \"#{$quicklookdmg_target}/#{appname}\"")
|
||||
end
|
||||
end
|
||||
File.unlink(dbfile)
|
||||
qlmanage "-r"
|
||||
end
|
||||
|
||||
def self.installquicklookdmg(source, name)
|
||||
unless source =~ /\.dmg$/i
|
||||
raise Puppet::Error.new("Mac OS X QuickLook DMG's must specificy a source string ending in .dmg")
|
||||
end
|
||||
require 'open-uri'
|
||||
require 'facter/util/plist'
|
||||
cached_source = source
|
||||
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
|
||||
cached_source = "/tmp/#{name}"
|
||||
begin
|
||||
curl "-o", cached_source, "-C", "-", "-k", "-s", "--url", source
|
||||
Puppet.debug "Success: curl transfered [#{name}]"
|
||||
rescue Puppet::ExecutionFailure
|
||||
Puppet.debug "curl did not transfer [#{name}]. Falling back to slower open-uri transfer methods."
|
||||
cached_source = source
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
open(cached_source) do |dmg|
|
||||
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-mountrandom", "/tmp", dmg.path
|
||||
ptable = Plist::parse_xml xml_str
|
||||
# JJM Filter out all mount-paths into a single array, discard the rest.
|
||||
mounts = ptable['system-entities'].collect { |entity|
|
||||
entity['mount-point']
|
||||
}.select { |mountloc|; mountloc }
|
||||
begin
|
||||
mounts.each do |fspath|
|
||||
Dir.entries(fspath).select { |f|
|
||||
f =~ /\.qlgenerator$/i
|
||||
}.each do |app|
|
||||
installapp("#{fspath}/#{app}", name, source)
|
||||
end
|
||||
end # mounts.each do
|
||||
ensure
|
||||
hdiutil "eject", mounts[0]
|
||||
end # begin
|
||||
end # open() do
|
||||
ensure
|
||||
# JJM Remove the file if open-uri didn't already do so.
|
||||
File.unlink(cached_source) if File.exist?(cached_source)
|
||||
end # begin
|
||||
end # def self.installquicklookdmg
|
||||
|
||||
def query
|
||||
if FileTest.exists?("/var/db/.puppet_quicklook_installed_#{@resource[:name]}.yaml")
|
||||
return {:name => @resource[:name], :ensure => :present}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
source = nil
|
||||
unless source = @resource[:source]
|
||||
raise Puppet::Error.new("Mac OS X quicklook DMG's must specify a package source.")
|
||||
end
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X quicklook DMG's must specify a package name.")
|
||||
end
|
||||
self.class.installquicklookdmg(source,name)
|
||||
end
|
||||
|
||||
def uninstall
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X QuickLook DMG's must specify a package name.")
|
||||
end
|
||||
self.class.uninstallquicklookdmg(name)
|
||||
end
|
||||
end
|
||||
|
||||
155
lib/puppet/provider/package/appdmg.rb
Normal file
155
lib/puppet/provider/package/appdmg.rb
Normal file
@@ -0,0 +1,155 @@
|
||||
# Jeff McCune <mccune.jeff@gmail.com>
|
||||
# Changed to app.dmg by: Udo Waechter <udo.waechter@uni-osnabrueck.de>
|
||||
# Mac OS X Package Installer which handles application (.app)
|
||||
# bundles inside an Apple Disk Image.
|
||||
#
|
||||
# Motivation: DMG files provide a true HFS file system
|
||||
# and are easier to manage.
|
||||
#
|
||||
# Note: the 'apple' Provider checks for the package name
|
||||
# in /L/Receipts. Since we possibly install multiple apps's from
|
||||
# a single source, we treat the source .app.dmg file as the package name.
|
||||
# As a result, we store installed .app.dmg file names
|
||||
# in /var/db/.puppet_appdmg_installed_<name>
|
||||
|
||||
require 'puppet/provider/package'
|
||||
require 'yaml'
|
||||
require "fileutils"
|
||||
|
||||
Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Package) do
|
||||
desc "Package management which copies application bundles to a target."
|
||||
$appdmg_target = "/Applications/_IKW"
|
||||
confine :operatingsystem => :darwin
|
||||
|
||||
commands :hdiutil => "/usr/bin/hdiutil"
|
||||
commands :curl => "/usr/bin/curl"
|
||||
commands :rsync => "/usr/bin/rsync"
|
||||
commands :ditto => "/usr/bin/ditto"
|
||||
# JJM We store a cookie for each installed .app.dmg in /var/db
|
||||
def self.instances_by_name
|
||||
Dir.entries("/var/db").find_all { |f|
|
||||
f =~ /^\.puppet_appdmg_installed_/
|
||||
}.collect do |f|
|
||||
name = f.sub(/^\.puppet_appdmg_installed_/, '')
|
||||
yield name if block_given?
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def self.instances
|
||||
instances_by_name.collect do |name|
|
||||
new(:name => name, :provider => :appdmg, :ensure => :installed)
|
||||
end
|
||||
end
|
||||
|
||||
def self.installapp(source, name, orig_source)
|
||||
appname = File.basename(source);
|
||||
if Facter.value(:macosx_productversion_major).to_f < 10.4 #ditto for 10.3 and lower.
|
||||
#remove the .app first, it internal structure might have changed
|
||||
if File.exists?("#{appdpmg_target}/#{appname}")
|
||||
FileUtils.remove_entry_secure("#{$appdmg_target}/#{appname}")
|
||||
end
|
||||
ditto "--rsrc", source, "#{$appdmg_target}/#{appname}"
|
||||
else #rsync deletes files if the source has changed (good for >=10.4)
|
||||
rsync "--delete", "-a","-C", source, "#{$appdmg_target}/"
|
||||
end
|
||||
dbfile = "/var/db/.puppet_appdmg_installed_#{name}.yaml"
|
||||
receipthash = {}
|
||||
receipthash["files"] = []
|
||||
if File.exist?(dbfile)
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
end
|
||||
receipthash["name"] = name
|
||||
receipthash["source"] = orig_source
|
||||
receipthash["files"].include?(appname) or receipthash["files"].push(appname)
|
||||
f = File.open(dbfile,"w")
|
||||
f.print receipthash.to_yaml
|
||||
f.close
|
||||
end
|
||||
|
||||
def self.uninstallappdmg(name)
|
||||
dbfile = "/var/db/.puppet_appdmg_installed_#{name}.yaml"
|
||||
unless File.exist?(dbfile)
|
||||
raise Puppet::Error.new("App DMG Package #{name} not installed.")
|
||||
end
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
receipthash["files"].each do |appname|
|
||||
FileUtils.remove_entry_secure("#{$appdmg_target}/#{appname}")
|
||||
unless $? == 0
|
||||
raise Puppet::Error.new("App DMG could not remove \"#{$appdmg_target}/#{appname}\"")
|
||||
end
|
||||
end
|
||||
File.unlink(dbfile)
|
||||
end
|
||||
|
||||
def self.installappdmg(source, name)
|
||||
unless source =~ /\.dmg$/i
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specificy a source string ending in .dmg")
|
||||
end
|
||||
require 'open-uri'
|
||||
require 'facter/util/plist'
|
||||
cached_source = source
|
||||
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
|
||||
cached_source = "/tmp/#{name}"
|
||||
begin
|
||||
curl "-o", cached_source, "-C", "-", "-k", "-s", "--url", source
|
||||
Puppet.debug "Success: curl transfered [#{name}]"
|
||||
rescue Puppet::ExecutionFailure
|
||||
Puppet.debug "curl did not transfer [#{name}]. Falling back to slower open-uri transfer methods."
|
||||
cached_source = source
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
open(cached_source) do |dmg|
|
||||
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-mountrandom", "/tmp", dmg.path
|
||||
ptable = Plist::parse_xml xml_str
|
||||
# JJM Filter out all mount-paths into a single array, discard the rest.
|
||||
mounts = ptable['system-entities'].collect { |entity|
|
||||
entity['mount-point']
|
||||
}.select { |mountloc|; mountloc }
|
||||
begin
|
||||
mounts.each do |fspath|
|
||||
Dir.entries(fspath).select { |f|
|
||||
f =~ /\.app$/i
|
||||
}.each do |app|
|
||||
installapp("#{fspath}/#{app}", name, source)
|
||||
end
|
||||
end # mounts.each do
|
||||
ensure
|
||||
hdiutil "eject", mounts[0]
|
||||
end # begin
|
||||
end # open() do
|
||||
ensure
|
||||
# JJM Remove the file if open-uri didn't already do so.
|
||||
File.unlink(cached_source) if File.exist?(cached_source)
|
||||
end # begin
|
||||
end # def self.installappdmg
|
||||
|
||||
def query
|
||||
if FileTest.exists?("/var/db/.puppet_appdmg_installed_#{@resource[:name]}.yaml")
|
||||
return {:name => @resource[:name], :ensure => :present}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
source = nil
|
||||
unless source = @resource[:source]
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specify a package source.")
|
||||
end
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specify a package name.")
|
||||
end
|
||||
self.class.installappdmg(source,name)
|
||||
end
|
||||
|
||||
def uninstall
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X app DMG's must specify a package name.")
|
||||
end
|
||||
self.class.uninstallappdmg(name)
|
||||
end
|
||||
end
|
||||
|
||||
88
lib/puppet/provider/package/darwinport.rb
Normal file
88
lib/puppet/provider/package/darwinport.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
require 'puppet/provider/package'
|
||||
|
||||
Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Package do
|
||||
desc "Package management using DarwinPorts on OS X."
|
||||
|
||||
confine :operatingsystem => :darwin
|
||||
commands :port => "/opt/local/bin/port"
|
||||
|
||||
def self.eachpkgashash
|
||||
# list out all of the packages
|
||||
open("| #{command(:port)} list installed") { |process|
|
||||
regex = %r{(\S+)\s+@(\S+)\s+(\S+)}
|
||||
fields = [:name, :ensure, :location]
|
||||
hash = {}
|
||||
|
||||
# now turn each returned line into a package object
|
||||
process.each { |line|
|
||||
hash.clear
|
||||
|
||||
if match = regex.match(line)
|
||||
fields.zip(match.captures) { |field,value|
|
||||
hash[field] = value
|
||||
}
|
||||
|
||||
hash.delete :location
|
||||
hash[:provider] = self.name
|
||||
yield hash.dup
|
||||
else
|
||||
raise Puppet::DevError,
|
||||
"Failed to match dpkg line %s" % line
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def self.instances
|
||||
packages = []
|
||||
|
||||
eachpkgashash do |hash|
|
||||
packages << new(hash)
|
||||
end
|
||||
|
||||
return packages
|
||||
end
|
||||
|
||||
def install
|
||||
should = @resource.should(:ensure)
|
||||
|
||||
# Seems like you can always say 'upgrade'
|
||||
output = port "install", @resource[:name]
|
||||
if output =~ /^Error: No port/
|
||||
raise Puppet::ExecutionFailure, "Could not find package %s" % @resource[:name]
|
||||
end
|
||||
end
|
||||
|
||||
def query
|
||||
version = nil
|
||||
self.class.eachpkgashash do |hash|
|
||||
if hash[:name] == @resource[:name]
|
||||
return hash
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
def latest
|
||||
info = port :search, "^#{@resource[:name]}$"
|
||||
|
||||
if $? != 0 or info =~ /^Error/
|
||||
return nil
|
||||
end
|
||||
|
||||
ary = info.split(/\s+/)
|
||||
version = ary[2].sub(/^@/, '')
|
||||
|
||||
return version
|
||||
end
|
||||
|
||||
def uninstall
|
||||
port :uninstall, @resource[:name]
|
||||
end
|
||||
|
||||
def update
|
||||
return install()
|
||||
end
|
||||
end
|
||||
|
||||
132
lib/puppet/provider/package/pkgdmg.rb
Normal file
132
lib/puppet/provider/package/pkgdmg.rb
Normal file
@@ -0,0 +1,132 @@
|
||||
#
|
||||
# pkgdmg.rb
|
||||
#
|
||||
# Install Installer.app packages wrapped up inside a DMG image file.
|
||||
#
|
||||
# Copyright (C) 2007 Jeff McCune Jeff McCune <jeff@northstarlabs.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation (version 2 of the License)
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
|
||||
#
|
||||
# Motivation: DMG files provide a true HFS file system
|
||||
# and are easier to manage and .pkg bundles.
|
||||
#
|
||||
# Note: the 'apple' Provider checks for the package name
|
||||
# in /L/Receipts. Since we install multiple pkg's from a single
|
||||
# source, we treat the source .pkg.dmg file as the package name.
|
||||
# As a result, we store installed .pkg.dmg file names
|
||||
# in /var/db/.puppet_pkgdmg_installed_<name>
|
||||
|
||||
require 'puppet/provider/package'
|
||||
|
||||
Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Package do
|
||||
desc "Package management based on Apple's Installer.app and DiskUtility.app. This package works by checking the contents of a DMG image for Apple pkg or mpkg files. Any number of pkg or mpkg files may exist in the root directory of the DMG file system. Sub directories are not checked for packages. See `the wiki docs </trac/puppet/wiki/DmgPackages>` for more detail."
|
||||
|
||||
confine :exists => "/Library/Receipts"
|
||||
commands :installer => "/usr/sbin/installer"
|
||||
commands :hdiutil => "/usr/bin/hdiutil"
|
||||
commands :curl => "/usr/bin/curl"
|
||||
# JJM We store a cookie for each installed .pkg.dmg in /var/db
|
||||
def self.instance_by_name
|
||||
Dir.entries("/var/db").find_all { |f|
|
||||
f =~ /^\.puppet_pkgdmg_installed_/
|
||||
}.collect do |f|
|
||||
name = f.sub(/^\.puppet_pkgdmg_installed_/, '')
|
||||
yield name if block_given?
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def self.instances
|
||||
instance_by_name.collect do |name|
|
||||
new(
|
||||
:name => name,
|
||||
:provider => :pkgdmg,
|
||||
:ensure => :installed
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def self.installpkg(source, name, orig_source)
|
||||
installer "-pkg", source, "-target", "/"
|
||||
# Non-zero exit status will throw an exception.
|
||||
File.open("/var/db/.puppet_pkgdmg_installed_#{name}", "w") do |t|
|
||||
t.print "name: '#{name}'\n"
|
||||
t.print "source: '#{orig_source}'\n"
|
||||
end
|
||||
end
|
||||
|
||||
def self.installpkgdmg(source, name)
|
||||
unless source =~ /\.dmg$/i
|
||||
self.fail "Mac OS X PKG DMG's must specificy a source string ending in .dmg"
|
||||
end
|
||||
require 'open-uri'
|
||||
require 'facter/util/plist'
|
||||
cached_source = source
|
||||
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
|
||||
cached_source = "/tmp/#{name}"
|
||||
begin
|
||||
curl "-o", cached_source, "-C", "-", "-k", "-s", "--url", source
|
||||
Puppet.debug "Success: curl transfered [#{name}]"
|
||||
rescue Puppet::ExecutionFailure
|
||||
Puppet.debug "curl did not transfer [#{name}]. Falling back to slower open-uri transfer methods."
|
||||
cached_source = source
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
open(cached_source) do |dmg|
|
||||
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path
|
||||
# JJM THIS IS A HORRIBLE HACK (Well, actually it's not so bad...)
|
||||
# mounts = xml_str.scan(/<string>(\/tmp.*?)<\/string>/)[0]
|
||||
ptable = Plist::parse_xml xml_str
|
||||
# JJM Filter out all mount-paths into a single array, discard the rest.
|
||||
mounts = ptable['system-entities'].collect { |entity|
|
||||
entity['mount-point']
|
||||
}.select { |mountloc|; mountloc }
|
||||
begin
|
||||
mounts.each do |fspath|
|
||||
Dir.entries(fspath).select { |f|
|
||||
f =~ /\.m{0,1}pkg$/i
|
||||
}.each do |pkg|
|
||||
installpkg("#{fspath}/#{pkg}", name, source)
|
||||
end
|
||||
end # mounts.each do
|
||||
ensure
|
||||
hdiutil "eject", mounts[0]
|
||||
end # begin
|
||||
end # open() do
|
||||
ensure
|
||||
# JJM Remove the file if open-uri didn't already do so.
|
||||
File.unlink(cached_source) if File.exist?(cached_source)
|
||||
end # begin
|
||||
end # def self.installpkgdmg
|
||||
|
||||
def query
|
||||
if FileTest.exists?("/var/db/.puppet_pkgdmg_installed_#{@resource[:name]}")
|
||||
return {:name => @resource[:name], :ensure => :present}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
source = nil
|
||||
unless source = @resource[:source]
|
||||
self.fail "Mac OS X PKG DMG's must specify a package source."
|
||||
end
|
||||
unless name = @resource[:name]
|
||||
self.fail "Mac OS X PKG DMG's must specify a package name."
|
||||
end
|
||||
self.class.installpkgdmg(source,name)
|
||||
end
|
||||
end
|
||||
|
||||
149
lib/puppet/provider/package/quicklookdmg.rb
Normal file
149
lib/puppet/provider/package/quicklookdmg.rb
Normal file
@@ -0,0 +1,149 @@
|
||||
# Udo Waechter <root@zoide.net>
|
||||
# Mac OS X QuickLook plugin provider installes quicklook plugins
|
||||
#
|
||||
# Motivation: DMG files provide a true HFS file system
|
||||
# and are easier to manage.
|
||||
#
|
||||
# Note: the 'apple' Provider checks for the package name
|
||||
# in /L/Receipts. Since we possibly install multiple plugins from
|
||||
# a single source, we treat the source .dmg file as the package name.
|
||||
# As a result, we store installed .dmg file names
|
||||
# in /var/db/.puppet_quicklookdmg_installed_<name>
|
||||
|
||||
require 'puppet/provider/package'
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
|
||||
Puppet::Type.type(:package).provide(:quicklookdmg, :parent => Puppet::Provider::Package) do
|
||||
desc "Package management which copies application bundles to a target."
|
||||
$quicklookdmg_target = "/Library/QuickLook"
|
||||
confine :operatingsystem => :darwin
|
||||
|
||||
commands :hdiutil => "/usr/bin/hdiutil"
|
||||
commands :curl => "/usr/bin/curl"
|
||||
commands :ditto => "/usr/bin/ditto"
|
||||
commands :qlmanage => "/usr/bin/qlmanage"
|
||||
# Save information about installed plugins in /var/db
|
||||
def self.instances_by_name
|
||||
Dir.entries("/var/db").find_all { |f|
|
||||
f =~ /^\.puppet_quicklook_installed_/
|
||||
}.collect do |f|
|
||||
name = f.sub(/^\.puppet_quicklook_installed_/, '')
|
||||
yield name if block_given?
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def self.instances
|
||||
instances_by_name.collect do |name|
|
||||
new(:name => name, :provider => :quicklookdmg, :ensure => :installed)
|
||||
end
|
||||
end
|
||||
|
||||
def self.installapp(source, name, orig_source)
|
||||
appname = File.basename(source);
|
||||
FileUtils.rm_rf "#{$quicklookdmg_target}/#{appname}"
|
||||
ditto "--rsrc", source, "#{$quicklookdmg_target}/#{appname}"
|
||||
dbfile = "/var/db/.puppet_quicklook_installed_#{name}.yaml"
|
||||
receipthash = {}
|
||||
receipthash["files"] = []
|
||||
if File.exist?(dbfile)
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
end
|
||||
receipthash["name"] = name
|
||||
receipthash["source"] = orig_source
|
||||
receipthash["files"].include?(appname) or receipthash["files"].push(appname)
|
||||
f = File.open(dbfile,"w")
|
||||
f.print receipthash.to_yaml
|
||||
f.close
|
||||
# refresh plugins
|
||||
qlmanage "-r"
|
||||
end
|
||||
|
||||
def self.uninstallquicklookdmg(name)
|
||||
dbfile = "/var/db/.puppet_quicklook_installed_#{name}.yaml"
|
||||
unless File.exist?(dbfile)
|
||||
raise Puppet::Error.new("QuickLook DMG Package #{name} not installed.")
|
||||
end
|
||||
receipthash = YAML::load_file(dbfile)
|
||||
receipthash["files"].each do |appname|
|
||||
FileUtils.remove_entry_secure("#{$quicklookdmg_target}/#{appname}")
|
||||
unless $? == 0
|
||||
raise Puppet::Error.new("QuickLook DMG could not remove \"#{$quicklookdmg_target}/#{appname}\"")
|
||||
end
|
||||
end
|
||||
File.unlink(dbfile)
|
||||
qlmanage "-r"
|
||||
end
|
||||
|
||||
def self.installquicklookdmg(source, name)
|
||||
unless source =~ /\.dmg$/i
|
||||
raise Puppet::Error.new("Mac OS X QuickLook DMG's must specificy a source string ending in .dmg")
|
||||
end
|
||||
require 'open-uri'
|
||||
require 'facter/util/plist'
|
||||
cached_source = source
|
||||
if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
|
||||
cached_source = "/tmp/#{name}"
|
||||
begin
|
||||
curl "-o", cached_source, "-C", "-", "-k", "-s", "--url", source
|
||||
Puppet.debug "Success: curl transfered [#{name}]"
|
||||
rescue Puppet::ExecutionFailure
|
||||
Puppet.debug "curl did not transfer [#{name}]. Falling back to slower open-uri transfer methods."
|
||||
cached_source = source
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
open(cached_source) do |dmg|
|
||||
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-mountrandom", "/tmp", dmg.path
|
||||
ptable = Plist::parse_xml xml_str
|
||||
# JJM Filter out all mount-paths into a single array, discard the rest.
|
||||
mounts = ptable['system-entities'].collect { |entity|
|
||||
entity['mount-point']
|
||||
}.select { |mountloc|; mountloc }
|
||||
begin
|
||||
mounts.each do |fspath|
|
||||
Dir.entries(fspath).select { |f|
|
||||
f =~ /\.qlgenerator$/i
|
||||
}.each do |app|
|
||||
installapp("#{fspath}/#{app}", name, source)
|
||||
end
|
||||
end # mounts.each do
|
||||
ensure
|
||||
hdiutil "eject", mounts[0]
|
||||
end # begin
|
||||
end # open() do
|
||||
ensure
|
||||
# JJM Remove the file if open-uri didn't already do so.
|
||||
File.unlink(cached_source) if File.exist?(cached_source)
|
||||
end # begin
|
||||
end # def self.installquicklookdmg
|
||||
|
||||
def query
|
||||
if FileTest.exists?("/var/db/.puppet_quicklook_installed_#{@resource[:name]}.yaml")
|
||||
return {:name => @resource[:name], :ensure => :present}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
source = nil
|
||||
unless source = @resource[:source]
|
||||
raise Puppet::Error.new("Mac OS X quicklook DMG's must specify a package source.")
|
||||
end
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X quicklook DMG's must specify a package name.")
|
||||
end
|
||||
self.class.installquicklookdmg(source,name)
|
||||
end
|
||||
|
||||
def uninstall
|
||||
unless name = @resource[:name]
|
||||
raise Puppet::Error.new("Mac OS X QuickLook DMG's must specify a package name.")
|
||||
end
|
||||
self.class.uninstallquicklookdmg(name)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user