Last active
November 29, 2024 13:36
-
-
Save talkingmoose/84cbe002aca35c73032bccd230d8988a to your computer and use it in GitHub Desktop.
Downloads and installs the latest available VLC software directly on the client. This avoids having to manually download and store an up-to-date installer on a distribution server. Includes an optional checksum for added security.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
:<<ABOUT_THIS_SCRIPT | |
------------------------------------------------------------------------------- | |
Written by:William Smith | |
Professional Services Engineer | |
Jamf | |
[email protected] | |
https://gist.github.com/84cbe002aca35c73032bccd230d8988a | |
Originally posted: February 21, 2020 | |
Updated: June 1, 2021 | |
Purpose: Checks version of latest available version of VLC online and | |
compares with locally installed version. Downloads and installs if | |
installed version is older or doesn't exist. | |
Instructions: | |
1. Set the optional sha256Checksum variable below for stronger | |
security and the preferred architecture of the app. | |
2. If using Jamf Pro, add the script to the Scripts area and set parameter | |
label 4 to "Checksum". | |
3. Add the script to a policy. Optionally, enter the checksum in the | |
Checkum paramter field. | |
4. Enable the policy for Login with a frequency of Once Per Week or other | |
periodic check. | |
5. Enable inventory update, scope and deploy. | |
Except where otherwise noted, this work is licensed under | |
http://creativecommons.org/licenses/by/4.0/ | |
"Deliberate practice by nature, must be hard." | |
------------------------------------------------------------------------------- | |
ABOUT_THIS_SCRIPT | |
# enter the SHA 256 checksum for the download file (DMG) | |
# download the package and run '/usr/bin/shasum -a 256 /path/to/file.dmg' | |
# this will change with each version | |
# leave blank to to skip the checksum verification (less secure) or if using a $4 script parameter with Jamf Pro | |
sha256Checksum="" # e.g. "67b1e8e036c575782b1c9188dd48fa94d9eabcb81947c8632fd4acac7b01644b" | |
if [ "$4" != "" ] && [ "$sha256Checksum" = "" ] | |
then | |
sha256Checksum=$4 | |
fi | |
# choose the most compatible architecture for your environment | |
architecture="universal" # or "arm64" or "intel64" | |
# FILE_LOCATIONS -------------------------------------------------------------- | |
# path to this script | |
currentDirectory=$( /usr/bin/dirname "$0" ) | |
# name of this script | |
currentScript=$( /usr/bin/basename -s .bash "$0" ) | |
# create log file in same directory as script | |
log="/Library/Logs/$currentScript.log" | |
# FUNCTIONS ------------------------------------------------------------------- | |
function logcomment() { | |
/bin/date "+%Y-%m-%d %H:%M:%S $1" >> "$log" | |
echo "$1" | |
} | |
function logresult() { | |
if [ $? = 0 ] ; then | |
/bin/date "+%Y-%m-%d %H:%M:%S $1" >> "$log" | |
else | |
/bin/date "+%Y-%m-%d %H:%M:%S $2" >> "$log" | |
fi | |
} | |
# BEGIN SCRIPT ---------------------------------------------------------------- | |
# define app name and name of DMG after downloading | |
dmgFile="VLC.dmg" | |
appName="VLC.app" | |
# define download url | |
downloadURL="https://download.videolan.org/pub/videolan/vlc/last/macosx/" | |
# get the latest version of software available from website | |
downloadFileName=$( /usr/bin/curl --silent "$downloadURL" | /usr/bin/grep "$architecture" | /usr/bin/awk -F "(>|<)" '/.*.dmg</{ print $3 }' ) | |
logcomment "Latest available download: $downloadFileName" | |
latestVersion=$( /usr/bin/sed -e 's/vlc-//g' -e "s/-$architecture.dmg//g" <<< "$downloadFileName" ) | |
logcomment "Latest version of $appName: $latestVersion" | |
# Get the version number of the currently-installed VLC, if any. | |
if [ -e "/Applications/VLC.app" ]; then | |
installedVersion=$( /usr/bin/defaults read "/Applications/VLC.app/Contents/Info.plist" CFBundleShortVersionString ) | |
echo "Installed version of VLC: $installedVersion" | |
if [ ${latestVersion} = ${installedVersion} ]; then | |
logcomment "VLC is current. Exiting." | |
exit 0 | |
fi | |
else | |
logcomment "VLC is either not installed or not up to date." | |
fi | |
# create temporary working directory | |
workDirectory=$( /usr/bin/basename $0 ) | |
tempDirectory=$( /usr/bin/mktemp -d "/private/tmp/$workDirectory.XXXXXX" ) | |
echo "Creating working directory '$tempDirectory'" | |
# change directory to temporary working directory | |
echo "Changing directory to working directory '$tempDirectory'" | |
cd "$tempDirectory" | |
# downloading software | |
logcomment "Downloading DMG..." | |
/usr/bin/curl --silent --output "$tempDirectory/$dmgFile" "${downloadURL}${downloadFileName}" | |
logresult "Downloaded DMG." "Failed to download DMG." | |
# checksum the download | |
downloadChecksum=$( /usr/bin/shasum -a 256 "$tempDirectory/$dmgFile" | /usr/bin/awk '{ print $1 }' ) | |
echo "Checksum for downloaded file: $downloadChecksum" | |
# install the download if checksum validates | |
if [ "$sha256Checksum" = "$downloadChecksum" ] || [ "$sha256Checksum" = "" ]; then | |
echo "Checksum verified. Installing software..." | |
# mounting DMG | |
logcomment "Mounting DMG..." | |
appVolume=$( /usr/bin/hdiutil attach -nobrowse "$tempDirectory/$dmgFile" | /usr/bin/grep /Volumes | /usr/bin/sed -e 's/^.*\/Volumes\///g' ) | |
logresult "Mounted $appVolume DMG." "Failed to mount $appVolume DMG." | |
# install software | |
logcomment "Installing software..." | |
/usr/bin/ditto -rsrc "/Volumes/$appVolume/$appName" "/Applications/$appName" | |
logresult "Installed software." "Failed to install software." | |
# unmount DMG | |
logcomment "Unmounting DMG..." | |
/sbin/umount "/Volumes/$appVolume" | |
logresult "Unmounting $appVolume DMG." "Failed to unmount $appVolume DMG." | |
else | |
echo "Checksum failed. Recalculate the SHA 256 checksum and try again. Or download may not be valid." | |
exit 1 | |
fi | |
# delete DMG | |
logcomment "Deleting DMG..." | |
/bin/rm -R "$tempDirectory" | |
logresult "Deleted DMG." "Failed to delete DMG." | |
# END SCRIPT ---------------------------------------------------------------- | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, i will have a look in to Installomator, looks like something that could be very useful