#!/usr/bin/env zsh -f
# Purpose: Download and install the latest version of VLC
#
# Author: Timothy J. Luoma
# Email: luomat at gmail dot com
# Date: 2011-10-26, verified 2018-08-07
NAME="$0:t"
INSTALL_TO='/Applications/VLC.app'
HOMEPAGE="http://www.videolan.org/vlc/"
DOWNLOAD_PAGE="http://www.videolan.org/vlc/"
SUMMARY="VLC is a free and open source cross-platform multimedia player and framework that plays most multimedia files as well as DVDs, Audio CDs, VCDs, and various streaming protocols."
if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
fi
if (( $+commands[lynx] ))
then
INFO='lynx'
BASE_URL=$(lynx -listonly -dump -nomargins -nonumbers "https://ftp.osuosl.org/pub/videolan/vlc/" | egrep '/vlc/[0-9]' | tail -1)
LATEST_VERSION="$BASE_URL:t"
URL=$(lynx -listonly -dump -nomargins -nonumbers "${BASE_URL}/macosx/" | egrep '/vlc-.*-universal.dmg$' | tail -1)
FILENAME="$HOME/Downloads/$INSTALL_TO:t:r-${LATEST_VERSION}-universal.dmg"
else
ARCH=$(sysctl kern.version | awk -F'_' '/RELEASE/{print $2}')
if [[ "$ARCH" == "ARM64" ]]
then
# M1 / Apple Silicon / ARM
XML_FEED='https://update.videolan.org/vlc/sparkle/vlc-arm64.xml'
ARCH='arm64'
elif [[ "$ARCH" == "X86" ]]
then
# Intel Mac
XML_FEED='http://update.videolan.org/vlc/sparkle/vlc-intel64.xml'
ARCH='intel'
else
echo "$NAME: 'sysctl kern.version' returned unknown arch: '$ARCH'" >>/dev/stderr
exit 2
fi
# NOTE: XML_FEED does not show 'sparkle:shortVersionString' (they're identical in the app)
INFO=($(curl -sfL "$XML_FEED" \
| tr ' ' '\012' \
| egrep '^(url|sparkle:version)=' \
| tail -2 \
| sort \
| awk -F'"' '//{print $2}'))
LATEST_VERSION="$INFO[1]"
URL="$INFO[2]"
FILENAME="$HOME/Downloads/$INSTALL_TO:t:r-${LATEST_VERSION}-${ARCH}.dmg"
fi # if lynx
if [ "$INFO" = "" -o "$LATEST_VERSION" = "" -o "$URL" = "" ]
then
echo "$NAME: Bad data from $XML_FEED
INFO: $INFO
LATEST_VERSION: $LATEST_VERSION
URL: $URL
"
exit 1
fi
if [[ -e "$INSTALL_TO" ]]
then
INSTALLED_VERSION=`defaults read "$INSTALL_TO/Contents/Info" CFBundleShortVersionString`
if [[ "$LATEST_VERSION" == "$INSTALLED_VERSION" ]]
then
echo "$NAME: Up-To-Date ($INSTALLED_VERSION)"
exit 0
fi
autoload is-at-least
is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
if [ "$?" = "0" ]
then
echo "$NAME: Installed version ($INSTALLED_VERSION) is ahead of official version $LATEST_VERSION"
exit 0
fi
echo "$NAME: Outdated (Installed = $INSTALLED_VERSION vs Latest = $LATEST_VERSION)"
fi
if (( $+commands[lynx] ))
then
RELEASE_NOTES_URL=`curl -sfL "$XML_FEED" \
| egrep '