We help top organizations stay competitive, by implementing the latest disruptive technologies.

Latest Posts

The 3 Step Process of Bundling Scripts with Pkgbuild for a Payload-less Package Deployment

The 3 Step Process of Bundling Scripts with Pkgbuild for a Payload-less Package Deployment

We all love Terminal and its simplicity, right?  After all, that’s why we’ve written scripts to help us in our enterprise Mac management, just so we can spend more time in Terminal.

Can you sense my sarcasm?

While Terminal is definitely simple, it’s quite probable that it’s not your love unless you’re a programmer or have a programming background. For the rest of us, Terminal is the place we go when we’re Googling how to accomplish some task; because the instructions we find have been written by a Terminal lover — despite the fact there is quite likely a fantastic graphical interface method to use.

Well, today is no different.  Chances are you’re a LANDESK administrator and found this page because you want to figure out how to deploy a script you’ve written and the easiest way to do that is to push a package inside of LANDESK’s Management Suite.

To convert our script into a package, we’re going to use Terminal and Apple’s pkgbuild command line tool.

Should I preface now there are graphical options to accomplish what we’re going to do? See Iceberg.  Apple, however, has deprecated their graphical package builder, PackageMaker, relegating it to the far flung corners of their developer website, making it difficult to even find.

Since there are a number of blogs explaining the granular details around pkgbuild available on the Internet, The Grey Blog being one of them, I’m only going to focus on the basics of creating a payload-less package using the -nopayload option on pkgbuild.

As outlined in the man pages for pkgbuild, the -nopayload option “indicates that the package will contain only scripts, with no payload.”  In other words, we’re not installing bits, we’re simply going to invoke some commands the OS can interpret as prescribed in our scripts bundled inside the package.

Using the example from the previous blog post, we’re going to take the script we wrote to create an XML file that the LANDESK inventory scanner can pick up and deliver to the LANDESK core server.  However, any script will work with the steps below, so manipulate as needed.

Our 3 step process is as follows:

  1. Create the folder structure and build script for pkgbuild
  2. Write your script
  3. Create the package
Step 1 – Create the Folder Structure and Build Script for PkgBuild

Alright, let’s create a folder to house our scripts.  In my example, using Finder, I’m going to create a new folder on my Desktop called SMART HD Detection.  Secondly, I’m going to create a second folder inside my SMART HD Detection folder titled ‘scripts’.

Using TextWrangler or Xcode or some other text editor, I need to create a blank file called postinstall and save it to the scripts folder.  We’ll come back to it later.

Now I need to create a my pkgbuild script.  Again, using TextWrangler or Xcode, create a file  titled package_the_script.sh and save it to the primary folder you created, in my example, the SMART HD Detection.


We will now add the requisite pkgbuild code to create a payload-less inside the package_the_script.sh script.  This script will be quite generic and essentially reusable for all of the packages you need to create now and in the future.

The code is:

[code language=”bash”]


sudo pkgbuild –identifier com.appleintheenterprise.$PKG_ID –nopayload –scripts ./scripts ./$PKG_ID.pkg


Alright, let’s break this down by the line of code.  Hopefully the #!/bin/bash is straight forward for you.

PKG_ID=Gather_SMART_Disk_Status is specifying a variable, PKG_ID, and it will be used as the name of the package we’re going to create.  You’ll want to replace Gather_SMART_Disk_Status with the desired name of your package.

The sudo pkgbuild has several arguments, which will break down individually. Please note, however, there are a number of other arguments you may want to add.  Again, refer to the man pages.

The –identifier is specifying you as the creator, so add in your domain or unique identifier bundled with the package ID.  The OS X Installer recognizes a package as being an upgrade to an already-installed package only if the package identifiers match, so it is advisable to set a meaningful, consistent identifier when you build the package.

The –nopayload option tells pkgbuilder we will be creating a payload-less package.

The –scripts ./scripts identifies the location of our script files that we want bundled up.

Now we can wrap everything up and name it ./$PKG_ID.pkg. Using the name variable allows us to reuse the same command line over and over.

Lastly, I need to save the script and mark it for execution by opening Terminal and browsing to my folder location.  In my instance, it’ll be ~/Desktop/“SMART HD Detection”  Once inside the folder structure, I’ll run the command “sudo chmod a+x package_the_script.sh”.

As can be seen, I didn’t sign this package.  If you need your package to work with Gatekeeper introduced in OS X 10.8, you’re going to need to use the –sign argument.

Step 2 – Write Your Script

Again, using TextWrangler or Xcode, I’m going to open the postinstall I created earlier and write my custom script into it.  My script is going to detect the status of the SMART HD.  However, you can write scripts to install printers, run software updates, reboot the machine, or any other number of tasks.  Just write or copy your script into the postinstall file and save it.

[code language=”bash”]

OUTPUT_FILE=”/Library/Application Support/LANDesk/CustomData/SmartHardDriveStatus.xml”

echo “<?xml version=\”1.0\” encoding=\”UTF-8\”?>” > “$OUTPUT_FILE”

echo “<SMART_info>” >> “$OUTPUT_FILE”

diskutil list | egrep “^/” | while read drive
DRIVE=`basename $drive`
STATUS=`diskutil info $drive | grep SMART | awk ‘{ $1=$2=”” ;print $0 }’`

echo “</SMART_info>” >> “$OUTPUT_FILE”

Step 3 – Create the Package

OK, we’re nearly there.  All I need to do now is to execute the script ‘package_the_script.sh’ and it will run pkgbuild and create the package for us.

To do this, again open Terminal and browse to your folder structure you created.  Again, mine will be ~/Desktop/“SMART HD Detection”

Once there, type “sudo ./package_the_script.sh”.  So doing should create a package inside your folder with the name you provided under the PKG_ID variable.

That’s it, we’re all done.  We can now double click on our package inside of Finder and it will execute.

If you desire to push the script with LANDESK Management Suite to one or more machines, you just will need to zip the pkg file and copy it to your software distribution share.

To build the LANDESK software package that’ll distribute your shiny new package, do the following:

  • From the LANDESK Console, open Tools > Distribution > Distribution Packages
  • Inside the menu tree, highlight My Packages or Public Packages and then select the New Package button on the menubar and select New Macintosh Package
  • Give the package a name, description and point the primary file to the zip file created previously
  • Fill out the Metadata details if desired
  • Save the package

To create a task to deploy your LANDESK package, walk through the steps below:

  • Right click on the package created and select Create Scheduled Task
  • Target the desired machine(s), user(s) or query(ies)
  • Right click on the task and select properties
  • Set the desired Task type under Task Settings
  • If you desire the end user to be able to initiate the task, set the radio button in the Portal Settings to either Recommended or Optional, otherwise set it to Required and it will automatically begin the upgrade during the next maintenance window
  • Change the Reboot Settings on the task to one that forces a reboot
  • Schedule the task

Post A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.