Creating the postinstall script

The postinstall script runs the WebsenseEndpoint installer, once both files are guaranteed to be in the same folder.

Create the file using a text editor such as nano. This is recommended over pasting directly into Terminal, to avoid shell quoting issues.
Important: Do not paste multi-line scripts directly into an interactive Terminal or zsh prompt. The zsh history expansion feature can misinterpret characters such as ! (as in the #!/bin/bash shebang line), producing an event not found error. Always write scripts into a file first, using a text editor such as nano, or a here-document with a quoted delimiter (<< 'EOF').

Steps

  1. Open a new file for the postinstall script:
    nano ~/wrapper/scripts/postinstall
  2. Paste in the following script content:
    #!/bin/bash
    STAGE="/private/tmp/websenseendpoint_install"
    
    /usr/sbin/installer -pkg "$STAGE/WebsenseEndpoint.pkg" -target /
    STATUS=$?
    
    rm -rf "$STAGE"
    exit $STATUS
  3. Save and exit the file.
    In nano, press Control+O, then Enter, then Control+X.
  4. Make the script executable:
    chmod +x ~/wrapper/scripts/postinstall

Result

The script works as follows:

  • STAGE points to the folder where both files were copied by the payload. The .pkg and the .json files now sit side by side, exactly as the WebsenseEndpoint installer expects.
  • The script calls the WebsenseEndpoint installer against the staged .pkg using the built-in macOS /usr/sbin/installer command.
  • The exit status of that installer is captured, the staging folder is deleted for cleanliness, and the script exits with the original status code so that Intune or Terminal can tell whether the install genuinely succeeded or failed.