Method: Jamf::Composer.mk_pkg
- Defined in:
- lib/jamf/composer.rb
.mk_pkg(name, version, root, **opts) ⇒ Pathname
Make a casper-happy .pkg out of a root folder, permissions are assumed to be correct.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/jamf/composer.rb', line 102 def self.mk_pkg(name, version, root, **opts) raise NoSuchItemError, "Missing pkgbuild tool. Please make sure you're running 10.8 or later." unless PKGBUILD.executable? opts[:out_dir] ||= DEFAULT_OUT_DIR opts[:bundle_id_prefix] ||= PKG_BUNDLE_ID_PFX pkg_filename = name.end_with?('.pkg') ? name : name + '.pkg' pkg_id = opts[:pkg_id] pkg_id ||= opts[:bundle_id_prefix] + '.' + name pkg_out = "#{opts[:out_dir]}/#{pkg_filename}" pkg_ownership = opts[:preserve_ownership] ? 'preserve' : 'recommended' if opts[:signing_identity] signing = "--sign '#{opts[:signing_identity]}'" signing << " #{opts[:signing_options]}" if opts[:signing_options] else signing = '' end # if opts[:signing_identity] # first, run 'analyze' to get a 'component plist' in which we can change some settings # for any bundles in the root (bundles like .apps, frameworks, plugins, etc..) # # we edit the settings thus: # BundleOverwriteAction = upgrade, totally replace any version current on disk # BundleIsVersionChecked = false, allow us to install regardless of what version is currently installed # BundleIsRelocatable = false, if there's a version of this in some other location, Do Not move this one there after installation # BundleHasStrictIdentifier = false, don't care if there's something at the install path with a different bundle id. # # In other words, just install the thing! # (see 'man pkgbuild' for more info) # # comp_plist_out = Pathname.new "/tmp/#{PKG_BUNDLE_ID_PFX}-#{pkg_filename}.plist" system "#{PKGBUILD} --analyze --root '#{root}' '#{comp_plist_out}'" comp_plist = JSS.parse_plist comp_plist_out # if the plist is empty, there are no bundles in the pkg if comp_plist[0].nil? comp_plist_arg = '' else # otherwise, edit the bundle dictionaries comp_plist.each do |bndl| bndl.delete 'ChildBundles' if bndl['ChildBundles'] bndl['BundleOverwriteAction'] = 'upgrade' bndl['BundleIsVersionChecked'] = false bndl['BundleIsRelocatable'] = false bndl['BundleHasStrictIdentifier'] = false end # write out the edits comp_plist_out.open('w') { |f| f.write JSS.xml_plist_from(comp_plist) } comp_plist_arg = "--component-plist '#{comp_plist_out}'" end # now build the pkg begin it_built = system "#{PKGBUILD} --identifier '#{pkg_id}' --version '#{version}' --ownership #{pkg_ownership} --install-location / --root '#{root}' #{signing} #{comp_plist_arg} '#{pkg_out}'" raise 'There was an error building the .pkg' unless it_built ensure comp_plist_out.delete if comp_plist_out.exist? end Pathname.new pkg_out end |