facter 1.6.11 → 1.6.12.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (43) hide show
  1. data/CHANGELOG +26 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +28 -0
  4. data/Rakefile +31 -73
  5. data/ext/build_defaults.yaml +20 -0
  6. data/ext/debian/changelog.erb +71 -0
  7. data/ext/debian/compat +1 -0
  8. data/ext/debian/control +14 -0
  9. data/ext/debian/copyright +19 -0
  10. data/ext/debian/docs +2 -0
  11. data/ext/debian/lintian-overrides +0 -0
  12. data/ext/debian/rules +9 -0
  13. data/ext/debian/source/format +1 -0
  14. data/ext/facter-diff +74 -0
  15. data/{conf → ext}/osx/PackageInfo.plist +0 -0
  16. data/{conf → ext}/osx/createpackage.sh +0 -0
  17. data/ext/osx/file_mapping.yaml +27 -0
  18. data/ext/osx/preflight.erb +30 -0
  19. data/ext/osx/prototype.plist.erb +38 -0
  20. data/ext/packaging/README.md +89 -0
  21. data/ext/packaging/tasks/00_utils.rb +214 -0
  22. data/ext/packaging/tasks/10_setupvars.rake +59 -0
  23. data/ext/packaging/tasks/apple.rake +201 -0
  24. data/ext/packaging/tasks/clean.rake +5 -0
  25. data/ext/packaging/tasks/deb.rake +105 -0
  26. data/ext/packaging/tasks/gem.rake +50 -0
  27. data/ext/packaging/tasks/mock.rake +88 -0
  28. data/ext/packaging/tasks/release.rake +18 -0
  29. data/ext/packaging/tasks/rpm.rake +39 -0
  30. data/ext/packaging/tasks/ship.rake +25 -0
  31. data/ext/packaging/tasks/sign.rake +62 -0
  32. data/ext/packaging/tasks/tar.rake +19 -0
  33. data/ext/project_data.yaml +15 -0
  34. data/{conf/redhat/facter.spec → ext/redhat/facter.spec.erb} +37 -19
  35. data/{conf → ext}/solaris/pkginfo +0 -0
  36. data/lib/facter.rb +2 -6
  37. data/lib/facter/facterversion.rb +5 -2
  38. data/lib/facter/util/ec2.rb +4 -3
  39. data/lib/facter/version.rb +13 -0
  40. data/spec/unit/facter_spec.rb +0 -5
  41. data/spec/unit/util/ec2_spec.rb +16 -0
  42. metadata +370 -200
  43. data/conf/osx/preflight +0 -16
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ #
3
+ # Make sure that old facter cruft is removed
4
+ # This also allows us to downgrade facter as
5
+ # it's more likely that installing old versions
6
+ # over new will cause issues.
7
+ #
8
+ # ${3} is the destination volume so that this works correctly
9
+ # when being installed to volumes other than the current OS.
10
+
11
+ <% begin %>
12
+ <% require 'rubygems' %>
13
+ <% rescue LoadError %>
14
+ <% end %>
15
+ <% require 'rake' %>
16
+
17
+ # remove libdir
18
+ <% Dir.chdir("lib") %>
19
+ <% FileList["**/*"].select {|i| File.file?(i)}.each do |file| %>
20
+ /bin/rm -Rf "${3}<%= @apple_libdir %>/<%=file%>"
21
+ <% end %>
22
+ # remove bin files
23
+ <% Dir.chdir("../bin") %>
24
+ <% FileList["**/*"].select {|i| File.file?(i)}.each do |file| %>
25
+ /bin/rm -Rf "${3}<%= @apple_bindir %>/<%=file%>"
26
+ <% end %>
27
+ <% Dir.chdir("..") %>
28
+
29
+ # remove old doc files
30
+ /bin/rm -Rf "${3}<%= @apple_docdir %>/<%=@package_name%>"
@@ -0,0 +1,38 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <pkg-info version="1.0">
4
+ <dict>
5
+ <key>CFBundleIdentifier</key>
6
+ <string><%= @title %></string>
7
+ <key>CFBundleShortVersionString</key>
8
+ <string><%= @version %></string>
9
+ <key>IFMajorVersion</key>
10
+ <integer><%= @package_major_version %></integer>
11
+ <key>IFMinorVersion</key>
12
+ <integer><%= @package_minor_version %></integer>
13
+ <key>IFPkgBuildDate</key>
14
+ <date><%= @build_date %></date>
15
+ <key>IFPkgFlagAllowBackRev</key>
16
+ <false/>
17
+ <key>IFPkgFlagAuthorizationAction</key>
18
+ <string>RootAuthorization</string>
19
+ <key>IFPkgFlagDefaultLocation</key>
20
+ <string>/</string>
21
+ <key>IFPkgFlagFollowLinks</key>
22
+ <true/>
23
+ <key>IFPkgFlagInstallFat</key>
24
+ <false/>
25
+ <key>IFPkgFlagIsRequired</key>
26
+ <false/>
27
+ <key>IFPkgFlagOverwritePermissions</key>
28
+ <false/>
29
+ <key>IFPkgFlagRelocatable</key>
30
+ <false/>
31
+ <key>IFPkgFlagRestartAction</key>
32
+ <string><%= @pm_restart %></string>
33
+ <key>IFPkgFlagRootVolumeOnly</key>
34
+ <true/>
35
+ <key>IFPkgFlagUpdateInstalledLanguages</key>
36
+ <false/>
37
+ </dict>
38
+ </pkg-info>
@@ -0,0 +1,89 @@
1
+ Packaging
2
+
3
+ This is a repository for packaging artifacts for Puppet Labs software.
4
+ The goal is to abstract and automate packaging processes beyond individual
5
+ software projects to a level where this repo can be cloned inside any
6
+ project and used to build Debian and Redhat packages.
7
+
8
+ It expects the following directory structure in the project
9
+ * ext/{debian,redhat,osx}
10
+
11
+ each of which contains templated erb files using the instance variables
12
+ specified in the setupvars task. These include a debian changelog, a
13
+ redhat spec file, and an osx preflight and plist.
14
+
15
+ The top level Rakefile in the project should have the following added:
16
+ ```ruby
17
+ Dir['ext/packaging/tasks/**/*'].sort.each { |t| load t }
18
+ begin
19
+ @build_defaults ||= YAML.load_file('ext/build_defaults.yaml')
20
+ @packaging_url = @build_defaults['packaging_url']
21
+ @packaging_repo = @build_defaults['packaging_repo']
22
+ rescue
23
+ STDERR.puts "Unable to read the packaging repo from ext/build_defaults.yaml"
24
+ end
25
+
26
+
27
+ namespace :package do
28
+ desc "Bootstrap packaging automation, e.g. clone into packaging repo"
29
+ task :bootstrap do
30
+ cd 'ext' do
31
+ %x{git clone #{@packaging_url}}
32
+ end
33
+ end
34
+
35
+ desc "Remove all cloned packaging automation"
36
+ task :implode do
37
+ rm_rf "ext/#{@packaging_repo}"
38
+ end
39
+ end
40
+ ```
41
+
42
+ Also in ext should be two files, build_defaults.yaml and project_data.yaml.
43
+
44
+ This is the sample build_defaults.yaml file from Hiera:
45
+ ```yaml
46
+ ---
47
+ packaging_url: 'git@github.com:puppetlabs/packaging --branch=master'
48
+ packaging_repo: 'packaging'
49
+ default_cow: 'base-squeeze-i386.cow'
50
+ cows: 'base-lucid-amd64.cow base-lucid-i386.cow base-natty-amd64.cow base-natty-i386.cow base-oneiric-amd64.cow base-oneiric-i386.cow base-precise-amd64.cow base-precise-i386.cow base-sid-amd64.cow base-sid-i386.cow base-squeeze-amd64.cow base-squeeze-i386.cow base-testing-amd64.cow base-testing-i386.cow base-wheezy-i386.cow'
51
+ pbuild_conf: '/etc/pbuilderrc'
52
+ packager: 'puppetlabs'
53
+ gpg_name: 'info@puppetlabs.com'
54
+ gpg_key: '4BD6EC30'
55
+ sign_tar: FALSE
56
+ # a space separated list of mock configs
57
+ final_mocks: 'pl-5-i386 pl-5-x86_64 pl-6-i386 pl-6-x86_64 fedora-15-i386 fedora-15-x86_64 fedora-16-i386 fedora-16-x86_64 fedora-17-i386 fedora-17-x86_64'
58
+ rc_mocks: 'pl-5-i386-dev pl-5-x86_64-dev pl-6-i386-dev pl-6-x86_64-dev fedora-15-i386-dev fedora-15-x86_64-dev fedora-16-i386-dev fedora-16-x86_64-dev fedora-17-i386-dev fedora-17-x86_64-dev'
59
+ yum_host: 'burji.puppetlabs.com'
60
+ yum_repo_path: '~/repo/'
61
+ apt_host: 'burji.puppetlabs.com'
62
+ apt_repo_url: 'http://apt.puppetlabs.com'
63
+ apt_repo_path: '/opt/repository/incoming'
64
+ # Whether to present the gem and apple tasks
65
+ build_gem: TRUE
66
+ build_dmg: TRUE
67
+ ```
68
+ This is the sample project_data.yaml file:
69
+ ```yaml
70
+ ---
71
+ project: 'hiera'
72
+ author: 'Puppet Labs'
73
+ email: 'info@puppetlabs.com'
74
+ homepage: 'https://github.com/puppetlabs/hiera'
75
+ summary: 'Light weight hierarchical data store'
76
+ description: 'A pluggable data store for hierarcical data'
77
+ version_file: '/lib/hiera.rb'
78
+ # files and gem_files are space separated lists
79
+ files: '[A-Z]* ext lib bin spec acceptance_tests'
80
+ gem_files: '{bin,lib}/**/* CHANGELOG COPYING README.md LICENSE'
81
+ gem_require_path: 'lib'
82
+ gem_test_files: 'spec/**/*'
83
+ gem_executables: 'hiera'
84
+ gem_default_executables: 'hiera'
85
+ # To add gem dependencies, indent.
86
+ # This is an example only, hiera doesn't really depend on hiera-puppet
87
+ gem_dependencies:
88
+ hiera-puppet: '1.0.0rc'
89
+ ```
@@ -0,0 +1,214 @@
1
+ # Utility methods used by the various rake tasks
2
+
3
+ def check_tool(tool)
4
+ %x{which #{tool}}
5
+ unless $?.success?
6
+ STDERR.puts "#{tool} tool not found...exiting"
7
+ exit 1
8
+ end
9
+ end
10
+
11
+ def find_tool(tool)
12
+ location = %x{which #{tool}}.chomp
13
+ location if $?.success?
14
+ end
15
+
16
+ def check_file(file)
17
+ unless File.exist?(file)
18
+ STDERR.puts "#{file} file not found...exiting"
19
+ exit 2
20
+ end
21
+ end
22
+
23
+ def check_var(varname,var=nil)
24
+ if var.nil?
25
+ STDERR.puts "Requires #{varname} be set...exiting"
26
+ exit 3
27
+ end
28
+ end
29
+
30
+ def check_host(host)
31
+ unless host == %x{hostname}.chomp!
32
+ STDERR.puts "Requires host to be #{host}...exiting"
33
+ exit 5
34
+ end
35
+ end
36
+
37
+ def erb(erbfile, outfile)
38
+ template = File.read(erbfile)
39
+ message = ERB.new(template, nil, "-")
40
+ output = message.result(binding)
41
+ File.open(outfile, 'w') { |f| f.write output }
42
+ puts "Generated: #{outfile}"
43
+ end
44
+
45
+ def cp_pr(src, dest, options={})
46
+ mandatory = {:preserve => true}
47
+ cp_r(src, dest, options.merge(mandatory))
48
+ end
49
+
50
+ def cp_p(src, dest, options={})
51
+ mandatory = {:preserve => true}
52
+ cp(src, dest, options.merge(mandatory))
53
+ end
54
+
55
+ def mv_f(src, dest, options={})
56
+ force = {:force => true}
57
+ mv(src, dest, options.merge(mandatory))
58
+ end
59
+
60
+ def git_co(dist)
61
+ %x{git reset --hard ; git checkout #{dist}}
62
+ unless $?.success?
63
+ STDERR.puts 'Could not checkout #{dist} git branch to build package from...exiting'
64
+ exit 1
65
+ end
66
+ end
67
+
68
+ def get_temp
69
+ temp = `mktemp -d -t tmpXXXXXX`.strip
70
+ end
71
+
72
+ def remote_ssh_cmd target, command
73
+ check_tool('ssh')
74
+ puts "Executing '#{command}' on #{target}"
75
+ %x{ssh #{target} '#{command}'}
76
+ end
77
+
78
+ def rsync_to *args
79
+ check_tool('rsync')
80
+ flags = "-Havxl -O --no-perms --no-owner --no-group"
81
+ source = args[0]
82
+ target = args[1]
83
+ dest = args[2]
84
+ puts "rsyncing #{source} to #{target}"
85
+ %x{rsync #{flags} #{source} #{ENV['USER']}@#{target}:#{dest}}
86
+ end
87
+
88
+ def scp_file_from(host,path,file)
89
+ %x{scp #{ENV['USER']}@#{host}:#{path}/#{file} #{@tempdir}/#{file}}
90
+ end
91
+
92
+ def scp_file_to(host,path,file)
93
+ %x{scp #{@tempdir}/#{file} #{ENV['USER']}@#{host}:#{path}}
94
+ end
95
+
96
+ def timestamp
97
+ Time.now.strftime("%Y-%m-%d %H:%M:%S")
98
+ end
99
+
100
+ def get_dash_version
101
+ if File.exists?('.git')
102
+ %x{git describe}.chomp.split('-')[0..1].join('-').gsub('v','')
103
+ else
104
+ get_pwd_version
105
+ end
106
+ end
107
+
108
+ def get_dot_version
109
+ if File.exists?('.git')
110
+ %x{git describe}.chomp.gsub('-', '.').split('.')[0..3].join('.').gsub('v', '')
111
+ else
112
+ get_pwd_version
113
+ end
114
+ end
115
+
116
+ def get_pwd_version
117
+ %x{pwd}.strip.split('.')[-1]
118
+ end
119
+
120
+ def get_debversion
121
+ (@version.include?("rc") ? @version.sub(/rc[0-9]+/, '0.1\0') : "#{@version}-1") + "#{@packager}#{get_debrelease}"
122
+ end
123
+
124
+ def get_origversion
125
+ @debversion.split('-')[0]
126
+ end
127
+
128
+ def get_rpmversion
129
+ @version.match(/^([0-9.]+)/)[1]
130
+ end
131
+
132
+ def get_version_file_version
133
+ File.open( @version_file ) {|io| io.grep(/VERSION = /)}[0].split()[-1]
134
+ end
135
+
136
+ def get_debrelease
137
+ ENV['RELEASE'] || '1'
138
+ end
139
+
140
+ def get_rpmrelease
141
+ ENV['RELEASE'] ||
142
+ if @version.include?("rc")
143
+ "0.1" + @version.gsub('-', '_').match(/rc[0-9]+.*/)[0]
144
+ else
145
+ "1"
146
+ end
147
+ end
148
+
149
+ def restart_keychain
150
+ kill_keychain
151
+ start_keychain
152
+ end
153
+
154
+ def kill_keychain
155
+ %x{keychain -k mine}
156
+ end
157
+
158
+ def start_keychain
159
+ keychain = %x{/usr/bin/keychain -q --agents gpg --eval #{@gpg_key}}.chomp
160
+ new_env = keychain.match(/(GPG_AGENT_INFO)=([^;]*)/)
161
+ ENV[new_env[1]] = new_env[2]
162
+ end
163
+
164
+ def gpg_sign_file(file)
165
+ gpg ||= find_tool('gpg')
166
+
167
+ if gpg
168
+ sh "#{gpg} --armor --detach-sign -u #{@gpg_key} #{file}"
169
+ else
170
+ STDERR.puts "No gpg available. Cannot sign tarball. Exiting..."
171
+ exit 1
172
+ end
173
+ end
174
+
175
+ def mkdir_pr *args
176
+ args.each do |arg|
177
+ mkdir_p arg
178
+ end
179
+ end
180
+
181
+ def set_cow_envs(cow)
182
+ elements = cow.split('-')
183
+ if elements.size != 3
184
+ STDERR.puts "Expecting a cow name split on hyphens, e.g. 'base-squeeze-i386'"
185
+ exit 1
186
+ else
187
+ dist = elements[1]
188
+ arch = elements[2]
189
+ if dist.nil? or arch.nil?
190
+ STDERR.puts "Couldn't get the arg and dist from cow name. Expecting something like 'base-dist-arch'"
191
+ exit 1
192
+ end
193
+ arch = arch.split('.')[0] if arch.include?('.')
194
+ end
195
+
196
+ ENV['DIST'] = dist
197
+ ENV['ARCH'] = arch
198
+ end
199
+
200
+ def ln(target, name)
201
+ %x{ln -f #{target} #{name}}
202
+ end
203
+
204
+ def git_commit_file(file)
205
+ %x{which git &> /dev/null}
206
+ if $?.success? and File.exist?('.git')
207
+ %x{git commit #{file} -m "Commit changes to #{file}" &> /dev/null}
208
+ end
209
+ end
210
+
211
+ def ship_gem(file)
212
+ %x{gem push #{file}}
213
+ end
214
+
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rubygems/package_task'
3
+ require 'rspec/core/rake_task'
4
+ require 'yaml'
5
+ require 'erb'
6
+
7
+ begin
8
+ @project_specs ||= YAML.load_file('ext/project_data.yaml')
9
+ @name = @project_specs['project']
10
+ @author = @project_specs['author']
11
+ @email = @project_specs['email']
12
+ @homepage = @project_specs['homepage']
13
+ @summary = @project_specs['summary']
14
+ @description = @project_specs['description']
15
+ @files = @project_specs['files']
16
+ @version_file = @project_specs['version_file']
17
+ @gem_files = @project_specs['gem_files']
18
+ @gem_require_path = @project_specs['gem_require_path']
19
+ @gem_test_files = @project_specs['gem_test_files']
20
+ @gem_executables = @project_specs['gem_executables']
21
+ @gem_runtime_dependencies = @project_specs['gem_runtime_dependencies']
22
+ @gem_devel_dependencies = @project_specs['gem_devel_dependencies']
23
+ @gem_rdoc_options = @project_specs['gem_rdoc_options']
24
+ @gem_forge_project = @project_specs['gem_forge_project']
25
+ rescue
26
+ STDERR.puts "There was an error loading the project specifications from the 'ext/project_data.yaml' file."
27
+ exit 1
28
+ end
29
+
30
+ begin
31
+ @pkg_defaults ||= YAML.load_file('ext/build_defaults.yaml')
32
+ @default_cow = ENV['COW'] || @pkg_defaults['default_cow']
33
+ @cows = ENV['COW'] || @pkg_defaults['cows']
34
+ @pbuild_conf = ENV['PBUILDCONF'] || @pkg_defaults['pbuild_conf']
35
+ @packager = ENV['PACKAGER'] || @pkg_defaults['packager']
36
+ @sign_tar = ENV['SIGN_TAR'] || @pkg_defaults['sign_tar']
37
+ @final_mocks = ENV['MOCK'] || @pkg_defaults['final_mocks']
38
+ @rc_mocks = ENV['MOCK'] || @pkg_defaults['rc_mocks']
39
+ @gpg_name = ENV['GPG_NAME'] || @pkg_defaults['gpg_name']
40
+ @gpg_key = ENV['GPG_KEY'] || @pkg_defaults['gpg_key']
41
+ @build_gem = ENV['GEM'] || @pkg_defaults['build_gem']
42
+ @build_dmg = ENV['DMG'] || @pkg_defaults['build_dmg']
43
+ @yum_host = @pkg_defaults['yum_host']
44
+ @yum_repo_path = @pkg_defaults['yum_repo_path']
45
+ @apt_host = @pkg_defaults['apt_host']
46
+ @apt_repo_url = @pkg_defaults['apt_repo_url']
47
+ @apt_repo_path = @pkg_defaults['apt_repo_path']
48
+ rescue
49
+ STDERR.puts "There was an error loading the packaging defaults from the 'ext/build_defaults.yaml' file."
50
+ exit 1
51
+ end
52
+
53
+ @build_root ||= Dir.pwd
54
+ @version ||= get_dash_version
55
+ @gemversion ||= get_dot_version
56
+ @debversion ||= get_debversion
57
+ @origversion ||= get_origversion
58
+ @rpmversion ||= get_rpmversion
59
+ @rpmrelease ||= get_rpmrelease
@@ -0,0 +1,201 @@
1
+ # Title: Rake task to build Apple packages for #{@name}.
2
+ # Author: Gary Larizza
3
+ # Date: 05/18/2012
4
+ # Description: This task will create a DMG-encapsulated package that will
5
+ # install a package on OS X systems. This happens by building
6
+ # a directory tree of files that will then be fed to the
7
+ # packagemaker binary (can be installed by installing the
8
+ # XCode Tools) which will create the .pkg file.
9
+ #
10
+
11
+ # Path to Binaries (Constants)
12
+ TAR = '/usr/bin/tar'
13
+ CP = '/bin/cp'
14
+ INSTALL = '/usr/bin/install'
15
+ DITTO = '/usr/bin/ditto'
16
+ PACKAGEMAKER = '/Developer/usr/bin/packagemaker'
17
+ SED = '/usr/bin/sed'
18
+
19
+ # Setup task to populate all the variables
20
+ task :setup do
21
+ # Read the Apple file-mappings
22
+ begin
23
+ @source_files = YAML.load_file('ext/osx/file_mapping.yaml')
24
+ rescue
25
+ STDERR.puts "Could not load Apple file mappings from 'ext/osx/file_mapping.yaml'"
26
+ exit 1
27
+ end
28
+ @package_name = @name
29
+ @title = "#{@name}-#{@version}"
30
+ @reverse_domain = "com.#{@packager}.#{@package_name}"
31
+ @package_major_version = @version.split('.')[0]
32
+ @package_minor_version = @version.split('.')[1] +
33
+ @version.split('.')[2].split('-')[0].split('rc')[0]
34
+ @pm_restart = 'None'
35
+ @build_date = timestamp
36
+ @apple_bindir = '/usr/bin'
37
+ @apple_sbindir = '/usr/sbin'
38
+ @apple_libdir = '/usr/lib/ruby/site_ruby/1.8'
39
+ @apple_docdir = '/usr/share/doc'
40
+ end
41
+
42
+ # method: make_directory_tree
43
+ # description: This method sets up the directory structure that packagemaker
44
+ # needs to build a package. A prototype.plist file (holding
45
+ # package-specific options) is built from an ERB template located
46
+ # in the ext/osx directory.
47
+ def make_directory_tree
48
+ project_tmp = "#{get_temp}/#{@package_name}"
49
+ @scratch = "#{project_tmp}/#{@title}"
50
+ @working_tree = {
51
+ 'scripts' => "#{@scratch}/scripts",
52
+ 'resources' => "#{@scratch}/resources",
53
+ 'working' => "#{@scratch}/root",
54
+ 'payload' => "#{@scratch}/payload",
55
+ }
56
+ puts "Cleaning Tree: #{project_tmp}"
57
+ rm_rf(project_tmp)
58
+ @working_tree.each do |key,val|
59
+ mkdir_p(val)
60
+ end
61
+
62
+ erb 'ext/osx/preflight.erb', "#{@working_tree["scripts"]}/preflight"
63
+ erb 'ext/osx/prototype.plist.erb', "#{@scratch}/prototype.plist"
64
+
65
+ end
66
+
67
+ # method: build_dmg
68
+ # description: This method builds a package from the directory structure in
69
+ # /tmp/#{@name} and puts it in the
70
+ # /tmp/#{@name}/#{@name}-#{version}/payload directory. A DMG is
71
+ # created, using hdiutil, based on the contents of the
72
+ # /tmp/#{@name}/#{@name}-#{version}/payload directory. The resultant
73
+ # DMG is placed in the pkg/apple directory.
74
+ #
75
+ def build_dmg
76
+ # Local Variables
77
+ dmg_format_code = 'UDZO'
78
+ zlib_level = '9'
79
+ dmg_format_option = "-imagekey zlib-level=#{zlib_level}"
80
+ dmg_format = "#{dmg_format_code} #{dmg_format_option}"
81
+ dmg_file = "#{@title}.dmg"
82
+ package_file = "#{@title}.pkg"
83
+ pm_extra_args = '--verbose --no-recommend --no-relocate'
84
+ package_target_os = '10.5'
85
+
86
+ # Build .pkg file
87
+ system("sudo #{PACKAGEMAKER} --root #{@working_tree['working']} \
88
+ --id #{@reverse_domain} \
89
+ --filter DS_Store \
90
+ --target #{package_target_os} \
91
+ --title #{@title} \
92
+ --info #{@scratch}/prototype.plist \
93
+ --scripts #{@working_tree['scripts']} \
94
+ --resources #{@working_tree['resources']} \
95
+ --version #{@version} \
96
+ #{pm_extra_args} --out #{@working_tree['payload']}/#{package_file}")
97
+
98
+ # Build .dmg file
99
+ system("sudo hdiutil create -volname #{@title} \
100
+ -srcfolder #{@working_tree['payload']} \
101
+ -uid 99 \
102
+ -gid 99 \
103
+ -ov \
104
+ -format #{dmg_format} \
105
+ #{dmg_file}")
106
+
107
+ if File.directory?("#{pwd}/pkg/apple")
108
+ mv("#{pwd}/#{dmg_file}", "#{pwd}/pkg/apple/#{dmg_file}")
109
+ puts "moved: #{dmg_file} has been moved to #{pwd}/pkg/apple/#{dmg_file}"
110
+ else
111
+ mkdir_p("#{pwd}/pkg/apple")
112
+ mv(dmg_file, "#{pwd}/pkg/apple/#{dmg_file}")
113
+ puts "moved: #{dmg_file} has been moved to #{pwd}/pkg/apple/#{dmg_file}"
114
+ end
115
+ end
116
+
117
+ # method: pack_source
118
+ # description: This method copies the #{@name} source into a directory
119
+ # structure in /tmp/#{@name}/#{@name}-#{version}/root mirroring the
120
+ # structure on the target system for which the package will be
121
+ # installed. Anything installed into /tmp/#{@name}/root will be
122
+ # installed as the package's payload.
123
+ #
124
+ def pack_source
125
+ work = "#{@working_tree['working']}"
126
+ source = pwd
127
+
128
+ # Make all necessary directories
129
+ @source_files.each_value do |files|
130
+ files.each_value do |params|
131
+ mkdir_p "#{work}/#{params['path']}"
132
+ end
133
+ end
134
+
135
+ # Install directory contents into place
136
+ unless @source_files['directories'].nil?
137
+ @source_files['directories'].each do |dir, params|
138
+ unless FileList["#{source}/#{dir}/*"].empty?
139
+ cmd = "#{DITTO} #{source}/#{dir}/ #{work}/#{params['path']}"
140
+ puts cmd
141
+ system(cmd)
142
+ end
143
+ end
144
+ end
145
+
146
+ # Setup a preflight script and replace variables in the files with
147
+ # the correct paths.
148
+ chown('root', 'wheel', "#{@working_tree['scripts']}/preflight")
149
+ chmod(0644, "#{@working_tree['scripts']}/preflight")
150
+
151
+ # Do a run through first setting the specified permissions then
152
+ # making sure 755 is set for all directories
153
+ unless @source_files['directories'].nil?
154
+ @source_files['directories'].each do |dir, params|
155
+ owner = params['owner']
156
+ group = params['group']
157
+ perms = params['perms']
158
+ path = params['path']
159
+ chmod_R(Integer(perms), "#{work}/#{path}")
160
+ chown_R(owner, group, "#{work}/#{path}")
161
+ chmod(0755, "#{work}/#{path}")
162
+ Dir["#{work}/#{path}/**/*"].each do |file|
163
+ chmod(0755, file) if File.directory?(file)
164
+ end
165
+ end
166
+ end
167
+
168
+ # Install any files
169
+ unless @source_files['files'].nil?
170
+ @source_files['files'].each do |file, params|
171
+ owner = params['owner']
172
+ group = params['group']
173
+ perms = params['perms']
174
+ dest = params['path']
175
+ # Allow for regexs like [A-Z]*
176
+ FileList[file].each do |file|
177
+ cmd = "#{INSTALL} -o #{owner} -g #{group} -m #{perms} #{source}/#{file} #{work}/#{dest}"
178
+ puts cmd
179
+ system(cmd)
180
+ end
181
+ end
182
+ end
183
+ end
184
+
185
+ if @build_dmg or @build_dmg == 'TRUE' or @build_dmg == 'true'
186
+ namespace :package do
187
+ desc "Task for building an Apple Package"
188
+ task :apple => [:setup] do
189
+ # Test for Root and Packagemaker binary
190
+ raise "Please run rake as root to build Apple Packages" unless Process.uid == 0
191
+ raise "Packagemaker must be installed. Please install XCode Tools" unless \
192
+ File.exists?('/Developer/usr/bin/packagemaker')
193
+
194
+ make_directory_tree
195
+ pack_source
196
+ build_dmg
197
+ chmod_R(0775, "#{pwd}/pkg")
198
+ end
199
+ end
200
+ end
201
+