Interactive Input for Flat Package(s) - Composer

ibro
New Contributor

If you're a Casper Suite customer, this discussion may not be helpful or relevant.

We're currently a Bushel MDM subscriber and we are still imaging our systems with a custom AutoDMG image (that changes monthly), which integrates some customization, such as third-party web browsers, collaboration apps (like Slack) and of course community editions of IDEs, such as IntelliJ IDEA and PyCharm.

We have a script that I developed to help facilitate the installation and configuration of our local development environment. Unfortunately, it requires a general understanding of scripting and the binaries used to make magic happen. Ergo, not all software engineers are created equal.

The only thing that was preventing me from creating a packaged installer of the script was handling interactive user input during the installation process. So, I asked a friend and JAMF Support to see if it was possible to display input dialogs via a postinstall script for a Flat Package created by JAMF Composer 9.81. My friend said that it was possible, but I'd have to test and debug it. JAMF Support, on the other hand, stated that the scripting had to be done by us and that Composer wasn't intended to be used in this fashion; they even suggested using AppleScript - I'd say, try both AppleScript (osascript) and Cocoa Dialog.

So, after half a day of tinkering around with Cocoa Dialog and Composer, I was able to get an interactive user input during the installation process, when the postinstall script was called/executed. The inputbox will appear as soon as the script execution reaches Line 35.

So here's an example, package something up in Composer, say a Desktop Picture and Cocoa Dialog, and then say you want to rename your computer (all three of them) based on an airport's IATA code, the script could look something like this:

#!/bin/bash

#  Get username
   LoggedInUser="`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`"
   if [[ "$LoggedInUser" = "MBSetupUser" || "$LoggedInUser" = "_mbsetupuser" ]]; then
      LoggedInUser=$(who -q | head -1 | cut -d ' ' -f2)
   fi

# Get user's home directory
   HOMEDIR=$(dscl . -read /Users/"$LoggedInUser" NFSHomeDirectory | awk -F':' 'END{gsub(/^[ 	]+/,"",$NF); printf "%s", $NF }')

# Change the user's shortname to all CAPS
   UserInLogged=`echo $LoggedInUser | tr [a-z] [A-Z]`

# Set variable for Cocoa Dialog
   cocoadialog=/path/to/CocoaDialog.app/Contents/MacOS/CocoaDialog

# Copy desktop picture to /Library/Desktop Pictures
   cp /private/var/tmp/starsandspace.png /Library/Desktop Pictures/
   chown root:wheel /Library/Desktop Pictures/starsandspace.png

# Interactive user input for local airport code
   airport=`$cocoadialog inputbox --title "Local Airport Code Required" --informative-text "Please enter the 3-digit code of the closest airport:" --button1 "OK" --float --no-cancel`
# Cleanup output
   InputBox_Output=`echo "${airport}" | awk 'NR>1{print $1}' | sed -e 's,.*(([^<]*)).*,1,g'`;

# Change the inputted text to all CAPS
   iatacode=`echo $InputBox_Output | tr [a-z] [A-Z]`

# Set HostName, LocalHostName and ComputerName via scutil
   scutil --set HostName "US-$iatacode-$UserInLogged"
   scutil --set LocalHostName "US-$iatacode-$UserInLogged"
   scutil --set ComputerName "US-$iatacode-$UserInLogged"

host=$(hostname)

if [ "$host" == "US-$iatacode-$UserInLogged.local" ]; then
   echo "The hostname is $host"
   exit 0
else
   echo "The hostname does not match, script failure."
   exit 1
fi
0 REPLIES 0