diff --git a/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh b/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh index 425a157..24ad8f5 100755 --- a/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh +++ b/MDM/Jamf/00_PrepareInstall_SwiftDialog.sh @@ -47,92 +47,92 @@ fi # swiftDialog installation name="Dialog" -printlog "$name check for installation" +echo "$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" +#echo "$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." + echo "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" +#echo "$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" +#echo "$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" +echo "${name} version: $currentInstalledVersion" if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then - printlog "$name not found or version not latest." - printlog "${destFile}" - printlog "Installing version ${appNewVersion}…" + echo "$name not found or version not latest." + echo "${destFile}" + echo "Installing version ${appNewVersion}…" # Create temporary working directory tmpDir="$(mktemp -d || true)" - printlog "Created working directory '$tmpDir'" + echo "Created working directory '$tmpDir'" # Download the installer package - printlog "Downloading $name package version $appNewVersion from: $downloadURL" + echo "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}" + echo "error downloading $downloadURL, with status $curlDownloadStatus" + echo "${curlDownload}" exitCode=1 else - printlog "Download $name succes." + echo "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" + echo "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'." + echo "$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}" + echo "ERROR. $name package installation failed." + echo "${pkgInstall}" exitCode=2 else - printlog "Installing $name package succes." + echo "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." + echo "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" + echo "$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)" + echo "Sleep a bit before trying download and install again. $installationCount time(s)." + echo "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" sleep 2 fi else - printlog "Download and install of $name succes." + echo "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)" + echo "Deleting working directory '$tmpDir' and its contents." + echo "Remove $(rm -Rfv "${tmpDir}" || true)" # Handle installation errors if [[ $exitCode != 0 ]]; then - printlog "ERROR. Installation of $name failed. Aborting." + echo "ERROR. Installation of $name failed. Aborting." caffexit $exitCode else - printlog "$name version $appNewVersion installed!" + echo "$name version $appNewVersion installed!" fi else - printlog "$name version $appNewVersion already found. Perfect!" + echo "$name version $appNewVersion already found. Perfect!" fi # check for Swift Dialog