Class: JSS::Package

Inherits:
APIObject show all
Includes:
Categorizable, Creatable, Updatable
Defined in:
lib/jss/api_object/package.rb,
lib/jss.rb

Overview

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)

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Package

Returns a new instance of Package.



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/jss/api_object/package.rb', line 250

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 ? (JSS::Client::RECEIPTS_FOLDER + @filename.to_s.sub(/.zip$/, '')) : nil
end

Instance Attribute Details

#allow_uninstalledBoolean Also known as: removable, removable?

Returns can this item be uninstalled? Some, e.g. OS Updates, can't.

Returns:

  • (Boolean)

    can this item be uninstalled? Some, e.g. OS Updates, can't



220
221
222
# File 'lib/jss/api_object/package.rb', line 220

def allow_uninstalled
  @allow_uninstalled
end

#boot_volume_requiredBoolean Also known as: boot, boot?

Returns should this pkg be installed on the boot volume during imaging.

Returns:

  • (Boolean)

    should this pkg be installed on the boot volume during imaging



232
233
234
# File 'lib/jss/api_object/package.rb', line 232

def boot_volume_required
  @boot_volume_required
end

#checksumString?

Returns the checksum value for the package file on the dist. point, if it's been calculated.

Returns:

  • (String, nil)

    the checksum value for the package file on the dist. point, if it's been calculated.



246
247
248
# File 'lib/jss/api_object/package.rb', line 246

def checksum
  @checksum
end

#checksum_typeObject

@ @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.


242
243
244
# File 'lib/jss/api_object/package.rb', line 242

def checksum_type
  @checksum_type
end

#filenameString

Returns the filename of the .pkg, .mpkg, or .dmg on the Casper server.

Returns:

  • (String)

    the filename of the .pkg, .mpkg, or .dmg on the Casper server



196
197
198
# File 'lib/jss/api_object/package.rb', line 196

def filename
  @filename
end

#fill_existing_usersBoolean Also known as: feu, feu?

Returns does this item 'Fill Existing Users' when jamf installs it?.

Returns:

  • (Boolean)

    does this item 'Fill Existing Users' when jamf installs it?



202
203
204
# File 'lib/jss/api_object/package.rb', line 202

def fill_existing_users
  @fill_existing_users
end

#fill_user_templateBoolean Also known as: fut, fut?

Returns does this pkg also get install in the OS user homedir template.

Returns:

  • (Boolean)

    does this pkg also get install in the OS user homedir template



205
206
207
# File 'lib/jss/api_object/package.rb', line 205

def fill_user_template
  @fill_user_template
end

#infoString

Returns the info field for this pkg - stores d3's basename & swupdate values.

Returns:

  • (String)

    the info field for this pkg - stores d3's basename & swupdate values



223
224
225
# File 'lib/jss/api_object/package.rb', line 223

def info
  @info
end

#install_if_reported_availableBoolean Also known as: if_in_swupdate, if_in_swupdate?

Returns only install this pkg if it's available in the commandline softwareupdate.

Returns:

  • (Boolean)

    only install this pkg if it's available in the commandline softwareupdate.



229
230
231
# File 'lib/jss/api_object/package.rb', line 229

def install_if_reported_available
  @install_if_reported_available
end

#need_to_updateBoolean (readonly) Originally defined in module Updatable

Returns do we have unsaved changes?.

Returns:

  • (Boolean)

    do we have unsaved changes?

#notesString

Returns the notes field for this pkg.

Returns:

  • (String)

    the notes field for this pkg



226
227
228
# File 'lib/jss/api_object/package.rb', line 226

def notes
  @notes
end

#os_requirementsArray<String> Also known as: oses

Returns the OS versions this can be installed onto. For all minor versions, the format is 10.5.x.

Returns:

  • (Array<String>)

    the OS versions this can be installed onto. For all minor versions, the format is 10.5.x



211
212
213
# File 'lib/jss/api_object/package.rb', line 211

def os_requirements
  @os_requirements
end

#priorityInteger

Returns Priority to use for deploying or uninstalling the package.

Returns:

  • (Integer)

    Priority to use for deploying or uninstalling the package



235
236
237
# File 'lib/jss/api_object/package.rb', line 235

def priority
  @priority
end

#reboot_requiredBoolean Also known as: reboot, reboot?

Returns does this item require a reboot after installation?.

Returns:

  • (Boolean)

    does this item require a reboot after installation?



208
209
210
# File 'lib/jss/api_object/package.rb', line 208

def reboot_required
  @reboot_required
end

#receiptPathname (readonly)

Returns the local receipt when this pkg is installed.

Returns:

  • (Pathname)

    the local receipt when this pkg is installed



199
200
201
# File 'lib/jss/api_object/package.rb', line 199

def receipt
  @receipt
end

#required_processorString Also known as: cpu_type

Returns limit installation to these architectures: 'x86', 'ppc', 'None'.

Returns:

  • (String)

    limit installation to these architectures: 'x86', 'ppc', 'None'



214
215
216
# File 'lib/jss/api_object/package.rb', line 214

def required_processor
  @required_processor
end

#send_notificationBoolean Also known as: notify

Returns does this pkg cause a notification to be sent on self-heal?.

Returns:

  • (Boolean)

    does this pkg cause a notification to be sent on self-heal?



238
239
240
# File 'lib/jss/api_object/package.rb', line 238

def send_notification
  @send_notification
end

#switch_with_packageString

Returns the name of a pkg to install (or “Do Not Install”) when this pkg can't be installed.

Returns:

  • (String)

    the name of a pkg to install (or “Do Not Install”) when this pkg can't be installed



217
218
219
# File 'lib/jss/api_object/package.rb', line 217

def switch_with_package
  @switch_with_package
end

Class Method Details

.all_filenames(api: JSS.api) ⇒ Array<String>

An array of all dist-point filenames used by all JSS packages

Slow cuz we have to instantiate every pkg

Parameters:

Returns:



123
124
125
126
127
# File 'lib/jss/api_object/package.rb', line 123

def self.all_filenames(api: JSS.api)
  pkgs_in_use = []
  all_ids.each { |pkg_id| pkgs_in_use << fetch(id: pkg_id, api: api).filename }
  pkgs_in_use.compact
end

.calculate_checksum(filepath, type = DEFAULT_CHECKSUM_HASH_TYPE) ⇒ String

Given a file path, and hash type, generate the checksum for an arbitrary file.

Parameters:

  • filepath (String, Pathname)

    The file to checksum

  • type (String) (defaults to: DEFAULT_CHECKSUM_HASH_TYPE)

    One of the keys of CHECKSUM_HASH_TYPES, either CHECKSUM_HASH_TYPE_MD5 or CHECKSUM_HASH_TYPE_SHA512

Returns:

  • (String)

    The checksum of the file

Raises:

  • (ArgumentError)


187
188
189
190
# File 'lib/jss/api_object/package.rb', line 187

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

.missing_files(ro_pw, unmount = true, api: JSS.api) ⇒ Array<String>

An array of String filenames for all filenames in any JSS::Package that don't exist on DIST_POINT_PKGS_FOLDER

Slow cuz we have to instantiate every pkg

Parameters:

  • ro_pw (String)

    the password for the readonly account on the master Distribution Point,

  • unmount (Boolean) (defaults to: true)

    whether or not ot unount the distribution point when finished.

  • api (JSS::APIConnection) (defaults to: JSS.api)

    an API connection to use Defaults to the corrently active API. See APIConnection

Returns:



169
170
171
172
173
174
175
# File 'lib/jss/api_object/package.rb', line 169

def self.missing_files(ro_pw, unmount = true, api: JSS.api)
  mdp = JSS::DistributionPoint.master_distribution_point api: api
  pkgs_dir = mdp.mount(ro_pw, :ro) + DIST_POINT_PKGS_FOLDER
  files_on_mdp = pkgs_dir.children.map { |f| f.basename.to_s }
  mdp.unmount if unmount
  all_filenames(api: api) - files_on_mdp
end

.orphaned_files(ro_pw, unmount = true, api: JSS.api) ⇒ Array<String>

An array of String filenames for all files DIST_POINT_PKGS_FOLDER that aren't used by a JSS::Package

Slow cuz we have to instantiate every pkg

Parameters:

  • ro_pw (String)

    the password for the readonly account on the master Distribution Point,

  • unmount (Boolean) (defaults to: true)

    whether or not ot unount the distribution point when finished.

  • api (JSS::APIConnection) (defaults to: JSS.api)

    an API connection to use Defaults to the corrently active API. See APIConnection

Returns:



145
146
147
148
149
150
151
# File 'lib/jss/api_object/package.rb', line 145

def self.orphaned_files(ro_pw, unmount = true, api: JSS.api)
  mdp = JSS::DistributionPoint.master_distribution_point api: api
  pkgs_dir = mdp.mount(ro_pw, :ro) + DIST_POINT_PKGS_FOLDER
  files_on_mdp = pkgs_dir.children.map { |f| f.basename.to_s }
  mdp.unmount if unmount
  files_on_mdp - all_filenames(api: api)
end

Instance Method Details

#calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true) ⇒ 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.

Parameters:

  • type (String) (defaults to: nil)

    The checksum hash type, one of the keys of CHECKSUM_HASH_TYPES

  • local_file (String, Pathname) (defaults to: nil)

    A local copy of the pkg file. BE SURE it's identical to the one on the server. If omitted, the master dist. point will be mounted and the file read from there.

  • rw_pw (String) (defaults to: nil)

    The read-write password for mounting the master dist point. Either this or the ro_pw must be provided if no local_file

  • ro_pw (String) (defaults to: nil)

    The read-onlypassword for mounting the master dist point. Either this or the rw_pw must be provided if no local_file

  • unmount (Boolean) (defaults to: true)

    Unmount the master dist point after using it. Only used if the dist point is mounted. default: true

Returns:

  • (String)

    The calculated checksum



699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/jss/api_object/package.rb', line 699

def calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true )
  type ||= DEFAULT_CHECKSUM_HASH_TYPE
  mdp = JSS::DistributionPoint.master_distribution_point api: @api

  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 = mdp.mount(dppw, mnt) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}"
  end
  new_checksum = self.class.calculate_checksum(file_to_calc, type)
  mdp.unmount if unmount && mdp.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

Parameters:

  • new_cat (Integer, String)

    The new category

Raises:

#category_assigned?Boolean Also known as: categorized? Originally defined in module Categorizable

Does this object have a category assigned?

Returns:

  • (Boolean)

    Does this object have a category assigned?

#category_idInteger Originally defined in module Categorizable

The id of the category for this object.

Returns:

  • (Integer)

    The id of the category for this object.

#category_nameString 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'

Returns:

  • (String)

    The name of the category for this object.

#category_objectJSS::Category Originally defined in module Categorizable

The JSS::Category instance for this object's category

Returns:

  • (JSS::Category)

    The JSS::Category instance for this object's category

#checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true) ⇒ Boolean

Is the checksum for this pkg is valid?

Parameters:

  • local_file (String, Pathname) (defaults to: nil)

    A local copy of the pkg file. BE SURE it's identical to the one on the server. If omitted, the master dist. point will be mounted and the file read from there.

  • rw_pw (String) (defaults to: nil)

    The read-write password for mounting the master dist point. Either this or the ro_pw must be provided if no local_file

  • ro_pw (String) (defaults to: nil)

    The read-onlypassword for mounting the master dist point. Either this or the rw_pw must be provided if no local_file

  • unmount (Boolean) (defaults to: true)

    Unmount the master dist point after using it. Only used if the dist point is mounted. default: true

Returns:

  • (Boolean)

    false if there is no checksum for this pkg, otherwise, does the calculated checksum match the one stored for the pkg?



740
741
742
743
744
745
746
747
748
749
750
# File 'lib/jss/api_object/package.rb', line 740

def checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true)
  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
  )
  new_checksum == @checksum
end

#clone(new_name, api: nil) ⇒ APIObject Originally defined in module Creatable

make a clone of this API object, with a new name. The class must be creatable

Parameters:

  • name (String)

    the name for the new object

  • api (JSS::APIConnection) (defaults to: nil)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (APIObject)

    An uncreated clone of this APIObject with the given name

Raises:

#createInteger Originally defined in module Creatable

Create a new object in the JSS.

Parameters:

  • api (JSS::APIConnection)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (Integer)

    the jss ID of the newly created object

Raises:

#delete(delete_file: false, rw_pw: nil, unmount: true) ⇒ Object

