Class: Jamf::Package Deprecated
- Includes:
- Categorizable, Creatable, Updatable
- Defined in:
- lib/jamf/api/classic/api_objects/package.rb
Overview
Use JPackage instead.
This class will be removed in a future release.
A Package in the JSS
Also the API provides no access to the package’s file list (index), so indexing must be done separately (usually via Casper Admin)
For accessing packages via the Jamf Pro API, see JPackage which provides access to the other package-related attributes such as manifests and installer file uploads
Constant Summary collapse
- RSRC_BASE =
The base for REST resources of this class
'packages'.freeze
- RSRC_LIST_KEY =
the hash key used for the JSON list output of all objects in the JSS
:packages
- RSRC_OBJECT_KEY =
The hash key used for the JSON object output. It’s also used in various error messages
:package
- DIST_POINT_PKGS_FOLDER =
The pkg storage folder on the distribution point
'Packages'.freeze
- CPU_TYPES =
The possible values for cpu_type (required_processor) in a JSS package
%w[None x86 ppc].freeze
- PRIORITIES =
the possible priorities
(1..20)
- DEFAULT_PRIORITY =
the default priority, since one is needed for making new pkgs
10
- DEFAULT_PROCESSOR =
by default, no processor requirement
'None'.freeze
- DO_NOT_INSTALL =
When we shouldn’t install anything (e.g. switch w/package)
'Do Not Install'.freeze
- DB_TABLE =
The table in the database for this object
'packages'.freeze
- CHECKSUM_HASH_TYPE_MD5 =
The hash_type value in the API for md5
'MD5'.freeze
- CHECKSUM_HASH_TYPE_SHA512 =
The hash_type value in the API for sha512
'SHA_512'.freeze
- CHECKSUM_HASH_TYPES =
Mapping of the hash types to the maching Digest modules See #calculate_checksum
{ CHECKSUM_HASH_TYPE_MD5 => Digest::MD5, CHECKSUM_HASH_TYPE_SHA512 => Digest::SHA512 }.freeze
- DEFAULT_CHECKSUM_HASH_TYPE =
CHECKSUM_HASH_TYPE_SHA512
- OBJECT_HISTORY_OBJECT_TYPE =
the object type for this object in the object history table. See APIObject#add_object_history_entry
90
- CATEGORY_SUBSET =
Where is the Category in the API JSON?
:top
- CATEGORY_DATA_TYPE =
How is the category stored in the API data?
String
Instance Attribute Summary collapse
-
#allow_uninstalled ⇒ Boolean
(also: #removable, #removable?)
Can this item be uninstalled? Some, e.g.
-
#boot_volume_required ⇒ Boolean
(also: #boot, #boot?)
Should this pkg be installed on the boot volume during imaging.
-
#checksum ⇒ String?
The checksum value for the package file on the dist.
-
#checksum_type ⇒ Object
@ @return [Symbol] The checksum hash type used to generate the checksum value, either :md5 or :sha512, defaults to :sha512 if there is no checksum yet.
-
#filename ⇒ String
The filename of the .pkg, .mpkg, or .dmg on the Casper server.
-
#fill_existing_users ⇒ Boolean
(also: #feu, #feu?)
Does this item ‘Fill Existing Users’ when jamf installs it?.
-
#fill_user_template ⇒ Boolean
(also: #fut, #fut?)
Does this pkg also get install in the OS user homedir template.
-
#info ⇒ String
The info field for this pkg - stores d3’s basename & swupdate values.
-
#install_if_reported_available ⇒ Boolean
(also: #if_in_swupdate, #if_in_swupdate?)
Only install this pkg if it’s available in the commandline softwareupdate.
-
#need_to_update ⇒ Boolean
included
from Updatable
readonly
Do we have unsaved changes?.
-
#notes ⇒ String
The notes field for this pkg.
-
#os_requirements ⇒ Array<String>
(also: #oses)
The OS versions this can be installed onto.
-
#priority ⇒ Integer
Priority to use for deploying or uninstalling the package.
-
#reboot_required ⇒ Boolean
(also: #reboot, #reboot?)
Does this item require a reboot after installation?.
-
#receipt ⇒ Pathname
readonly
The local receipt when this pkg is installed.
-
#required_processor ⇒ String
(also: #cpu_type)
Limit installation to these architectures: ‘x86’, ‘ppc’, ‘None’.
-
#send_notification ⇒ Boolean
(also: #notify)
Does this pkg cause a notification to be sent on self-heal?.
-
#switch_with_package ⇒ String
The name of a pkg to install (or “Do Not Install”) when this pkg can’t be installed.
Class Method Summary collapse
-
.all_filenames(api: nil, cnx: Jamf.cnx) ⇒ Array<String>
An array of all dist-point filenames used by all JSS packages.
-
.all_filenames_by(key, api: nil, cnx: Jamf.cnx) ⇒ Hash{Ingeter,String => String}
A Hash of all dist-point filenames used by all JSS packages, keyed by package name or id.
-
.calculate_checksum(filepath, type = DEFAULT_CHECKSUM_HASH_TYPE) ⇒ String
Given a file path, and hash type, generate the checksum for an arbitrary file.
- .fetch_dist_point(dist_point, api: nil, cnx: Jamf.cnx) ⇒ Jamf::DistributionPoint
-
.missing_files(ro_pw, unmount = true, dist_point: nil, api: nil, cnx: Jamf.cnx) ⇒ Array<String>
An array of String filenames for all filenames in any Jamf::Package that don’t exist on DIST_POINT_PKGS_FOLDER.
-
.orphaned_files(ro_pw, unmount = true, dist_point: nil, api: nil, cnx: Jamf.cnx) ⇒ Array<String>
An array of String filenames for all files DIST_POINT_PKGS_FOLDER that aren’t used by a Jamf::Package.
Instance Method Summary collapse
-
#calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) ⇒ String
Caclulate and return the checksum hash for a given local file, or the file on the master dist point if no local file is given.
-
#category=(new_cat) ⇒ void
included
from Categorizable
Change the category of this object.
-
#category_assigned? ⇒ Boolean
(also: #categorized?)
included
from Categorizable
Does this object have a category assigned?.
-
#category_id ⇒ Integer
included
from Categorizable
The id of the category for this object.
-
#category_name ⇒ String
(also: #category)
included
from Categorizable
The name of the category for this object.
-
#category_object ⇒ Jamf::Category
included
from Categorizable
The Jamf::Category instance for this object’s category.
-
#checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) ⇒ Boolean
Is the checksum for this pkg is valid?.
-
#clone(new_name, api: nil, cnx: nil) ⇒ APIObject
included
from Creatable
make a clone of this API object, with a new name.
-
#delete(delete_file: false, rw_pw: nil, unmount: true, dist_point: nil) ⇒ void
Delete this package from the JSS, optionally deleting the master dist point file also.
-
#delete_master_file(rw_pw, unmount = true, dist_point: nil) ⇒ Boolean
Delete the filename from the master distribution point, if it exists.
-
#evaluate_new_category(new_cat) ⇒ Array<String, Integer>
included
from Categorizable
Given a category name or id, return the name and id TODO: use APIObject.exist? and/or APIObject.valid_id.
-
#initialize(**args) ⇒ Package
constructor
A new instance of Package.
-
#install(**args) ⇒ Boolean
Install this package via the jamf binary ‘install’ command from the distribution point for this machine.
-
#installed? ⇒ Boolean
Is this packaged installed on the current machine (via casper)? We just look for the receipt, which is the @filename less any possible .zip extension.
-
#name=(newname) ⇒ void
included
from Updatable
Change the name of this item Remember to #update to push changes to the server.
-
#os_ok?(os = nil) ⇒ Boolean
Is a given OS OK for this package based on its @os_requirements?.
-
#processor_ok?(processor = nil) ⇒ Boolean
Is a given processor OK for this package based on its @required_processor?.
-
#reset_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) ⇒ void
Using either a local file, or the file on the master dist.
-
#type ⇒ Symbol
What type of package is this?.
-
#uninstall(**args) ⇒ Process::Status
Uninstall this pkg via the jamf command.
-
#unset_category ⇒ void
included
from Categorizable
Set the category to nothing.
-
#update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true, dist_point: nil) ⇒ nil
Change the name of a package file on the master distribution point.
-
#upload_master_file(local_file_path, rw_pw, unmount = true, chksum: DEFAULT_CHECKSUM_HASH_TYPE, dist_point: nil) ⇒ void
Upload a locally-readable file to the master distribution point.
Constructor Details
#initialize(**args) ⇒ Package
Returns a new instance of Package.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 307 def initialize(**args) super # now we have pkg_data with something in it, so fill out the instance vars @allow_uninstalled = @init_data[:allow_uninstalled] @boot_volume_required = @init_data[:boot_volume_required] @filename = @init_data[:filename] || @init_data[:name] @fill_existing_users = @init_data[:fill_existing_users] @fill_user_template = @init_data[:fill_user_template] @info = @init_data[:info] @install_if_reported_available = @init_data[:install_if_reported_available] @notes = @init_data[:notes] @os_requirements = @init_data[:os_requirements].split(/\s*,\s*/) if @init_data[:os_requirements] @os_requirements ||= [] @priority = @init_data[:priority] || DEFAULT_PRIORITY @reboot_required = @init_data[:reboot_required] @required_processor = @init_data[:required_processor] || DEFAULT_PROCESSOR @required_processor = nil if @required_processor.to_s.casecmp('none').zero? @send_notification = @init_data[:send_notification] @switch_with_package = @init_data[:switch_with_package] || DO_NOT_INSTALL @checksum = @init_data[:hash_value] # ill be nil if no checksum @checksum_type = @checksum ? @init_data[:hash_type] : DEFAULT_CHECKSUM_HASH_TYPE # the receipt is the filename with any .zip extension removed. @receipt = @filename ? (Jamf::Client::RECEIPTS_FOLDER + @filename.to_s.sub(/.zip$/, '')) : nil end |
Instance Attribute Details
#allow_uninstalled ⇒ Boolean Also known as: removable, removable?
Returns can this item be uninstalled? Some, e.g. OS Updates, can’t.
277 278 279 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 277 def allow_uninstalled @allow_uninstalled end |
#boot_volume_required ⇒ Boolean Also known as: boot, boot?
Returns should this pkg be installed on the boot volume during imaging.
289 290 291 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 289 def boot_volume_required @boot_volume_required end |
#checksum ⇒ String?
Returns the checksum value for the package file on the dist. point, if it’s been calculated.
303 304 305 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 303 def checksum @checksum end |
#checksum_type ⇒ Object
@ @return [Symbol] The checksum hash type used to generate the checksum value,
either :md5 or :sha512, defaults to :sha512 if there is no checksum yet.
299 300 301 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 299 def checksum_type @checksum_type end |
#filename ⇒ String
Returns the filename of the .pkg, .mpkg, or .dmg on the Casper server.
253 254 255 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 253 def filename @filename end |
#fill_existing_users ⇒ Boolean Also known as: feu, feu?
Returns does this item ‘Fill Existing Users’ when jamf installs it?.
259 260 261 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 259 def fill_existing_users @fill_existing_users end |
#fill_user_template ⇒ Boolean Also known as: fut, fut?
Returns does this pkg also get install in the OS user homedir template.
262 263 264 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 262 def fill_user_template @fill_user_template end |
#info ⇒ String
Returns the info field for this pkg - stores d3’s basename & swupdate values.
280 281 282 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 280 def info @info end |
#install_if_reported_available ⇒ Boolean Also known as: if_in_swupdate, if_in_swupdate?
Returns only install this pkg if it’s available in the commandline softwareupdate.
286 287 288 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 286 def install_if_reported_available @install_if_reported_available end |
#need_to_update ⇒ Boolean (readonly) Originally defined in module Updatable
Returns do we have unsaved changes?.
#notes ⇒ String
Returns the notes field for this pkg.
283 284 285 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 283 def notes @notes end |
#os_requirements ⇒ Array<String> Also known as: oses
Returns the OS versions this can be installed onto. For all minor versions, the format is 10.5.x.
268 269 270 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 268 def os_requirements @os_requirements end |
#priority ⇒ Integer
Returns Priority to use for deploying or uninstalling the package.
292 293 294 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 292 def priority @priority end |
#reboot_required ⇒ Boolean Also known as: reboot, reboot?
Returns does this item require a reboot after installation?.
265 266 267 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 265 def reboot_required @reboot_required end |
#receipt ⇒ Pathname (readonly)
Returns the local receipt when this pkg is installed.
256 257 258 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 256 def receipt @receipt end |
#required_processor ⇒ String Also known as: cpu_type
Returns limit installation to these architectures: ‘x86’, ‘ppc’, ‘None’.
271 272 273 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 271 def required_processor @required_processor end |
#send_notification ⇒ Boolean Also known as: notify
Returns does this pkg cause a notification to be sent on self-heal?.
295 296 297 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 295 def send_notification @send_notification end |
#switch_with_package ⇒ String
Returns the name of a pkg to install (or “Do Not Install”) when this pkg can’t be installed.
274 275 276 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 274 def switch_with_package @switch_with_package end |
Class Method Details
.all_filenames(api: nil, cnx: Jamf.cnx) ⇒ Array<String>
An array of all dist-point filenames used by all JSS packages
Slow cuz we have to instantiate every pkg
129 130 131 132 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 129 def self.all_filenames(api: nil, cnx: Jamf.cnx) cnx = api if api all_filenames_by(:id, cnx: cnx).values end |
.all_filenames_by(key, api: nil, cnx: Jamf.cnx) ⇒ Hash{Ingeter,String => String}
A Hash of all dist-point filenames used by all JSS packages, keyed by package name or id
Slow cuz we have to instantiate every pkg
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 146 def self.all_filenames_by(key, api: nil, cnx: Jamf.cnx) cnx = api if api raise ArgumentError, 'key must be :id or :name' unless %i[id name].include? key files_in_use = {} all_ids(:refresh, cnx: cnx).each do |pkg_id| pkg = fetch id: pkg_id, cnx: cnx files_in_use[pkg.send(key)] = pkg.filename end files_in_use end |
.calculate_checksum(filepath, type = DEFAULT_CHECKSUM_HASH_TYPE) ⇒ String
Given a file path, and hash type, generate the checksum for an arbitrary file.
229 230 231 232 233 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 229 def self.calculate_checksum(filepath, type = DEFAULT_CHECKSUM_HASH_TYPE) raise ArgumentError, 'Unknown checksum hash type' unless CHECKSUM_HASH_TYPES.key? type CHECKSUM_HASH_TYPES[type].file(filepath).hexdigest end |
.fetch_dist_point(dist_point, api: nil, cnx: Jamf.cnx) ⇒ Jamf::DistributionPoint
239 240 241 242 243 244 245 246 247 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 239 def self.fetch_dist_point(dist_point, api: nil, cnx: Jamf.cnx) cnx = api if api if dist_point Jamf::DistributionPoint.fetch dist_point, cnx: cnx else Jamf::DistributionPoint.master_distribution_point cnx: cnx end end |
.missing_files(ro_pw, unmount = true, dist_point: nil, api: nil, cnx: Jamf.cnx) ⇒ Array<String>
An array of String filenames for all filenames in any Jamf::Package that don’t exist on DIST_POINT_PKGS_FOLDER
Slow cuz we have to instantiate every pkg
209 210 211 212 213 214 215 216 217 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 209 def self.missing_files(ro_pw, unmount = true, dist_point: nil, api: nil, cnx: Jamf.cnx) cnx = api if api dp = fetch_dist_point(dist_point, cnx: cnx) pkgs_dir = dp.mount(ro_pw, :ro) + DIST_POINT_PKGS_FOLDER files_on_dp = pkgs_dir.children.map { |f| f.basename.to_s } dp.unmount if unmount all_filenames(cnx: cnx) - files_on_dp end |
.orphaned_files(ro_pw, unmount = true, dist_point: nil, api: nil, cnx: Jamf.cnx) ⇒ Array<String>
An array of String filenames for all files DIST_POINT_PKGS_FOLDER that aren’t used by a Jamf::Package
Slow cuz we have to instantiate every pkg
179 180 181 182 183 184 185 186 187 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 179 def self.orphaned_files(ro_pw, unmount = true, dist_point: nil, api: nil, cnx: Jamf.cnx) cnx = api if api dp = fetch_dist_point(dist_point, cnx: cnx) pkgs_dir = dp.mount(ro_pw, :ro) + DIST_POINT_PKGS_FOLDER files_on_dp = pkgs_dir.children.map { |f| f.basename.to_s } dp.unmount if unmount files_on_dp - all_filenames(cnx: cnx) end |
Instance Method Details
#calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) ⇒ String
Caclulate and return the checksum hash for a given local file, or the file on the master dist point if no local file is given.
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 779 def calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) type ||= DEFAULT_CHECKSUM_HASH_TYPE dp = self.class.fetch_dist_point(dist_point, cnx: @cnx) if local_file file_to_calc = local_file else if rw_pw dppw = rw_pw mnt = :rw elsif ro_pw dppw = ro_pw mnt = :ro else raise ArgumentError, 'Either rw_pw: or ro_pw: must be provided' end file_to_calc = dp.mount(dppw, mnt) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}" end new_checksum = self.class.calculate_checksum(file_to_calc, type) dp.unmount if unmount && dp.mounted? new_checksum end |
#category=(new_cat) ⇒ void Originally defined in module Categorizable
This method returns an undefined value.
Change the category of this object. Any of the NON_CATEGORIES values will unset the category
#category_assigned? ⇒ Boolean Also known as: categorized? Originally defined in module Categorizable
Does this object have a category assigned?
#category_id ⇒ Integer Originally defined in module Categorizable
The id of the category for this object.
#category_name ⇒ String Also known as: category Originally defined in module Categorizable
The name of the category for this object. For backward compatibility, this is aliased to just ‘category’
#category_object ⇒ Jamf::Category Originally defined in module Categorizable
The Jamf::Category instance for this object’s category
#checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) ⇒ Boolean
Is the checksum for this pkg is valid?
823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 823 def checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) return false unless @checksum new_checksum = calculate_checksum( type: @checksum_type, local_file: local_file, rw_pw: rw_pw, ro_pw: ro_pw, unmount: unmount, dist_point: dist_point ) new_checksum == @checksum end |
#clone(new_name, api: nil, cnx: nil) ⇒ APIObject Originally defined in module Creatable
make a clone of this API object, with a new name. The class must be creatable
#delete(delete_file: false, rw_pw: nil, unmount: true, dist_point: nil) ⇒ void
This method returns an undefined value.
Delete this package from the JSS, optionally deleting the master dist point file also.
914 915 916 917 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 914 def delete(delete_file: false, rw_pw: nil, unmount: true, dist_point: nil) super() delete_master_file(rw_pw, unmount, dist_point: dist_point) if delete_file end |
#delete_master_file(rw_pw, unmount = true, dist_point: nil) ⇒ Boolean
Delete the filename from the master distribution point, if it exists.
If you’ll be uploading several files you can specify unmount as false, and do it manually when all are finished.
887 888 889 890 891 892 893 894 895 896 897 898 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 887 def delete_master_file(rw_pw, unmount = true, dist_point: nil) dp = self.class.fetch_dist_point(dist_point, cnx: @cnx) file = dp.mount(rw_pw, :rw) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}" if file.exist? file.delete did_it = true else did_it = false end # if exists dp.unmount if unmount did_it end |
#evaluate_new_category(new_cat) ⇒ Array<String, Integer> Originally defined in module Categorizable
Given a category name or id, return the name and id TODO: use APIObject.exist? and/or APIObject.valid_id
#install(**args) ⇒ Boolean
deal with cert-based https authentication in dist points
This code must be run as root to install packages
Install this package via the jamf binary ‘install’ command from the distribution point for this machine. See DistributionPoint.my_distribution_point
The read-only or http passwd for the dist. point must be provided, except for non-authenticated http downloads)
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 959 def install(**args) raise Jamf::UnsupportedError, 'You must have root privileges to install packages' unless JSS.superuser? args[:target] ||= '/' ro_pw = args[:ro_pw] # as of Casper 9.72, with http downloads, the jamf binary requires # the filename must be at the end of the -path url, but before 9.72 # it can't be. # e.g. # in <9.72: jamf install -package foo.pkg -path http://mycasper.myorg.edu/CasperShare/Packages # but # in >=9.72: jamf install -package foo.pkg -path http://mycasper.myorg.edu/CasperShare/Packages/foo.pkg # append_at_vers = JSS.parse_jss_version('9.72')[:version] our_vers = JSS.parse_jss_version(@cnx.server.raw_version)[:version] no_filename_in_url = (our_vers < append_at_vers) # use a provided alternative url for an http download if args[:alt_download_url] # we'll re-add the filename below if needed. src_path = args[:alt_download_url].chomp "/#{@filename}" using_http = true # use our appropriate dist. point for download else mdp = Jamf::DistributionPoint.my_distribution_point cnx: @cnx # how do we access our dist. point? with http? if mdp.http_downloads_enabled && !(args[:no_http]) using_http = true src_path = mdp.http_url if mdp.username_password_required raise Jamf::MissingDataError, 'No password provided for http download' unless ro_pw raise Jamf::InvaldDatatError, 'Incorrect password for http access to distribution point.' unless mdp.check_pw(:http, ro_pw) # insert the name and pw into the uri # reserved_chars = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}]") # we'll escape all the chars that aren't unreserved src_path = src_path.sub(%r{(https?://)(\S)}, "#{Regexp.last_match(1)}#{CGI.escape mdp.http_username.to_s}:#{CGI.escape ro_pw.to_s}@#{Regexp.last_match(2)}") end # or with filesharing? else using_http = false src_path = mdp.mount(ro_pw) end # look at the pkgs folder src_path += "#{DIST_POINT_PKGS_FOLDER}/" end # if args[:alt_download_url] src_path += @filename.to_s if using_http && !no_filename_in_url # are we doing "fill existing users" or "fill user template"? do_feu = args[:feu] ? '-feu' : '' do_fut = args[:fut] ? '-fut' : '' # the install args for jamf command_args = "-package '#{@filename}' -path '#{src_path}' -target '#{args[:target]}' #{do_feu} #{do_fut} -showProgress -verbose" # run it via a client cmd install_out = Jamf::Client.run_jamf :install, command_args, args[:verbose] install_out =~ %r{<exitCode>(\d+)</exitCode>} install_exit = Regexp.last_match(1) ? Regexp.last_match(1).to_i : nil install_exit ||= $CHILD_STATUS.exitstatus mdp.unmount if args.include?(:unmount) && !using_http install_exit.zero? ? true : false end |
#installed? ⇒ Boolean
Is this packaged installed on the current machine (via casper)? We just look for the receipt, which is the @filename less any possible .zip extension.
641 642 643 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 641 def installed? @receipt.file? end |
#name=(newname) ⇒ void Originally defined in module Updatable
This method returns an undefined value.
Change the name of this item Remember to #update to push changes to the server.
#os_ok?(os = nil) ⇒ Boolean
Is a given OS OK for this package based on its @os_requirements?
537 538 539 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 537 def os_ok?(os = nil) JSS.os_ok? @os_requirements, os end |
#processor_ok?(processor = nil) ⇒ Boolean
Is a given processor OK for this package based on its @required_processor?
598 599 600 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 598 def processor_ok?(processor = nil) JSS.processor_ok? @required_processor, processor end |
#reset_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) ⇒ void
This method returns an undefined value.
Using either a local file, or the file on the master dist. point, re-set the checksum for this package. Call #update to save the new one to the JSS.
BE VERY CAREFUL if using a local copy of the file - make sure its identical to the one on the dist point.
This can be used to change the checksum type, and by default will use DEFAULT_CHECKSUM_HASH_TYPE (‘SHA_512’)
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 737 def reset_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true, dist_point: nil) type ||= DEFAULT_CHECKSUM_HASH_TYPE new_checksum = calculate_checksum( type: type, local_file: local_file, rw_pw: rw_pw, ro_pw: ro_pw, unmount: unmount, dist_point: dist_point ) return if @checksum == new_checksum @checksum_type = type @checksum = new_checksum @need_to_update = true end |
#type ⇒ Symbol
What type of package is this?
1075 1076 1077 1078 1079 1080 1081 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 1075 def type case @filename when /\.m?pkg(\.zip)?$/ then :pkg when /\.dmg$/ then :dmg else :unknown end end |
#uninstall(**args) ⇒ Process::Status
This code must be run as root to uninstall packages
Uninstall this pkg via the jamf command.
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 1049 def uninstall(**args) unless removable? raise Jamf::UnsupportedError, \ 'This package cannot be uninstalled. Please use CasperAdmin to index it and allow uninstalls' end raise Jamf::UnsupportedError, 'You must have root privileges to uninstall packages' unless JSS.superuser? args[:target] ||= '/' # are we doing "fill existing users" or "fill user template"? do_feu = args[:feu] ? '-feu' : '' do_fut = args[:fut] ? '-fut' : '' # use jamf binary to uninstall the pkg jamf_opts = "-target '#{args[:target]}' -id '#{@id}' #{do_feu} #{do_fut}" # run it via a client Jamf::Client.run_jamf 'uninstall', jamf_opts, args[:verbose] $CHILD_STATUS end |
#unset_category ⇒ void Originally defined in module Categorizable
This method returns an undefined value.
Set the category to nothing
#update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true, dist_point: nil) ⇒ nil
Change the name of a package file on the master distribution point.
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 853 def update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true, dist_point: nil) raise Jamf::NoSuchItemError, "#{old_file_name} does not exist in the jss." unless @in_jss dp = self.class.fetch_dist_point(dist_point, cnx: @cnx) pkgs_dir = dp.mount(rw_pw, :rw) + DIST_POINT_PKGS_FOLDER.to_s old_file = pkgs_dir + old_file_name raise Jamf::NoSuchItemError, "File not found on the master distribution point at #{DIST_POINT_PKGS_FOLDER}/#{old_file_name}." unless \ old_file.exist? new_file = pkgs_dir + new_file_name # use the extension of the original file. new_file = pkgs_dir + (new_file_name + old_file.extname) if new_file.extname.empty? old_file.rename new_file dp.unmount if unmount nil end |
#upload_master_file(local_file_path, rw_pw, unmount = true, chksum: DEFAULT_CHECKSUM_HASH_TYPE, dist_point: nil) ⇒ void
This method returns an undefined value.
Upload a locally-readable file to the master distribution point. If the file is a directory (like a bundle .pk/.mpkg) it will be zipped before uploading and the @filename will be adjusted accordingly by adding a .zip extension
The name of the local file doesn’t matter, the file on the dist. point will use the @filename (possibly with .zip)
If you’ll be uploading several files you can specify unmount as false, and do it manually when all are finished with Jamf::DistributionPoint.master_distribution_point.unmount
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/jamf/api/classic/api_objects/package.rb', line 670 def upload_master_file(local_file_path, rw_pw, unmount = true, chksum: DEFAULT_CHECKSUM_HASH_TYPE, dist_point: nil) raise Jamf::NoSuchItemError, 'Please create this package in the JSS before uploading it.' unless @in_jss dp = self.class.fetch_dist_point(dist_point, cnx: @cnx) destination = dp.mount(rw_pw, :rw) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}" local_path = Pathname.new local_file_path raise Jamf::NoSuchItemError, "Local file '#{@local_file}' doesn't exist" unless local_path.exist? # should we zip it? if local_path.directory? begin # go to the same dir as the local file wd = Dir.pwd Dir.chdir local_path.parent # the contents of the zip file have to have the same name as the zip file itself (minus the .zip) # so temporarily rename the source local_path_to_upload = local_path.parent + @filename local_path.rename local_path_to_upload unless local_path_to_upload == local_path zipdir = Pathname.new "/tmp/rubyjsstmp-#{Time.new.strftime '%Y%m%d%H%M%S'}-#{$PROCESS_ID}" zipdir.mkpath zipdir.chmod 0o700 zipfile = zipdir + (local_path_to_upload.basename.to_s + '.zip') raise 'There was a problem zipping the pkg bundle' unless system "/usr/bin/zip -qr '#{zipfile}' '#{local_path_to_upload}'" ensure # rename the source to the original name local_path_to_upload.rename local_path if local_path_to_upload.exist? && local_path_to_upload != local_path # go back where we started Dir.chdir wd end # begin # update our info local_path = zipfile destination = destination.to_s + '.zip' @filename = zipfile.basename.to_s @need_to_update = true end # if directory FileUtils.copy_entry local_path, destination if CHECKSUM_HASH_TYPES.keys.include? chksum @checksum_type = chksum @checksum = calculate_checksum local_file: local_path, type: chksum, unmount: false, dist_point: dist_point @need_to_update = true end update if @need_to_update dp.unmount if unmount end |