Calling a policy via postinstall in Composer

danshaw
Contributor II

I'm trying to evoke a policy in the post install phase of a payload free package. I created the postinstall script in Composer and entered the line:

#!/bin/sh
## postinstall


jamf policy -event sierra-postinstall


exit 0      ## Success
exit 1      ## Failure

But when I install the package it doesn't run the policy that I have set up with trigger "sierra-postinstall". I can run the policy just fine via terminal.

Is this not possible with Composer? Or am I missing something?

1 ACCEPTED SOLUTION

rtrouton
Release Candidate Programs Tester

@danshaw,

You may be running into an issue with the PATH environment variables not correctly identifying the location of the jamf binary. Try running this:

#!/bin/sh
## postinstall

# This script runs a manual policy trigger to
# allow the policie(s) associated with that
# trigger to be executed.

trigger_name="$4"

CheckBinary (){

# Identify location of jamf binary.

jamf_binary=`/usr/bin/which jamf`

 if [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then
    jamf_binary="/usr/sbin/jamf"
 elif [[ "$jamf_binary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
    jamf_binary="/usr/local/bin/jamf"
 elif [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
    jamf_binary="/usr/local/bin/jamf"
 fi
}

# Run the CheckBinary function to identify the location
# of the jamf binary for the jamf_binary variable.

CheckBinary

$jamf_binary policy -event sierra-postinstall

I have a post on PATH environment variables and how they can affect Casper, available via the link below:

https://derflounder.wordpress.com/2015/09/24/path-environment-variables-and-casper-9-8/

View solution in original post

5 REPLIES 5

sdagley
Esteemed Contributor II

Have you tried sudo jamf policy -event sierra-postinstall?

Another thought, could you trigger the policy via Execute Command from a Files and Processes payload in the policy that's installing the package rather than in the package itself?

danshaw
Contributor II

Yeah no dice on adding SUDO. And while I could use the files and processes payload (maybe I will), ideally I would like to invoke it by a package. Thanks for your response!

rtrouton
Release Candidate Programs Tester

@danshaw,

You may be running into an issue with the PATH environment variables not correctly identifying the location of the jamf binary. Try running this:

#!/bin/sh
## postinstall

# This script runs a manual policy trigger to
# allow the policie(s) associated with that
# trigger to be executed.

trigger_name="$4"

CheckBinary (){

# Identify location of jamf binary.

jamf_binary=`/usr/bin/which jamf`

 if [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then
    jamf_binary="/usr/sbin/jamf"
 elif [[ "$jamf_binary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
    jamf_binary="/usr/local/bin/jamf"
 elif [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
    jamf_binary="/usr/local/bin/jamf"
 fi
}

# Run the CheckBinary function to identify the location
# of the jamf binary for the jamf_binary variable.

CheckBinary

$jamf_binary policy -event sierra-postinstall

I have a post on PATH environment variables and how they can affect Casper, available via the link below:

https://derflounder.wordpress.com/2015/09/24/path-environment-variables-and-casper-9-8/

TajChana
New Contributor II

Removed..

danshaw
Contributor II

Hey @rtrouton that did it! Thank you so much. It just needed to know where the JAMF binary was. Well done. And a quick thank you for your blog and all that you have contributed. It has helped me more than I can count.