mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
code cleanup
This commit is contained in:
@@ -100,8 +100,8 @@ installomator() {
|
|||||||
startItem $description
|
startItem $description
|
||||||
|
|
||||||
$installomator $label \
|
$installomator $label \
|
||||||
DIALOG_PROGRESS="list" \
|
DIALOG_CMD_FILE=${(q)dialog_command_file} \
|
||||||
DIALOG_CMD_FILE=$dialog_command_file \
|
DIALOG_LIST_ITEM_NAME=${(q)description} \
|
||||||
DEBUG=$DEBUG \
|
DEBUG=$DEBUG \
|
||||||
LOGGING=DEBUG
|
LOGGING=DEBUG
|
||||||
|
|
||||||
@@ -117,12 +117,8 @@ printlog(){
|
|||||||
while IFS= read -r logmessage; do
|
while IFS= read -r logmessage; do
|
||||||
if [[ "$(whoami)" == "root" ]]; then
|
if [[ "$(whoami)" == "root" ]]; then
|
||||||
echo "$timestamp" : "${log_priority}${space_char} : $label : ${logmessage}" | tee -a $log_location
|
echo "$timestamp" : "${log_priority}${space_char} : $label : ${logmessage}" | tee -a $log_location
|
||||||
updateDialogProgressText "${logmessage}"
|
|
||||||
# updateDialogProgress "increment"
|
|
||||||
else
|
else
|
||||||
echo "$timestamp" : "${log_priority}${space_char} : $label : ${logmessage}"
|
echo "$timestamp" : "${log_priority}${space_char} : $label : ${logmessage}"
|
||||||
updateDialogProgressText "${logmessage}"
|
|
||||||
# updateDialogProgress "increment"
|
|
||||||
fi
|
fi
|
||||||
done <<< "$log_message"
|
done <<< "$log_message"
|
||||||
fi
|
fi
|
||||||
@@ -649,7 +645,7 @@ installFromPKG() {
|
|||||||
# install pkg
|
# install pkg
|
||||||
printlog "Installing $archiveName to $targetDir"
|
printlog "Installing $archiveName to $targetDir"
|
||||||
|
|
||||||
if [[ $DIALOG_PROGRESS == "main" || $DIALOG_PROGRESS == "list" ]]; then
|
if [[ $DIALOG_CMD_FILE != "" ]]; then
|
||||||
# pipe
|
# pipe
|
||||||
pipe="$tmpDir/installpipe"
|
pipe="$tmpDir/installpipe"
|
||||||
# initialise named pipe for installer output
|
# initialise named pipe for installer output
|
||||||
@@ -659,14 +655,11 @@ installFromPKG() {
|
|||||||
readPKGInstallPipe $pipe "$DIALOG_CMD_FILE" & installPipePID=$!
|
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
|
printlog "listening to output of installer with pipe $pipe and command file $DIALOG_CMD_FILE on PID $installPipePID" DEBUG
|
||||||
|
|
||||||
# curl (extract - line in "# MARK: download the archive" of Installomator.sh)
|
|
||||||
pkgInstall=$(installer -verboseR -pkg "$archiveName" -tgt "$targetDir" 2>&1 | tee $pipe)
|
pkgInstall=$(installer -verboseR -pkg "$archiveName" -tgt "$targetDir" 2>&1 | tee $pipe)
|
||||||
pkgInstallStatus=$pipestatus[1]
|
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
|
# 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
|
killProcess $installPipePID
|
||||||
|
|
||||||
#enableDialogButtonAndSetToDone "$DIALOGCMDFILE"
|
|
||||||
#quitDialog $DIALOGCMDFILE
|
|
||||||
else
|
else
|
||||||
pkgInstall=$(installer -verbose -dumplog -pkg "$archiveName" -tgt "$targetDir" 2>&1)
|
pkgInstall=$(installer -verbose -dumplog -pkg "$archiveName" -tgt "$targetDir" 2>&1)
|
||||||
pkgInstallStatus=$(echo $?)
|
pkgInstallStatus=$(echo $?)
|
||||||
@@ -853,11 +846,9 @@ runUpdateTool() {
|
|||||||
|
|
||||||
finishing() {
|
finishing() {
|
||||||
printlog "Finishing..."
|
printlog "Finishing..."
|
||||||
if [[ $DIALOG_PROGRESS == "main" || $DIALOG_PROGRESS == "list" ]]; then
|
updateDialog "wait" "Finishing..."
|
||||||
updateDialogProgress "complete"
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 5 # wait a moment to let spotlight catch up
|
sleep 3 # wait a moment to let spotlight catch up
|
||||||
getAppVersion
|
getAppVersion
|
||||||
|
|
||||||
if [[ -z $appversion ]]; then
|
if [[ -z $appversion ]]; then
|
||||||
@@ -940,12 +931,7 @@ readDownloadPipe() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $char == % ]]; then
|
if [[ $char == % ]]; then
|
||||||
if [[ $DIALOG_PROGRESS == "main" ]]; then
|
updateDialog $progress "Downloading $name - $progress%"
|
||||||
updateDialogProgressText "Downloading $name - $progress%"
|
|
||||||
updateDialogProgress "$progress"
|
|
||||||
elif [[ $DIALOG_PROGRESS == "list" ]]; then
|
|
||||||
updateDialogListItem $progress $name "Downloading..." $log
|
|
||||||
fi
|
|
||||||
progress=""
|
progress=""
|
||||||
keep=0
|
keep=0
|
||||||
fi
|
fi
|
||||||
@@ -971,12 +957,7 @@ readPKGInstallPipe() {
|
|||||||
progress="$progress$char"
|
progress="$progress$char"
|
||||||
fi
|
fi
|
||||||
if [[ $char == . && $keep == 1 ]]; then
|
if [[ $char == . && $keep == 1 ]]; then
|
||||||
if [[ $DIALOG_PROGRESS == "main" ]]; then
|
updateDialog $progress "Installing $appname"
|
||||||
updateDialogProgressText "Installing $appname $progress%" $log
|
|
||||||
updateDialogProgress "$progress" $log
|
|
||||||
elif [[ $DIALOG_PROGRESS == "list" ]]; then
|
|
||||||
updateDialogListItem $progress $name "Installing..." $log
|
|
||||||
fi
|
|
||||||
progress=""
|
progress=""
|
||||||
keep=0
|
keep=0
|
||||||
fi
|
fi
|
||||||
@@ -988,22 +969,40 @@ killProcess() {
|
|||||||
builtin kill $1 2>/dev/null
|
builtin kill $1 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDialogProgress() {
|
updateDialog() {
|
||||||
local progress=$1
|
local state=$1
|
||||||
local log=${2:-$DIALOG_CMD_FILE}
|
local message=$2
|
||||||
echo "progress: $progress" >> $log
|
local listitem=${3:-$DIALOG_LIST_ITEM_NAME}
|
||||||
}
|
local cmd_file=${4:-$DIALOG_CMD_FILE}
|
||||||
|
local progress=""
|
||||||
|
|
||||||
updateDialogProgressText() {
|
if [[ state =~ [0-9]* \
|
||||||
local message=$1
|
|| state == "reset" \
|
||||||
local log=${2:-$DIALOG_CMD_FILE}
|
|| state == "increment" \
|
||||||
echo "progresstext: $message" >> $log
|
|| state == "complete" \
|
||||||
}
|
|| state == "indeterminate" ]]; then
|
||||||
|
progress=$state
|
||||||
|
fi
|
||||||
|
|
||||||
updateDialogListItem() {
|
# when to cmdfile is set, do nothing
|
||||||
local progress=$1
|
if [[ $$cmd_file == "" ]]; then
|
||||||
local listitem=${2:-$name}
|
return
|
||||||
local action=${3:-"Processing..."}
|
fi
|
||||||
local log=${4:-$DIALOG_CMD_FILE}
|
|
||||||
echo "listitem: title: $listitem, statustext: $action, progress: $progress" >> $log
|
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: $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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,14 +137,24 @@ IGNORE_DND_APPS=""
|
|||||||
# example that will ignore browsers when evaluating DND:
|
# example that will ignore browsers when evaluating DND:
|
||||||
# IGNORE_DND_APPS="firefox,Google Chrome,Safari,Microsoft Edge,Opera,Amphetamine,caffeinate"
|
# IGNORE_DND_APPS="firefox,Google Chrome,Safari,Microsoft Edge,Opera,Amphetamine,caffeinate"
|
||||||
|
|
||||||
# show swiftDialog window with download and install progress
|
|
||||||
DIALOG_PROGRESS="no"
|
# Swift Dialog integration
|
||||||
# options:
|
|
||||||
# - no do not show download or install progress (default)
|
# These variables will allow Installomator to communicate progress with Swift Dialog
|
||||||
# - main show download or install progress in the main progress bar
|
# https://github.com/bartreardon/swiftDialog
|
||||||
# - list show download or install progress with each list item
|
|
||||||
# the `-list` option requires the DIALOG_LIST_INDEX to be set
|
# This requires Swift Dialog 2.11.2 or higher.
|
||||||
DIALOG_CMD_FILE="/private/var/tmp/dialog.log"
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $DIALOG_PROGRESS == "main" || $DIALOG_PROGRESS == "list" ]]; then
|
if [[ $DIALOG_CMD_FILE != "" ]]; then
|
||||||
# pipe
|
# pipe
|
||||||
pipe="$tmpDir/downloadpipe"
|
pipe="$tmpDir/downloadpipe"
|
||||||
# initialise named pipe for curl output
|
# initialise named pipe for curl output
|
||||||
@@ -205,14 +205,11 @@ else
|
|||||||
readDownloadPipe $pipe "$DIALOG_CMD_FILE" & downloadPipePID=$!
|
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
|
printlog "listening to output of curl with pipe $pipe and command file $DIALOG_CMD_FILE on PID $downloadPipePID" DEBUG
|
||||||
|
|
||||||
# curl (extract - line in "# MARK: download the archive" of Installomator.sh)
|
|
||||||
curlDownload=$(curl -fL -# --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1 | tee $pipe)
|
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
|
# 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])
|
curlDownloadStatus=$(echo $pipestatus[1])
|
||||||
killProcess $downloadPipePID
|
killProcess $downloadPipePID
|
||||||
|
|
||||||
#enableDialogButtonAndSetToDone "$DIALOGCMDFILE"
|
|
||||||
#quitDialog $DIALOGCMDFILE
|
|
||||||
else
|
else
|
||||||
printlog "No Dialog connection, just download" DEBUG
|
printlog "No Dialog connection, just download" DEBUG
|
||||||
curlDownload=$(curl -v -fsL --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1)
|
curlDownload=$(curl -v -fsL --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1)
|
||||||
|
|||||||
Reference in New Issue
Block a user