Delete this package from the JSS, optionally deleting the master dist point file also.

Parameters:

  • delete_file (Boolean) (defaults to: false)

    should the master dist point file be deleted?

  • rw_pw (String) (defaults to: nil)

    the password for the read/write account on the master Distribution Point or :prompt, or :stdin# where # is the line of stdin containing the password. See DistributionPoint#mount

  • unmount (Boolean) (defaults to: true)

    whether or not ot unount the distribution point when finished.



819
820
821
822
# File 'lib/jss/api_object/package.rb', line 819

def delete(delete_file: false, rw_pw: nil, unmount: true)
  super()
  delete_master_file(rw_pw, unmount) if delete_file
end

#delete_master_file(rw_pw, unmount = true) ⇒ 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.

Parameters:

  • rw_pw (String)

    the password for the read/write account on the master Distribution Point or :prompt, or :stdin# where # is the line of stdin containing the password. See DistributionPoint#mount

  • unmount (Boolean) (defaults to: true)

    whether or not ot unount the distribution point when finished.

Returns:

  • (Boolean)

    was the file deleted?



796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/jss/api_object/package.rb', line 796

def delete_master_file(rw_pw, unmount = true)
  mdp = JSS::DistributionPoint.master_distribution_point api: @api
  file = mdp.mount(rw_pw, :rw) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}"
  if file.exist?
    file.delete
    did_it = true
  else
    did_it = false
  end # if exists
  mdp.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

Parameters:

  • new_cat (String, Integer)

    The name or id of a possible category

Returns:

  • (Array<String, Integer>)

    The matching name and id, which may be nil.

#install(args = {}) ⇒ Boolean

TODO:

deal with cert-based https authentication in dist points

Note:

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)

Parameters:

  • args (Hash) (defaults to: {})

    the arguments for installation

Options Hash (args):

  • :ro_pw (String)

    the read-only or http password for the distribution point for the local machine (http will be used if available, and may not need a pw)

  • :target (String, Pathname)

    The drive on which to install the package, defaults to '/'

  • :verbose (Boolean)

    be verbose to stdout, defaults to false

  • :feu (Boolean)

    fill existing users, defaults to false

  • :fut (Boolean)

    fill user template, defaults to false

  • :unmount (Boolean)

    unmount the distribution point when finished?(if we mounted it), defaults to false

  • :no_http (Boolean)

    don't use http downloads even if they are enabled for the dist. point.

  • :alt_download_url (String)

    Use this url for an http download, regardless of distribution point settings. This can be used to access Cloud Distribution Points if the fileshare isn't available. The URL should already be ur The package filename will be removed or appended as needed.

Returns:

  • (Boolean)

    did the jamf install succeed?

Raises:



864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
# File 'lib/jss/api_object/package.rb', line 864

def install(args = {})
  raise JSS::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(@api.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}"

  # use our appropriate dist. point for download
  else
    mdp = JSS::DistributionPoint.my_distribution_point api: @api

    # 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 JSS::MissingDataError, 'No password provided for http download' unless ro_pw
        raise JSS::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]

  if using_http
    src_path += @filename.to_s unless no_filename_in_url
  end

  # 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 = JSS::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

  if args.include? :unmount
    mdp.unmount unless using_http
  end

  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.

Returns:

  • (Boolean)


569
570
571
# File 'lib/jss/api_object/package.rb', line 569

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.

Parameters:

  • newname (String)

    the new name

Raises:

#os_ok?(os = nil) ⇒ Boolean

Is a given OS OK for this package based on its @os_requirements?

Parameters:

  • os (String) (defaults to: nil)

    the os to check, defaults to the os of the current machine.

Returns:

  • (Boolean)

    can this pkg be installed with the os given?



472
473
474
# File 'lib/jss/api_object/package.rb', line 472

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?

Parameters:

  • processor (String) (defaults to: nil)

    the processor to check, defaults to the processor of the current machine.

Returns:

  • (Boolean)

    can this pkg be installed with the processor given?



529
530
531
# File 'lib/jss/api_object/package.rb', line 529

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) ⇒ 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')

Parameters:

  • @see

    calculate_checksum



661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
# File 'lib/jss/api_object/package.rb', line 661

def reset_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true)
  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
  )
  return if @checksum == new_checksum

  @checksum_type = type
  @checksum = new_checksum
  @need_to_update = true
end

#typeSymbol

What type of package is this?

Returns:

  • (Symbol)

    :pkg or :dmg or:unknown



981
982
983
984
985
986
987
# File 'lib/jss/api_object/package.rb', line 981

def type
  case @filename
  when /\.m?pkg(\.zip)?$/ then :pkg
  when /\.dmg$/ then :dmg
  else :unknown
  end
end

#uninstall(args = {}) ⇒ Process::Status

Note:

This code must be run as root to uninstall packages

Uninstall this pkg via the jamf command.

Parameters:

  • args (Hash) (defaults to: {})

    the arguments for installation

Options Hash (args):

  • :target (String, Pathname)

    The drive from which to uninstall the package, defaults to '/'

  • :verbose (Boolean)

    be verbose to stdout, defaults to false

  • :feu (Boolean)

    fill existing users, defaults to false

  • :fut (Boolean)

    fill user template, defaults to false

Returns:

  • (Process::Status)

    the result of the 'jamf uninstall' command

Raises:



956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'lib/jss/api_object/package.rb', line 956

def uninstall(args = {})
  unless removable?
    raise JSS::UnsupportedError, \
          'This package cannot be uninstalled. Please use CasperAdmin to index it and allow uninstalls'
  end
  raise JSS::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
  JSS::Client.run_jamf 'uninstall', jamf_opts, args[:verbose]

  $CHILD_STATUS
end

#unset_categoryvoid Originally defined in module Categorizable

This method returns an undefined value.

Set the category to nothing

#updateBoolean Originally defined in module Updatable

Save changes to the JSS

Returns:

  • (Boolean)

    success

Raises:

#update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true) ⇒ nil

Change the name of a package file on the master distribution point.

Parameters:

  • new_file_name (String)
  • old_file_name (default: @filename, String)
  • unmount (Boolean) (defaults to: true)

    whether or not ot unount the distribution point when finished.

  • rw_pw (String, Symbol)

    the password for the read/write account on the master Distribution Point, or :prompt, or :stdin# where # is the line of stdin containing the password See DistributionPoint#mount

Returns:

  • (nil)

Raises:



765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/jss/api_object/package.rb', line 765

def update_master_filename(old_file_name, new_file_name, rw_pw, unmount = true)
  raise JSS::NoSuchItemError, "#{old_file_name} does not exist in the jss." unless @in_jss
  mdp = JSS::DistributionPoint.master_distribution_point api: @api
  pkgs_dir = mdp.mount(rw_pw, :rw) + DIST_POINT_PKGS_FOLDER.to_s
  old_file = pkgs_dir + old_file_name
  raise JSS::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
  mdp.unmount if unmount
  nil
end

#upload_master_file(local_file_path, rw_pw, unmount = true, chksum: DEFAULT_CHECKSUM_HASH_TYPE) ⇒ 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 JSS::DistributionPoint.master_distribution_point.unmount

Parameters:

  • local_file_path (String, Pathname)

    the local path to the file to be uploaded

  • rw_pw (String, Symbol)

    the password for the read/write account on the master Distribution Point, or :prompt, or :stdin# where # is the line of stdin containing the password See DistributionPoint#mount

  • unmount (Boolean) (defaults to: true)

    whether or not ot unount the distribution point when finished.

  • chksum (String) (defaults to: DEFAULT_CHECKSUM_HASH_TYPE)

    the constants CHECKSUM_HASH_TYPE_SHA512 or CHECKSUM_HASH_TYPE_MD5. Anything else means don't calc.

Raises:



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/jss/api_object/package.rb', line 595

def upload_master_file(local_file_path, rw_pw, unmount = true, chksum: DEFAULT_CHECKSUM_HASH_TYPE )
  raise JSS::NoSuchItemError, 'Please create this package in the JSS before uploading it.' unless @in_jss

  mdp = JSS::DistributionPoint.master_distribution_point api: @api
  destination = mdp.mount(rw_pw, :rw) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}"

  local_path = Pathname.new local_file_path
  raise JSS::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
    @need_to_update = true
  end
  update if @need_to_update
  mdp.unmount if unmount
end