#!/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 '.*' \ | tail -1 \ | sed 's#.*##g; s#.*##g;' ` (echo "$NAME: Release Notes: " ; (curl -sfL "${RELEASE_NOTES_URL}" \ | sed '1,//d; /<\/ul>/,$d' \ | sed '1,//d;' \ ; echo '') \ | lynx -dump -nomargins -width=10000 -assume_charset=UTF-8 -pseudo_inlines -stdin ; echo "\nSource: <${RELEASE_NOTES_URL}>" ) | tee "$FILENAME:r.txt" fi echo "$NAME: Downloading '$URL' to '$FILENAME':" curl --continue-at - --fail --location --output "$FILENAME" "$URL" EXIT="$?" ## exit 22 means 'the file was already fully downloaded' [ "$EXIT" != "0" -a "$EXIT" != "22" ] && echo "$NAME: Download of $URL failed (EXIT = $EXIT)" && exit 0 [[ ! -e "$FILENAME" ]] && echo "$NAME: $FILENAME does not exist." && exit 0 [[ ! -s "$FILENAME" ]] && echo "$NAME: $FILENAME is zero bytes." && exit 0 echo "$NAME: Mounting $FILENAME:" MNTPNT=$(hdiutil attach -nobrowse -plist "$FILENAME" 2>/dev/null \ | fgrep -A 1 'mount-point' \ | tail -1 \ | sed 's#.*##g ; s#.*##g') if [[ "$MNTPNT" == "" ]] then echo "$NAME: MNTPNT is empty" exit 1 fi if [[ -e "$INSTALL_TO" ]] then # Quit app, if running pgrep -xq "$INSTALL_TO:t:r" \ && LAUNCH='yes' \ && osascript -e "tell application \"$INSTALL_TO:t:r\" to quit" # move installed version to trash mv -vf "$INSTALL_TO" "$HOME/.Trash/$INSTALL_TO:t:r.${INSTALLED_VERSION}_${INSTALLED_BUILD}.app" fi echo "$NAME: Installing '$MNTPNT/$INSTALL_TO:t' to '$INSTALL_TO': " ditto --noqtn -v "$MNTPNT/$INSTALL_TO:t" "$INSTALL_TO" EXIT="$?" if [[ "$EXIT" == "0" ]] then echo "$NAME: Successfully installed $INSTALL_TO" else echo "$NAME: ditto failed" exit 1 fi echo -n "$NAME: Unmounting $MNTPNT: " && diskutil eject "$MNTPNT" exit 0