v1.2.0 = Updated for changes to the xpath tool

+ Updated for changes to the `xpath` tool
+ Other miscellaneous improvements
This commit is contained in:
Zack T
2021-11-16 09:36:13 -07:00
parent 6f61a1f819
commit a9e66e65e7

View File

@@ -3,7 +3,7 @@
###################################################################################################
# Script Name: update_AutoCAD.sh
# By: Zack Thompson / Created: 4/2/2018
# Version: 1.1.0 / Updated: 4/14/2020 / By: ZT
# Version: 1.2.0 / Updated: 11/15/2021 / By: ZT
#
# Description: This script will update an AutoCAD install.
#
@@ -11,6 +11,17 @@
echo "***** Update AutoCAD process: START *****"
##################################################
# Define Functions
xpath_tool() {
if [[ $( /usr/bin/sw_vers -buildVersion ) > "20A" ]]; then
/usr/bin/xpath -e "$@"
else
/usr/bin/xpath "$@"
fi
}
##################################################
# Define Variables
@@ -24,7 +35,7 @@ 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' )
versionsToPatch=$( /bin/cat "${pkgDir}/VerTarget.plist" | /usr/bin/xmllint --format - | xpath_tool '/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}"
##################################################
@@ -35,16 +46,10 @@ 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 "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
@@ -52,7 +57,7 @@ fi
# Check if patch version is the current version.
if [[ "${newVersion}" == "${oldBundleVersion}" ]]; then
echo "AutoCAD is already up to date!"
echo "***** Update AutoCAD process: COMPLETE *****"
echo "***** Update AutoCAD process: BYPASSED *****"
exit 0
fi
@@ -61,7 +66,7 @@ echo "Current Version: ${oldBundleVersion}"
echo "Patch Version: ${newVersion}"
# Verify that this patch is compatible with this version.
while IFS=\n read -r versionPatch; do
while IFS=$'\n' read -r versionPatch; do
if [[ "${versionPatch}" == "${oldBundleVersion}" ]]; then
echo "${newVersion} is a valid patch for: ${oldBundleVersion}"
compatible="true"
@@ -69,7 +74,7 @@ while IFS=\n read -r versionPatch; do
done < <( /usr/bin/printf '%s\n' "${versionsToPatch}" )
# If compatible, install, if not error out.
if [[ $compatible -eq "true" ]]; then
if [[ "${compatible}" == "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)
@@ -89,16 +94,26 @@ else
exit 2
fi
# Get the new CFBundleVersion...
newBundleVersion=$( /usr/bin/defaults read "${appPath}/Contents/Info.plist" CFBundleVersion )
# Confirm a successful update
if [[ $exitCode != 0 || "${newVersion}" != "${newBundleVersion}" ]]; then
# Check the exit code.
if [[ $exitCode != 0 ]]; then
echo "ERROR: Update failed!"
echo "Exit Code: ${exitCode}"
echo "Exit status was: ${exitStatus}"
echo "***** Update AutoCAD process: FAILED *****"
exit 3
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 4
fi
fi
echo "***** Update AutoCAD process: COMPLETE *****"