mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
Merge pull request #641 from scriptingosx/swiftdialog
swiftDialog Integration
This commit is contained in:
69
MDM/Jamf/00_Prepare_SwiftDialog.sh
Executable file
69
MDM/Jamf/00_Prepare_SwiftDialog.sh
Executable 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
48
MDM/Jamf/ReadMe.md
Normal 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.
|
||||
|
||||

|
||||
|
||||
BIN
MDM/Jamf/SelfServiceProgress.png
Normal file
BIN
MDM/Jamf/SelfServiceProgress.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 576 KiB |
57
MDM/Jamf/zz_Quit_SwiftDialog.sh
Executable file
57
MDM/Jamf/zz_Quit_SwiftDialog.sh
Executable 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
151
MDM/swiftdialog_example.sh
Executable 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
185
MDM/swiftdialog_list.sh
Executable 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"
|
||||
|
||||
@@ -7,6 +7,7 @@ if ! is-at-least 10.14 $installedOSversion; then
|
||||
exit 98
|
||||
fi
|
||||
|
||||
|
||||
# MARK: argument parsing
|
||||
if [[ $# -eq 0 ]]; then
|
||||
if [[ -z $label ]]; then # check if label is set inside script
|
||||
@@ -24,7 +25,7 @@ fi
|
||||
while [[ -n $1 ]]; do
|
||||
if [[ $1 =~ ".*\=.*" ]]; then
|
||||
# if an argument contains an = character, send it to eval
|
||||
printlog "setting variable from argument $1" WARN
|
||||
printlog "setting variable from argument $1" INFO
|
||||
eval $1
|
||||
else
|
||||
# assume it's a label
|
||||
@@ -99,6 +100,16 @@ if [[ "$(whoami)" != "root" && "$DEBUG" -eq 0 ]]; then
|
||||
cleanupAndExit 6 "not running as root, exiting" ERROR
|
||||
fi
|
||||
|
||||
|
||||
# check Swift Dialog presence and version
|
||||
DIALOG_CMD="/usr/local/bin/dialog"
|
||||
|
||||
if [[ ! -x $DIALOG_CMD ]]; then
|
||||
# Swift Dialog is not installed, clear cmd file variable to ignore
|
||||
printlog "SwiftDialog is not installed, clear cmd file var"
|
||||
DIALOG_CMD_FILE=""
|
||||
fi
|
||||
|
||||
# MARK: labels in case statement
|
||||
case $label in
|
||||
longversion)
|
||||
|
||||
@@ -14,12 +14,15 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
|
||||
printlog "Debugging enabled, Deleting tmpDir output was:\n$deleteTmpOut" DEBUG
|
||||
fi
|
||||
|
||||
|
||||
# If we closed any processes, reopen the app again
|
||||
reopenClosedProcess
|
||||
if [[ -n $2 && $1 -ne 0 ]]; then
|
||||
printlog "ERROR: $2" $3
|
||||
updateDialog "fail" "Error ($1; $2)"
|
||||
else
|
||||
printlog "$2" $3
|
||||
updateDialog "success" ""
|
||||
fi
|
||||
printlog "################## End Installomator, exit code $1 \n" REQ
|
||||
|
||||
@@ -428,6 +431,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir
|
||||
|
||||
# verify with spctl
|
||||
printlog "Verifying: $appPath" INFO
|
||||
updateDialog "wait" "Verifying..."
|
||||
printlog "App size: $(du -sh "$appPath")" DEBUG
|
||||
appVerify=$(spctl -a -vv "$appPath" 2>&1 )
|
||||
appVerifyStatus=$(echo $?)
|
||||
@@ -573,6 +577,7 @@ installFromDMG() {
|
||||
installFromPKG() {
|
||||
# verify with spctl
|
||||
printlog "Verifying: $archiveName"
|
||||
updateDialog "wait" "Verifying..."
|
||||
printlog "File list: $(ls -lh "$archiveName")" DEBUG
|
||||
printlog "File type: $(file "$archiveName")" DEBUG
|
||||
spctlOut=$(spctl -a -vv -t install "$archiveName" 2>&1 )
|
||||
@@ -640,8 +645,29 @@ installFromPKG() {
|
||||
|
||||
# install pkg
|
||||
printlog "Installing $archiveName to $targetDir"
|
||||
|
||||
if [[ $DIALOG_CMD_FILE != "" ]]; then
|
||||
# pipe
|
||||
pipe="$tmpDir/installpipe"
|
||||
# initialise named pipe for installer output
|
||||
initNamedPipe create $pipe
|
||||
|
||||
# run the pipe read in the background
|
||||
readPKGInstallPipe $pipe "$DIALOG_CMD_FILE" & installPipePID=$!
|
||||
printlog "listening to output of installer with pipe $pipe and command file $DIALOG_CMD_FILE on PID $installPipePID" DEBUG
|
||||
|
||||
pkgInstall=$(installer -verboseR -pkg "$archiveName" -tgt "$targetDir" 2>&1 | tee $pipe)
|
||||
pkgInstallStatus=$pipestatus[1]
|
||||
# because we are tee-ing the output, we want the pipe status of the first command in the chain, not the most recent one
|
||||
killProcess $installPipePID
|
||||
|
||||
else
|
||||
pkgInstall=$(installer -verbose -dumplog -pkg "$archiveName" -tgt "$targetDir" 2>&1)
|
||||
pkgInstallStatus=$(echo $?)
|
||||
fi
|
||||
|
||||
|
||||
|
||||
sleep 1
|
||||
pkgEndTime=$(date "+$LogDateFormat")
|
||||
pkgInstall+=$(echo "\nOutput of /var/log/install.log below this line.\n")
|
||||
@@ -821,7 +847,8 @@ runUpdateTool() {
|
||||
|
||||
finishing() {
|
||||
printlog "Finishing..."
|
||||
sleep 10 # wait a moment to let spotlight catch up
|
||||
|
||||
sleep 3 # wait a moment to let spotlight catch up
|
||||
getAppVersion
|
||||
|
||||
if [[ -z $appversion ]]; then
|
||||
@@ -869,3 +896,113 @@ hasDisplaySleepAssertion() {
|
||||
return 1
|
||||
}
|
||||
|
||||
initNamedPipe() {
|
||||
# create or delete a named pipe
|
||||
# commands are "create" or "delete"
|
||||
|
||||
local cmd=$1
|
||||
local pipe=$2
|
||||
case $cmd in
|
||||
"create")
|
||||
if [[ -e $pipe ]]; then
|
||||
rm $pipe
|
||||
fi
|
||||
# make named pipe
|
||||
mkfifo -m 644 $pipe
|
||||
;;
|
||||
"delete")
|
||||
# clean up
|
||||
rm $pipe
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
readDownloadPipe() {
|
||||
# reads from a previously created named pipe
|
||||
# output from curl with --progress-bar. % downloaded is read in and then sent to the specified log file
|
||||
local pipe=$1
|
||||
local log=${2:-$DIALOG_CMD_FILE}
|
||||
# set up read from pipe
|
||||
while IFS= read -k 1 -u 0 char; do
|
||||
if [[ $char =~ [0-9] ]]; then
|
||||
keep=1
|
||||
fi
|
||||
|
||||
if [[ $char == % ]]; then
|
||||
updateDialog $progress "Downloading..."
|
||||
progress=""
|
||||
keep=0
|
||||
fi
|
||||
|
||||
if [[ $keep == 1 ]]; then
|
||||
progress="$progress$char"
|
||||
fi
|
||||
done < $pipe
|
||||
}
|
||||
|
||||
readPKGInstallPipe() {
|
||||
# reads from a previously created named pipe
|
||||
# output from installer with -verboseR. % install status is read in and then sent to the specified log file
|
||||
local pipe=$1
|
||||
local log=${2:-$DIALOG_CMD_FILE}
|
||||
local appname=${3:-$name}
|
||||
|
||||
while read -k 1 -u 0 char; do
|
||||
if [[ $char == % ]]; then
|
||||
keep=1
|
||||
fi
|
||||
if [[ $char =~ [0-9] && $keep == 1 ]]; then
|
||||
progress="$progress$char"
|
||||
fi
|
||||
if [[ $char == . && $keep == 1 ]]; then
|
||||
updateDialog $progress "Installing..."
|
||||
progress=""
|
||||
keep=0
|
||||
fi
|
||||
done < $pipe
|
||||
}
|
||||
|
||||
killProcess() {
|
||||
# will silently kill the specified PID
|
||||
builtin kill $1 2>/dev/null
|
||||
}
|
||||
|
||||
updateDialog() {
|
||||
local state=$1
|
||||
local message=$2
|
||||
local listitem=${3:-$DIALOG_LIST_ITEM_NAME}
|
||||
local cmd_file=${4:-$DIALOG_CMD_FILE}
|
||||
local progress=""
|
||||
|
||||
if [[ $state =~ '^[0-9]' \
|
||||
|| $state == "reset" \
|
||||
|| $state == "increment" \
|
||||
|| $state == "complete" \
|
||||
|| $state == "indeterminate" ]]; then
|
||||
progress=$state
|
||||
fi
|
||||
|
||||
# when to cmdfile is set, do nothing
|
||||
if [[ $$cmd_file == "" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $listitem == "" ]]; then
|
||||
# no listitem set, update main progress bar and progress text
|
||||
if [[ $progress != "" ]]; then
|
||||
echo "progress: $progress" >> $cmd_file
|
||||
fi
|
||||
if [[ $message != "" ]]; then
|
||||
echo "progresstext: $name - $message" >> $cmd_file
|
||||
fi
|
||||
else
|
||||
# list item has a value, so we update the progress and text in the list
|
||||
if [[ $progress != "" ]]; then
|
||||
echo "listitem: title: $listitem, statustext: $message, progress: $progress" >> $cmd_file
|
||||
else
|
||||
echo "listitem: title: $listitem, statustext: $message, status: $state" >> $cmd_file
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ NOTIFY=success
|
||||
# - silent no notifications
|
||||
# - all all notifications (great for Self Service installation)
|
||||
|
||||
|
||||
# behavior when blocking processes are found
|
||||
BLOCKING_PROCESS_ACTION=tell_user
|
||||
# options:
|
||||
@@ -139,6 +138,26 @@ IGNORE_DND_APPS=""
|
||||
# IGNORE_DND_APPS="firefox,Google Chrome,Safari,Microsoft Edge,Opera,Amphetamine,caffeinate"
|
||||
|
||||
|
||||
# Swift Dialog integration
|
||||
|
||||
# These variables will allow Installomator to communicate progress with Swift Dialog
|
||||
# https://github.com/bartreardon/swiftDialog
|
||||
|
||||
# This requires Swift Dialog 2.11.2 or higher.
|
||||
|
||||
DIALOG_CMD_FILE=""
|
||||
# When this variable is set, Installomator will write Swift Dialog commands to this path.
|
||||
# Installomator will not launch Swift Dialog. The process calling Installomator will have
|
||||
# launch and configure Swift Dialog to listen to this file.
|
||||
# See `MDM/swiftdialog_example.sh` for an example.
|
||||
|
||||
DIALOG_LIST_ITEM_NAME=""
|
||||
# When this variable is set, progress for downloads and installs will be sent to this
|
||||
# listitem.
|
||||
# When the variable is unset, progress will be sent to Swift Dialog's main progress bar.
|
||||
|
||||
|
||||
|
||||
# NOTE: How labels work
|
||||
|
||||
# Each workflow label needs to be listed in the case statement below.
|
||||
|
||||
@@ -168,6 +168,8 @@ fi
|
||||
# MARK: check if this is an Update and we can use updateTool
|
||||
if [[ (-n $appversion && -n "$updateTool") || "$type" == "updateronly" ]]; then
|
||||
printlog "appversion & updateTool"
|
||||
updateDialog "wait" "Updating..."
|
||||
|
||||
if [[ $DEBUG -ne 1 ]]; then
|
||||
if runUpdateTool; then
|
||||
finishing
|
||||
@@ -194,8 +196,28 @@ else
|
||||
displaynotification "Downloading new $name" "Download in progress …"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $DIALOG_CMD_FILE != "" ]]; then
|
||||
# pipe
|
||||
pipe="$tmpDir/downloadpipe"
|
||||
# initialise named pipe for curl output
|
||||
initNamedPipe create $pipe
|
||||
|
||||
# run the pipe read in the background
|
||||
readDownloadPipe $pipe "$DIALOG_CMD_FILE" & downloadPipePID=$!
|
||||
printlog "listening to output of curl with pipe $pipe and command file $DIALOG_CMD_FILE on PID $downloadPipePID" DEBUG
|
||||
|
||||
curlDownload=$(curl -fL -# --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1 | tee $pipe)
|
||||
# because we are tee-ing the output, we want the pipe status of the first command in the chain, not the most recent one
|
||||
curlDownloadStatus=$(echo $pipestatus[1])
|
||||
killProcess $downloadPipePID
|
||||
|
||||
else
|
||||
printlog "No Dialog connection, just download" DEBUG
|
||||
curlDownload=$(curl -v -fsL --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1)
|
||||
curlDownloadStatus=$(echo $?)
|
||||
fi
|
||||
|
||||
deduplicatelogs "$curlDownload"
|
||||
if [[ $curlDownloadStatus -ne 0 ]]; then
|
||||
#if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
|
||||
@@ -237,8 +259,10 @@ if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
|
||||
printlog "notifying"
|
||||
if [[ $updateDetected == "YES" ]]; then
|
||||
displaynotification "Updating $name" "Installation in progress …"
|
||||
updateDialog "wait" "Updating..."
|
||||
else
|
||||
displaynotification "Installing $name" "Installation in progress …"
|
||||
updateDialog "wait" "Installing..."
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -275,6 +299,8 @@ case $type in
|
||||
;;
|
||||
esac
|
||||
|
||||
updateDialog "wait" "Finishing..."
|
||||
|
||||
# MARK: Finishing — print installed application location and version
|
||||
finishing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user