now displays installer progress in list and main

This commit is contained in:
Armin Briegel
2022-08-01 14:44:51 +02:00
parent 4905091908
commit 1d49c08344
3 changed files with 65 additions and 57 deletions

View File

@@ -14,7 +14,11 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# set to 1 to not require root and not actually do any changes # set to 1 to not require root and not actually do any changes
# set to 0 for production # set to 0 for production
if [[ $1 == "NODEBUG" ]]; then
DEBUG=0
else
DEBUG=1 DEBUG=1
fi
# the delay to simulate an install in DEBUG mode # the delay to simulate an install in DEBUG mode
fakeInstallDelay=5 fakeInstallDelay=5
@@ -24,7 +28,6 @@ fakeInstallDelay=5
items=( items=(
"firefoxpkg|Firefox" "firefoxpkg|Firefox"
"googlechromepkg|Google Chrome" "googlechromepkg|Google Chrome"
"microsoftedge|Microsoft Edge"
) )
# MARK: Constants # MARK: Constants
@@ -32,11 +35,11 @@ items=(
scriptDir=$(dirname ${0:A}) scriptDir=$(dirname ${0:A})
repoDir=$(dirname $scriptDir) repoDir=$(dirname $scriptDir)
if [[ $DEBUG -eq 1 ]]; then # if [[ $DEBUG -eq 1 ]]; then
installomator="$repoDir/utils/assemble.sh" installomator="$repoDir/utils/assemble.sh"
else # else
installomator="/usr/local/Installomator/Installomator.sh" # installomator="/usr/local/Installomator/Installomator.sh"
fi # fi
dialog="/usr/local/bin/dialog" dialog="/usr/local/bin/dialog"
@@ -99,7 +102,8 @@ installomator() {
$installomator $label \ $installomator $label \
DIALOG_PROGRESS="list" \ DIALOG_PROGRESS="list" \
DIALOG_CMD_FILE=$dialog_command_file \ DIALOG_CMD_FILE=$dialog_command_file \
DEBUG=$DEBUG DEBUG=$DEBUG \
LOGGING=DEBUG
# if [[ $DEBUG -eq 0 ]]; then # if [[ $DEBUG -eq 0 ]]; then
# $installomator $label DIALOG_PROGRESS=yes DIALOG_CMD_FILE=$dialog_command_file # $installomator $label DIALOG_PROGRESS=yes DIALOG_CMD_FILE=$dialog_command_file
@@ -211,7 +215,6 @@ if [[ $DEBUG -eq 0 && $(id -u) -ne 0 ]]; then
exit 97 exit 97
fi fi
# MARK: Setup # MARK: Setup
# No sleeping # No sleeping

View File

@@ -648,8 +648,32 @@ installFromPKG() {
# install pkg # install pkg
printlog "Installing $archiveName to $targetDir" printlog "Installing $archiveName to $targetDir"
if [[ $DIALOG_PROGRESS == "main" || $DIALOG_PROGRESS == "list" ]]; 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
# curl (extract - line in "# MARK: download the archive" of Installomator.sh)
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
#enableDialogButtonAndSetToDone "$DIALOGCMDFILE"
#quitDialog $DIALOGCMDFILE
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 $?)
fi
sleep 1 sleep 1
pkgEndTime=$(date "+$LogDateFormat") pkgEndTime=$(date "+$LogDateFormat")
pkgInstall+=$(echo "\nOutput of /var/log/install.log below this line.\n") pkgInstall+=$(echo "\nOutput of /var/log/install.log below this line.\n")
@@ -920,7 +944,7 @@ readDownloadPipe() {
updateDialogProgressText "Downloading $name - $progress%" updateDialogProgressText "Downloading $name - $progress%"
updateDialogProgress "$progress" updateDialogProgress "$progress"
elif [[ $DIALOG_PROGRESS == "list" ]]; then elif [[ $DIALOG_PROGRESS == "list" ]]; then
echo "listitem: title: $name, statustext: Downloading... $progress%, progress: $progress" >> $log updateDialogListItem $progress $name "Downloading..." $log
fi fi
progress="" progress=""
keep=0 keep=0
@@ -936,12 +960,26 @@ readPKGInstallPipe() {
# reads from a previously created named pipe # 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 # output from installer with -verboseR. % install status is read in and then sent to the specified log file
local pipe=$1 local pipe=$1
local log=$2 local log=${2:-$DIALOG_CMD_FILE}
local appname=$3 local appname=${3:-$name}
while read -k 1 -u 0 char; do while read -k 1 -u 0 char; do
[[ $char == % ]] && keep=1 ; if [[ $char == % ]]; then
[[ $char =~ [0-9] ]] && [[ $keep == 1 ]] && progress="$progress$char" ; keep=1
[[ $char == . ]] && [[ $keep == 1 ]] && updateDialogProgressText "Installing $appname $progress%" $log && updateDialogProgress "$progress" $log && progress="" && keep=0 ; fi
if [[ $char =~ [0-9] && $keep == 1 ]]; then
progress="$progress$char"
fi
if [[ $char == . && $keep == 1 ]]; then
if [[ $DIALOG_PROGRESS == "main" ]]; then
updateDialogProgressText "Installing $appname $progress%" $log
updateDialogProgress "$progress" $log
elif [[ $DIALOG_PROGRESS == "list" ]]; then
updateDialogListItem $progress $name "Installing..." $log
fi
progress=""
keep=0
fi
done < $pipe done < $pipe
} }
@@ -962,45 +1000,10 @@ updateDialogProgressText() {
echo "progresstext: $message" >> $log echo "progresstext: $message" >> $log
} }
launchDialog() { updateDialogListItem() {
# launches a dialog window to display download and/or install progress. local progress=$1
local name=$1 local listitem=${2:-$name}
local log=${2:-$DIALOG_CMD_FILE} local action=${3:-"Processing..."}
if [[ -z "$log" ]]; then local log=${4:-$DIALOG_CMD_FILE}
log="/private/var/tmp/dialog.log" echo "listitem: title: $listitem, statustext: $action, progress: $progress" >> $log
fi
# check for laptop or desktop
#if /usr/bin/pmset -g batt | grep -iq "battery"; then
# icon="SF=laptopcomputer.and.arrow.down"
#else
# icon="SF=desktopcomputer.and.arrow.down"
#fi
icon="SF=arrow.down.to.line,colour=green,bgcolour=white,weight=regular"
# launch dialog
/usr/local/bin/dialog -o \
--title "none" \
--message "## Installing $name\n\nPlease wait..." \
--progress 120 \
--alignment centre \
--icon "$LOGO" \
--overlayicon "$icon" \
--height 350 --width 550 \
--centreicon \
--position bottomright \
--button1disabled \
--button1text "Please Wait" \
--commandfile "$log"
}
quitDialog() {
# sends the quit command to dialog
local log=${1:-$DIALOG_CMD_FILE}
echo "quit:" >> "$log"
}
enableDialogButtonAndSetToDone() {
local log=${1:-$DIALOG_CMD_FILE}
echo "button1text: Done" >> $log
echo "button1: enable" >> $log
} }

View File

@@ -203,6 +203,7 @@ else
# run the pipe read in the background # run the pipe read in the background
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
# curl (extract - line in "# MARK: download the archive" of Installomator.sh) # 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)
@@ -213,6 +214,7 @@ else
#enableDialogButtonAndSetToDone "$DIALOGCMDFILE" #enableDialogButtonAndSetToDone "$DIALOGCMDFILE"
#quitDialog $DIALOGCMDFILE #quitDialog $DIALOGCMDFILE
else else
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)
curlDownloadStatus=$(echo $?) curlDownloadStatus=$(echo $?)
fi fi