-
-
Save talkingmoose/84cbe002aca35c73032bccd230d8988a to your computer and use it in GitHub Desktop.
#!/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 |
@yinghuakang, appears VLC is now offering arm64, intel64 and universal apps in response to Apple Silicon.
I've adjusted the script to account for the additional variants it'll find.
Line 56 is set to download and install the universal version by default. You can change this to one of the other architectures if you wish.
Thanks for the heads up!
@talkingmoose, Thank you so much, it works great! I am just a beginner on mac administration and I really appreciate all your scripts, save me a lot of time.
Great script, only one I've found that still works, and is also the most robust VLC script. +1 for Jamf pointers. Great work.
Hey William, thank you so much for the script so it worked in my environment. I appreciate it.
Hey all, I've been trying to use this script to deploy vlc to our mac's via jamf using the universal .dmg, we have a mix of imac with intel and mac silicon.
trouble is it get's to the mounting DMG and i get a "failed to attach" message appear in the log.
script is verbatim aside the url for the file and the checksum, have i missed something simple or am i going crazy, this is the part of the log from jamf with the error
Script result: Latest available download:
Latest version of VLC Install.app:
VLC is either not installed or not up to date.
Creating working directory '/private/tmp/VLC Install.chyFa5'
Changing directory to working directory '/private/tmp/VLC Install.chyFa5'
Downloading DMG...
Checksum for downloaded file: 5e805ab4dfbb8733302a23309505b02af0ca2a11a59e36b459d672c938a631c0
Checksum verified. Installing software...
Mounting DMG...
hdiutil: attach failed - image not recognised
Installing software...
ditto: Cannot get the real path for source '/Volumes//VLC Install.app'
Unmounting DMG...
umount: /Volumes/: not currently mounted
Deleting DMG...
can anyone help with this please.
thanks
whole script i have here
#!/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" != "182125733ea1c4969927a79d7bee29b3907fd0107ca70294a58292f6847cef2f" ] && [ "$sha256Checksum" = "182125733ea1c4969927a79d7bee29b3907fd0107ca70294a58292f6847cef2f" ]
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-3.0.19-universal.dmg"
appName="VLC Install.app"
define download url
downloadURL="https://get.videolan.org/vlc/3.0.19/macosx/vlc-3.0.19-universal.dmg/"
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
@bobna01 I would use Installomator and use the VLC label instead of this script. Installomator is still being actively developed and maintained, and has more logic built-in.
@bobna01 I would use Installomator and use the VLC label instead of this script. Installomator is still being actively developed and maintained, and has more logic built-in.
thanks, i will have a look in to Installomator, looks like something that could be very useful
Hi William,
The script has been working great but just stopped working with their newest version, thank you for all your hard work.