Skip to content

Instantly share code, notes, and snippets.

@jmahlman
Last active May 23, 2022 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmahlman/991edd0e5e8e4d85b96c51cd119c3042 to your computer and use it in GitHub Desktop.
Save jmahlman/991edd0e5e8e4d85b96c51cd119c3042 to your computer and use it in GitHub Desktop.
Large install helper main function (download portion)
# Call this with "install" or "download" to update the DEPNotify window and progress dialogs
depNotifyProgress() {
last_progress_value=0
current_progress_value=0
if [[ "$1" == "download" ]]; then
echo "Command: MainTitle: Downloading $APPNAME" >> $DNLOG
# Wait for for the download to start, if it doesn't we'll bail out.
while [ ! -f "$JAMF_DOWNLOADS/$PKG_NAME" ]; do
userCancelProcess
if [[ "$TIMEOUT" == 0 ]]; then
echo "ERROR: (depNotifyProgress) Timeout while waiting for the download to start."
{
/bin/echo "Command: MainText: $DL_ERROR"
echo "Status: Error downloading $PKG_NAME"
echo "Command: DeterminateManualStep: 100"
echo "Command: Quit: $DL_ERROR"
} >> $DNLOG
exit 1
fi
sleep 1
((TIMEOUT--))
done
# Download started, lets set the progress bar
echo "Status: Downloading - 0%" >> $DNLOG
echo "Command: DeterminateManual: 100" >> $DNLOG
# Until at least 100% is reached, calculate the downloading progress and move the bar accordingly
until [[ "$current_progress_value" -ge 100 ]]; do
# shellcheck disable=SC2012
until [ "$current_progress_value" -gt "$last_progress_value" ]; do
# Check if the download is in the waiting room (it moves from downloads to the waiting room after it's fully downloaded)
if [[ ! -e "$JAMF_DOWNLOADS/$PKG_NAME" ]]; then
CURRENT_DL_SIZE=$(ls -l "$JAMF_WAITING_ROOM/$PKG_NAME" | awk '{ print $5 }' | awk '{$1/=1024;printf "%.i\n",$1}')
userCancelProcess
current_progress_value=$((CURRENT_DL_SIZE * 100 / PKG_Size))
sleep 2
else
CURRENT_DL_SIZE=$(ls -l "$JAMF_DOWNLOADS/$PKG_NAME" | awk '{ print $5 }' | awk '{$1/=1024;printf "%.i\n",$1}')
userCancelProcess
current_progress_value=$((CURRENT_DL_SIZE * 100 / PKG_Size))
sleep 2
fi
done
echo "Command: DeterminateManualStep: $((current_progress_value-last_progress_value))" >> $DNLOG
echo "Status: Downloading - $current_progress_value%" >> $DNLOG
last_progress_value=$current_progress_value
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment