Skip to content

Instantly share code, notes, and snippets.

@grahampugh
Created February 27, 2017 12:59
Show Gist options
  • Select an option

  • Save grahampugh/2c6fc82d24ca355e8775473de7a595b5 to your computer and use it in GitHub Desktop.

Select an option

Save grahampugh/2c6fc82d24ca355e8775473de7a595b5 to your computer and use it in GitHub Desktop.
Adobe Reader latest "full" install URL provider and downloader/installer
#!/bin/bash
# Adobe Reader installer
# Based on https://github.com/mm2270/CasperSuiteScripts/blob/master/install_Latest_AdobeReader.sh
# Requires a downloaded Adobe Reader DMG
# Proxy if required
#export http_proxy="http://proxy.my.org:2010/"
#export https_proxy=$http_proxy
# Python file that determines the download URL
AdobeReaderURLProvider="./AdobeReaderURLProvider.py"
# Adobe Reader Information file
AdobeReaderInfoFile="/tmp/AdobeReaderDownloadLocation.txt"
## Function section for downloading the latest Flash Player installer and running the installation
function downloadAR () {
# Download latest Adobe Reader DMG to a file in /tmp/
echo "Download URL set to: ${AR_DMG_URL}"
echo "Downloading Adobe Reader DMG..."
## Download the DMG using curl and the URL set
curl -s -f "${AR_DMG_URL}" -o "/tmp/${AR_DMG_DL}"
## Check the exit status of the curl command
if [[ "$?" != "0" ]]; then
echo "Curl operation failed. Site may be blocked or unavailable right now. Exiting with code 1..."
exit 1
fi
## Mount the downloaded disk image and capture the mounted volume name as a variable we can use for the next steps
echo "Silently mounting Adobe Reader Installer disk image..."
ARInstallVol=$( /usr/bin/hdiutil attach "/tmp/${AR_DMG_DL}" -nobrowse -noverify -noautoopen 2>&1 | awk -F'[\t]' '/\/Volumes/{ print $NF }' )
## Check the exit status of the mount operation
if [[ "$?" == "0" ]]; then
## Get the pkg name from the mounted volume
AR_PKG=$( ls "${ARInstallVol}" | grep ".pkg$" )
echo "Silently installing Adobe Reader from pkg..."
## Install the Adobe Reader pkg while reading output from installer
## Check for the successful upgrade line to set the installation status
installStatus=1
while read line; do
echo " $line"
if [[ $( echo "$line" | egrep "The upgrade was successful|The install was successful" ) ]]; then
installStatus=0
fi
done < $(/usr/sbin/installer -pkg "${ARInstallVol}/${AR_PKG}" -tgt / 2>&1)
## Pause 3 seconds to allow installation to finish out
sleep 3
## Now check the installation results
if [[ "$installStatus" == "0" ]]; then
echo "Adobe Reader installation was successful. Checking new version for confirmation..."
## Get the new version number from disk to ensure it matches the expected current version
AR_newVers=$( /usr/bin/defaults read "/Applications/Adobe Reader.app/Contents/Info" CFBundleShortVersionString | tr -dc '0-9')
if [[ "${AR_newVers}" == "${ARCurrVersFull}" ]]; then
echo "Confirmed current version is now ${ARCurrVersFull}..."
exit_status=0
else
echo "New version and latest version do not match. Installation may have failed..."
exit_status=1
fi
else
## If we didn't get a status 0 returned from the installation, exit with an error code
echo "Installation exited with an error code. Install failed..."
exit_status=1
fi
## Clean up (we do this regardless of the installation result so as not to leave downloads around in /tmp/)
echo "Cleaning up. Force ejecting the Adobe Reader install volume..."
/usr/bin/hdiutil eject -force "${ARInstallVol}"
echo "Deleting downloaded disk image..."
rm -rf "/tmp/${AR_DMG_DL}"
exit $exit_status
else
## If mounting the disk image failed, clean up partial/broken download and exit until next run
echo "Could not mount the downloaded disk image. Cleaning up and exiting with status 1..."
rm -rf "/tmp/${AR_DMG_DL}"
exit 1
fi
}
## If running the script locally, call the AdobeReaderURLProvider script. If running from JAMF folder, do not.
if [[ -z $(pwd | grep JAMF) ]]; then
python "${AdobeReaderURLProvider}"
fi
# AdobeReader download location, determined by the python script
AR_DMG_URL=$(head -n 1 "${AdobeReaderInfoFile}")
AR_DMG_DL=$(echo ${AR_DMG_URL} | rev | cut -d/ -f1 | rev)
echo $AR_DMG_URL
echo $AR_DMG_DL
## Get the current release version from Adobe by curling the site as a browser
ARCurrVersFull=$(echo "$AR_DMG_DL" | tr -dc '0-9')
## Get the installed version string
ARVersFullWithDots=$( defaults read /Applications/Adobe\ Reader.app/Contents/Info CFBundleShortVersionString 2> /dev/null )
ARVersFull=$(echo "$ARVersFullWithDots" | tr -dc '0-9')
## Check to see if we got any version returned. If not, set it to "0"
if [[ -z "${ARVersFull}" ]]; then
ARVersFull="0"
fi
## Get the first set of digits from the current version string
ARCurrMajVers=$( echo "${ARCurrVersFull}" | cut -c1-2 )
echo "The Adobe Reader major version number is: $ARCurrMajVers"
## Echo back what we pulled
echo "The Adobe Reader current released version is: $ARCurrVersFull"
echo "The Adobe Reader current installed version on disk is: $ARVersFull"
## Check to see if the version was set to "0" meaning not installed and also if we set the installNew flag and take appropriate next steps
echo "Determining any version difference..."
## Using the normalized version strings, check to see if the installed version is somehow higher than the current public release version.
if [[ "${ARVersFull}" -gt "${ARCurrVersFull}" ]]; then
echo "Installed version, ${ARVersFull} is higher than the current release version, ${ARCurrVersFull}. Exiting..."
exit 0
fi
if [[ "${ARVersFull}" -lt "${ARCurrVersFull}" ]]; then
## Adobe Reader is installed, but is not up to date. Download and install
echo "Adobe Reader is not up to date. Downloading and installing..."
downloadAR
fi
if [[ "${ARVersFull}" == "${ARCurrVersFull}" ]]; then
## Adobe Reader is installed, but matches the current release. Up to date, so exit
echo "Adobe Reader is installed and already up to date. Exiting..."
exit 0
fi
#!/usr/bin/python
#
# This script adapted from the AutoPkg AdobeReaderURLProvider.py
# https://github.com/autopkg/recipes/blob/master/AdobeReader/AdobeReaderURLProvider.py
# Copyright 2010 Per Olofsson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""See docstring for AdobeReaderURLProvider class"""
import json
import urllib2
#from autopkglib import Processor, ProcessorError
__all__ = ["AdobeReaderURLProvider"]
DOWNLOAD_PATH = '/tmp/'
VERSION_INFO_FILE = '/%s/AdobeReaderDownloadLocation.txt' % DOWNLOAD_PATH
AR_BASE_URL = (
"http://get.adobe.com/reader/webservices/json/standalone/"
"?platform_type=Macintosh&platform_dist=OSX&platform_arch=x86-32"
"&platform_misc=%s&language=%s&eventname=readerotherversions")
LANGUAGE_DEFAULT = "English"
MAJOR_VERSION_DEFAULT = "11"
OS_VERSION_DEFAULT = '10.9.0'
MAJOR_VERSION_MATCH_STR = "adobe/reader/mac/%s"
def get_reader_dmg_url(base_url, language, major_version, os_version):
'''Returns download URL for Adobe Reader DMG'''
# Set the proxy if you need one
#proxy = urllib2.ProxyHandler({'http': 'http://proxy.my.org:2010/'})
#opener = urllib2.build_opener(proxy)
#urllib2.install_opener(opener)
request_url = base_url % (os_version, language)
request = urllib2.Request(request_url)
request.add_header("x-requested-with", "XMLHttpRequest")
try:
url_handle = urllib2.urlopen(request)
json_response = url_handle.read()
url_handle.close()
reader_info = json.loads(json_response)
major_version_string = MAJOR_VERSION_MATCH_STR % major_version
matches = [item["download_url"] for item in reader_info
if major_version_string in item["download_url"]]
except BaseException as err:
print "Can't open %s: %s" % (base_url, err)
try:
return matches[0]
except IndexError:
print "Can't find Adobe Reader download URL for %s, version %s" % (language, major_version)
if __name__ == "__main__":
# This section adapted from https://gist.github.com/hughdbrown/c145b8385a2afa6570e2
adobeReaderURL = get_reader_dmg_url(AR_BASE_URL, LANGUAGE_DEFAULT, MAJOR_VERSION_DEFAULT, OS_VERSION_DEFAULT)
# write the URL to a file
f = open( VERSION_INFO_FILE, 'w' )
f.write( str(adobeReaderURL) + '\n' )
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment