v1.1.0 = Resolved issue with patching

AutoCAD patches will not install from command line, only via GUI.  This because they have a script that runs on launch of the .pkg (via GUI) that locates the base .app that needs to be upgraded, and then creates a symlink to that .app in /tmp.

This updated "fixes" this issue with the usual trickery.
This commit is contained in:
Zack T
2021-11-16 09:16:47 -07:00
parent d2f91dbf27
commit 6f61a1f819

View File

@@ -3,7 +3,7 @@
###################################################################################################
# Script Name: update_AutoCAD.sh
# By: Zack Thompson / Created: 4/2/2018
# Version: 1.0 / Updated: 4/2/2018 / By: ZT
# Version: 1.1.0 / Updated: 4/14/2020 / By: ZT
#
# Description: This script will update an AutoCAD install.
#
@@ -15,37 +15,45 @@ echo "***** Update AutoCAD process: START *****"
# Define Variables
# Set working directory
pkgDir=$(/usr/bin/dirname "${0}")
# Get Configuration details...
targetAppName=$(/usr/bin/defaults read "${pkgDir}/VerTarget.plist" TargetAppName)
newVersion=$(/usr/bin/defaults read "${pkgDir}/VerTarget.plist" UpdateVersion)
versionsToPatch=$(/bin/cat "${pkgDir}/VerTarget.plist" | /usr/bin/xmllint --format - | /usr/bin/xpath '/plist/dict/array/string' 2>/dev/null | LANG=C /usr/bin/sed -e 's/<[^/>]*>//g' | LANG=C /usr/bin/sed -e 's/<[^>]*>/\'$'\n/g')
compatible=1
# Find the AutoCAD version being updated...
echo "Searching for ${targetAppName}..."
appPath=$(/usr/bin/find -E /Applications -iregex ".*[/]${targetAppName}[.]app" -type d -prune)
pkgDir=$( /usr/bin/dirname "${0}" )
compatible="false"
if [[ -z "${appPath}" ]]; then
echo "A version of AutoCAD was not found in the expected location!"
echo "***** Update AutoCAD process: FAILED *****"
exit 1
else
# Get the App Bundle name...
appName=$(echo "${appPath}" | /usr/bin/awk -F "/" '{print $NF}')
# Get only the install path...
installPath=$(echo "${appPath}" | /usr/bin/awk -F "/${appName}" '{print $1}')
# Get the Current Version CFBundleVersion...
oldBundleVersion=$(/usr/bin/defaults read "${appPath}/Contents/Info.plist" CFBundleVersion)
fi
# Get the filename of the .pkg file
pkg=$( /bin/ls "${pkgDir}" | /usr/bin/grep .pkg )
# Get Configuration details...
targetAppName=$( /usr/bin/defaults read "${pkgDir}/VerTarget.plist" TargetAppName )
newVersion=$( /usr/bin/defaults read "${pkgDir}/VerTarget.plist" UpdateVersion )
versionsToPatch=$( /bin/cat "${pkgDir}/VerTarget.plist" | /usr/bin/xmllint --format - | /usr/bin/xpath '/plist/dict/array/string' 2>/dev/null | LANG=C /usr/bin/sed -e 's/<[^/>]*>//g' | LANG=C /usr/bin/sed -e 's/<[^>]*>/\'$'\n/g' )
tmp_folder="/private/tmp/_adsk_${newVersion}"
##################################################
# Bits staged...
# Find the AutoCAD version being updated...
echo "Searching for ${targetAppName}..."
appPath=$( /usr/bin/find -E /Applications -iregex ".*[/]${targetAppName}[.]app" -type d -prune )
if [[ -z "${appPath}" ]]; then
echo "Unable to locate an AutoCAD application in the expected location!"
echo "***** Update AutoCAD process: FAILED *****"
exit 1
else
# Get the App Bundle name...
appName=$( echo "${appPath}" | /usr/bin/awk -F "/" '{print $NF}' )
# Get only the install path...
installPath=$( echo "${appPath}" | /usr/bin/awk -F "/${appName}" '{print $1}' )
# Get the Current Version CFBundleVersion...
oldBundleVersion=$( /usr/bin/defaults read "${appPath}/Contents/Info.plist" CFBundleVersion )
fi
# Check if patch version is the current version.
if [[ "${newVersion}" == "${oldBundleVersion}" ]]; then
echo "AutoCAD is already up to date!"
echo "***** Update AutoCAD process: FAILED *****"
exit 2
echo "***** Update AutoCAD process: COMPLETE *****"
exit 0
fi
echo "App Path: ${appPath}"
@@ -56,41 +64,41 @@ echo "Patch Version: ${newVersion}"
while IFS=\n read -r versionPatch; do
if [[ "${versionPatch}" == "${oldBundleVersion}" ]]; then
echo "${newVersion} is a valid patch for: ${oldBundleVersion}"
compatible=0
compatible="true"
fi
done < <(/usr/bin/printf '%s\n' "${versionsToPatch}")
done < <( /usr/bin/printf '%s\n' "${versionsToPatch}" )
# If compatible, install, if not error out.
if [[ $compatible -eq true ]]; then
if [[ $compatible -eq "true" ]]; then
# Silliness that is only performed when running the installer via the GUI
# Credit to @Lincolnep (https://www.jamf.com/jamf-nation/discussions/34668/deploying-autocad-2020-using-script#responseChild199660)
if [[ ! -d "${tmp_folder}" ]]; then
/bin/mkdir -p "${tmp_folder}"
fi
/bin/ln -s "${appPath}" "${tmp_folder}/acupdt_rone"
echo "Installing patch..."
exitStatus=$("${pkgDir}/BinaryDelta" apply "${installPath}" "${pkgDir}/product.delta")
exitStatus=$( /usr/sbin/installer -dumplog -verbose -pkg "${pkgDir}/${pkg}" -target / )
exitCode=$?
else
echo "ERROR: This patch is not compatible with the installed version!"
echo "***** Update AutoCAD process: FAILED *****"
exit 3
exit 2
fi
# Check the exit code.
if [[ $exitCode != 0 ]]; then
# Get the new CFBundleVersion...
newBundleVersion=$( /usr/bin/defaults read "${appPath}/Contents/Info.plist" CFBundleVersion )
# Confirm a successful update
if [[ $exitCode != 0 || "${newVersion}" != "${newBundleVersion}" ]]; then
echo "ERROR: Update failed!"
echo "Exit Code: ${exitCode}"
echo "Exit status was: ${exitStatus}"
echo "***** Update AutoCAD process: FAILED *****"
exit 4
else
# Get the new CFBundleVersion...
newBundleVersion=$(/usr/bin/defaults read "${appPath}/Contents/Info.plist" CFBundleVersion)
# Confirm that the CFBundleVersion is the expected value.
if [[ "${newVersion}" == "${newBundleVersion}" ]]; then
echo "Update complete!"
else
echo "ERROR: Update failed!"
echo "AutoCAD was not properly updated!"
echo "***** Update AutoCAD process: FAILED *****"
exit 5
fi
exit 3
fi
echo "***** Update AutoCAD process: COMPLETE *****"