Merge pull request #641 from scriptingosx/swiftdialog

swiftDialog Integration
This commit is contained in:
Armin Briegel
2022-08-12 16:35:40 +02:00
committed by GitHub
10 changed files with 713 additions and 10 deletions

View File

@@ -0,0 +1,69 @@
#!/bin/zsh
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# MARK: Arguments/Parameters
# Parameter 4: path to the swiftDialog command file
dialog_command_file=${4:-"/var/tmp/dialog.log"}
# Parameter 5: message displayed over the progress bar
message=${5:-"Self Service Progress"}
# Parameter 6: path or URL to an icon
icon=${6:-"/System/Applications/App Store.app/Contents/Resources/AppIcon.icns"}
# see Dan Snelson's advice on how to get a URL to an icon in Self Service
# https://rumble.com/v119x6y-harvesting-self-service-icons.html
# MARK: Constants
dialogApp="/Library/Application Support/Dialog/Dialog.app"
# MARK: Functions
dialogUpdate() {
# $1: dialog command
local dcommand="$1"
if [[ -n $dialog_command_file ]]; then
echo "$dcommand" >> "$dialog_command_file"
echo "Dialog: $dcommand"
fi
}
# MARK: sanity checks
# check minimal macOS requirement
if [[ $(sw_vers -buildVersion ) < "20A" ]]; then
echo "This script requires at least macOS 11 Big Sur."
exit 98
fi
# check we are running as root
if [[ $DEBUG -eq 0 && $(id -u) -ne 0 ]]; then
echo "This script should be run as root"
exit 97
fi
# check for Swift Dialog
if [[ ! -d $dialogApp ]]; then
echo "Cannot find dialog at $dialogApp"
exit 95
fi
# MARK: Configure and display swiftDialog
# display first screen
open -a "$dialogApp" --args \
--title none \
--icon "$icon" \
--message "$message" \
--mini \
--progress 100 \
--position bottomright \
--movable \
--commandfile "$dialog_command_file"
# give everything a moment to catch up
sleep 0.1

48
MDM/Jamf/ReadMe.md Normal file
View File

