From e6088a2edae361dacf077eec7705c8aa3a869212 Mon Sep 17 00:00:00 2001 From: Theile Date: Tue, 20 Sep 2022 16:34:12 +0200 Subject: [PATCH] Install swiftDialog in preparation script --- MDM/Jamf/00_PrepareInstall_SwiftDialog.sh | 159 ++++++++++++++++++++++ MDM/install Installomator direct.sh | 2 +- 2 files changed, 160 insertions(+), 1 deletion(-) create mode 100755 MDM/Jamf/00_PrepareInstall_SwiftDialog.sh diff --git a/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh b/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh new file mode 100755 index 0000000..425a157 --- /dev/null +++ b/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh @@ -0,0 +1,159 @@ +#!/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 + +# swiftDialog installation +name="Dialog" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg w. app version check +gitusername="bartreardon" +gitreponame="swiftDialog" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="PWA5E9TQ59" +destFile="/Library/Application Support/Dialog/Dialog.app" +versionKey="CFBundleShortVersionString" #CFBundleVersion + +currentInstalledVersion="$(defaults read "${destFile}/Contents/Info.plist" $versionKey || true)" +printlog "${name} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion}…" + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +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 diff --git a/MDM/install Installomator direct.sh b/MDM/install Installomator direct.sh index b822e34..ee7fbcf 100755 --- a/MDM/install Installomator direct.sh +++ b/MDM/install Installomator direct.sh @@ -59,7 +59,7 @@ caffexit () { name="Installomator" printlog "$name check for installation" # download URL, version and Expected Team ID -# Method for GitHub pkg +# Method for GitHub pkg with destFile gitusername="Installomator" gitreponame="Installomator" #printlog "$gitusername $gitreponame"