@@ -0,0 +1,48 @@
# Display Installomator Progress with SwiftDialog in Jamf
Installomator 10 has functionality to communicate with [Bart Reardon's swiftDialog](https://github.com/bartreardon/swiftDialog). When you set the `DIALOG_CMD_FILE` variable Installomator will write progress for downloads and installation (with pkgs) to the command file which allows swiftDialog to display the progress.
However, you have to launch and setup swiftDialog to display a window with a progress bar before Installomator launches and also make sure swiftDialog quits after Installomator has run. This may seem complex at first but allows to configure swiftDialog just for your case without needing to modify the Installomator script.
Here are some example script that would run before and after Installomator to display a swiftDialog window and quit the process after. Since Jamf Pro executes scripts in alphanumerical order, the names are chosen accordingly, to ensure proper order.
## Setup in Jamf Pro
To show Installomator progress with swiftDialog from a Jamf Policy, you require three scripts:
- `00_Prepare_SwiftDialog.sh`: Configures and displays the swiftDialog window
- `Installomator.sh`: (v10 or higher)
- `zz_Quit_SwiftDialog.sh`: quits swiftDialog
Add these three scripts to your Jamf Pro and create a policy with these three scripts. The names are chosen that the script appear in the correct order. If you rename the scripts in Jamf Pro, this may disrupt the order and the workflow will not work anymore. The "Priority" of the scripts in the policy should all be the same value.
The different scripts require a set of parameters. We will use the `googlechromepkg` label as an example.
`00_Prepare_SwiftDialog.sh`
Parameter 4: `/var/tmp/dialog` (Path to the swiftDialog command file)
Parameter 5: `Installing Google Chrome...` (text shown in the swiftDialog window above the progress bar)
Parameter 6: Path to or URL for an icon in swiftDialog. This can be a path on the client or a URL. See Dan Snelson's advice on how to get icon URLs for Self Service icons: https://rumble.com/v119x6y-harvesting-self-service-icons.html
`Installomator.sh`
Parameter 4: `googlechromepkg` (the label to install)
Parameter 5: `DIALOG_CMD_FILE=\var\log\dialog.log` (the swiftDialog command file, this has to be the same value as parameter 4 in the previous script)
Parameter 6: `NOTIFY=silent` (disable Installomator notifications, optional)
You can add more configurations to the Installomator script when needed.
`zz_Quit_SwiftDialog`
Parameter 4: `/var/log/dialog.log` (the swiftDialog command file, this has to be the same value as parameter 4 in the first script)
Then setup the remainder of the Jamf Policy to your needs. This works best with Self Service policies.
When you run the policy, the first script will configure and display swiftDialog. Installomator.sh will download and install the app while writing the proper update commands to the file set in `DIALOG_CMD_FILE`. The final script will quit swiftDialog.
![](SelfServiceProgress.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 KiB

57
MDM/Jamf/zz_Quit_SwiftDialog.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/zsh
# MARK: Arguments/Parameters
# Parameter 4: path to the swiftDialog command file
dialog_command_file=${4:-"/var/tmp/dialog.log"}
# MARK: Constants
dialogApp="/Library/Application Support/Dialog/Dialog.app"
dialogUpdate() {
# $1: dialog command
local dcommand="$1"
if [[ -n $dialog_command_file ]]; then
echo "$dcommand" >> "$dialog_command_file"
echo "Dialog: $dcommand"
fi
}
# check minimal macOS requirement
if [[ $(sw_vers -buildVersion ) < "20A" ]]; then
echo "This script requires at least macOS 11 Big Sur."
exit 98
fi
# check we are running as root
if [[ $DEBUG -eq 0 && $(id -u) -ne 0 ]]; then
echo "This script should be run as root"
exit 97
fi
# check for Swift Dialog
if [[ ! -d $dialogApp ]]; then
echo "Cannot find dialog at $dialogApp"
exit 95
fi
# close and quit dialog
dialogUpdate "progress: complete"
dialogUpdate "progresstext: Done"
# pause a moment
sleep 0.5
dialogUpdate "quit:"
# let everything catch up
sleep 0.5
# just to be safe
killall "Dialog"
# the killall command above will return error when Dialog is already quit
# but we don't want that to register as a failure in Jamf, so always exit 0
exit 0

151
MDM/swiftdialog_example.sh Executable file
View File

@@ -0,0 +1,151 @@
#!/bin/zsh
# runs through a list of Installomator items
# and displays status using Swift Dialog
#
# dependencies:
# - Swift Dialog: https://github.com/bartreardon/swiftDialog
# - Installomator: https://github.com/Installomator/Installomator
# this script will install both if they are not yet present
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# MARK: Variables
# set to 1 to not require root and not actually do any changes
# set to 0 for production
if [[ $1 == "NODEBUG" ]]; then
DEBUG=0
else
DEBUG=1
fi
# the label to install:
label="googlechromepkg"
# MARK: Constants
scriptDir=$(dirname ${0:A})
repoDir=$(dirname $scriptDir)
# if [[ $DEBUG -eq 1 ]]; then
installomator="$repoDir/utils/assemble.sh"
# else
# installomator="/usr/local/Installomator/Installomator.sh"
# fi
dialog="/usr/local/bin/dialog"
if [[ DEBUG -eq 0 ]]; then
dialog_command_file="/var/tmp/dialog.log"
else
dialog_command_file="$HOME/dialog.log"
fi
# MARK: Functions
dialogUpdate() {
# $1: dialog command
local dcommand=$1
if [[ -n $dialog_command_file ]]; then
echo "$dcommand" >> $dialog_command_file
echo "Dialog: $dcommand"
fi
}
progressUpdate() {
# $1: progress text (optional)
local text=$1
itemCounter=$((itemCounter + 1))
dialogUpdate "progress: $itemCounter"
if [[ -n $text ]]; then
dialogUpdate "progresstext: $text"
fi
}
startItem() {
local description=$1
echo "Starting Item: $description"
dialogUpdate "listitem: $description: wait"
progressUpdate $description
}
cleanupAndExit() {
# kill caffeinate process
if [[ -n $caffeinatePID ]]; then
echo "killing caffeinate..."
kill $caffeinatePID
fi
# clean up tmp dir
if [[ -n $tmpDir && -d $tmpDir ]]; then
echo "removing tmpDir $tmpDir"
rm -rf $tmpDir
fi
}
# MARK: sanity checks
# check minimal macOS requirement
if [[ $(sw_vers -buildVersion ) < "20" ]]; then
echo "This script requires at least macOS 11 Big Sur."
exit 98
fi
# check we are running as root
if [[ $DEBUG -eq 0 && $(id -u) -ne 0 ]]; then
echo "This script should be run as root"
exit 97
fi
# check for installomator
if [[ ! -x $installomator ]]; then
echo "Cannot find Installomator at $installomator"
exit 96
fi
# check for Swift Dialog
if [[ ! -x $dialog ]]; then
echo "Cannot find dialog at $dialog"
exit 95
fi
# MARK: Setup
# No sleeping
caffeinate -dimsu & caffeinatePID=$!
# trap exit for cleanup
trap cleanupAndExit EXIT
# display first screen
$dialog --title "Installing $label" \
--message "" \
--hideicon \
--mini \
--progress 100 \
--position bottomright \
--ontop \
--movable \
--commandfile $dialog_command_file & dialogPID=$!
sleep 0.1
$installomator $label \
DIALOG_CMD_FILE="$dialog_command_file" \
DEBUG=$DEBUG
# clean up UI
dialogUpdate "progress: complete"
dialogUpdate "progresstext: Done"
sleep 0.5
dialogUpdate "quit:"

185
MDM/swiftdialog_list.sh Executable file
View File

@@ -0,0 +1,185 @@
#!/bin/zsh
# runs through a list of Installomator items
# and displays status using Swift Dialog
#
# dependencies:
# - Swift Dialog: https://github.com/bartreardon/swiftDialog
# - Installomator: https://github.com/Installomator/Installomator
# this script will install both if they are not yet present
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# MARK: Variables
# set to 1 to not require root and not actually do any changes
# set to 0 for production
if [[ $1 == "NODEBUG" ]]; then
DEBUG=0
else
DEBUG=1
fi
# list of Installomator labels
items=(
"firefoxpkg|Firefox"
"error|Expected Error"
"googlechromepkg|Google Chrome"
)
# MARK: Constants
scriptDir=$(dirname ${0:A})
repoDir=$(dirname $scriptDir)
# if [[ $DEBUG -eq 1 ]]; then
installomator="$repoDir/utils/assemble.sh"
# else
# installomator="/usr/local/Installomator/Installomator.sh"
# fi
dialog="/usr/local/bin/dialog"
if [[ DEBUG -eq 0 ]]; then
dialog_command_file="/var/tmp/dialog.log"
else
dialog_command_file="$HOME/dialog.log"
fi
# MARK: Functions
dialogUpdate() {
# $1: dialog command
local dcommand=$1
if [[ -n $dialog_command_file ]]; then
echo "$dcommand" >> $dialog_command_file
echo "Dialog: $dcommand"
fi
}
progressUpdate() {
# $1: progress text (optional)
local text=$1
itemCounter=$((itemCounter + 1))
dialogUpdate "progress: $itemCounter"
if [[ -n $text ]]; then
dialogUpdate "progresstext: $text"
fi
}
startItem() {
local description=$1
echo "Starting Item: $description"
dialogUpdate "listitem: $description: wait"
progressUpdate $description
}
installomator() {
# $1: label
# $2: description
local label=$1
local description=$2
$installomator $label \
DIALOG_CMD_FILE=${(q)dialog_command_file} \
DIALOG_LIST_ITEM_NAME=${(q)description} \
DEBUG=$DEBUG \
LOGGING=DEBUG
}
cleanupAndExit() {
# kill caffeinate process
if [[ -n $caffeinatePID ]]; then
echo "killing caffeinate..."
kill $caffeinatePID
fi
# clean up tmp dir
if [[ -n $tmpDir && -d $tmpDir ]]; then
echo "removing tmpDir $tmpDir"
rm -rf $tmpDir
fi
}
# MARK: sanity checks
# check minimal macOS requirement
if [[ $(sw_vers -buildVersion ) < "20" ]]; then
echo "This script requires at least macOS 11 Big Sur."
exit 98
fi
# check we are running as root
if [[ $DEBUG -eq 0 && $(id -u) -ne 0 ]]; then
echo "This script should be run as root"
exit 97
fi
# check for installomator
if [[ ! -x $installomator ]]; then
echo "Cannot find Installomator at $installomator"
exit 96
fi
# check for Swift Dialog
if [[ ! -x $dialog ]]; then
echo "Cannot find dialog at $dialog"
exit 95
fi
# MARK: Setup
# No sleeping
caffeinate -dimsu & caffeinatePID=$!
# trap exit for cleanup
trap cleanupAndExit EXIT
# setup first list
itemCount=$((${#items} + 1))
listitems=( )
for item in $items; do
label=$(cut -d '|' -f 1 <<< $item)
description=$(cut -d '|' -f 2 <<< $item)
listitems+=( "--listitem" ${description} )
done
# display first screen
$dialog --title "More Software" \
--icon "SF=gear" \
--message "We are downloading and installing some extra Apps..." \
--progress $itemCount \
"${listitems[@]}" \
--button1disabled \
--big \
--ontop \
--liststyle compact \
--width 700 \
--commandfile $dialog_command_file & dialogPID=$!
sleep 0.1
itemCounter=0
for item in $items; do
label=$(cut -d '|' -f 1 <<< $item)
description=$(cut -d '|' -f 2 <<< $item)
startItem $description
installomator $label $description
done
# clean up UI
dialogUpdate "progress: complete"
dialogUpdate "progresstext: Finished"
dialogUpdate "button1: enable"
dialogUpdate "button1text: Done"