June 1, 2010
dropbox-latest.sh: Find latest Dropbox beta

I use and love Dropbox and almost always run the latest beta version from the forum. The only problem is that I don’t always check the forum every day so I don’t always know when a new version is available.

This script is designed to check the forums for me and see:

  1. what the latest version is
  2. what my installed version is (Mac only)

If the two are not the same, the script will show me the URL to the forum post which announced the new version, and try to show me the download link for the newest Mac beta.

Notes:

  • requires lynx which is not installed by default on OS X. You can get it at Rudix already compiled and in a nice OS X installer package.
  • this script relies heavily on web scraping which means that it is extremely likely to break in the future if/when Dropbox changes things

Feel free to improve upon it. If you do, please let me know. Any questions, please feel free to ask me.

Short URL for this post: http://luo.ma/dropbox-latest

#!/bin/sh
#
#   Author: Timothy J. Luoma
#   Email:  luomat at gmail dot com
#   Date:   2010-05-28
#
#   Purpose: find the latest Dropbox beta, compare to installed version (Mac only)

# Requires lynx. Download for OS X here:
# http://rudix.org/packages-jkl.html#lynx


# customize if needed
PATH=$HOME/bin:/usr/gnu/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/X11R6/bin:/root/bin:/usr/local/git/bin

# Temp file
TMP=/tmp/latestdropbox.txt

# Dump the source of the page, looking for 'Experimental Forum Build'
# first two lines should produce something like this :
#
#  $ lynx -source http://forums.dropbox.com/|fgrep -i 'Experimental Forum Build'   
#        <td>Sticky: <big><a href="http://forums.dropbox.com/topic.php?id=20472">(5/27) - Experimental Forum Build - 0.8.64</a></big></td>
#
# From there we just want the URL and the build number, so we throw it back into lynx
# which is happy to parse the HTML for us, changing it to something like this:
#
#     Sticky: [1](5/27) - Experimental Forum Build - 0.8.64
#
#
# References
#
#   1. http://forums.dropbox.com/topic.php?id=20472
#
# We really only want the 'experimental' line and the URL, so we egrep those 
# and 'sed' out the bits we don't want
#
# Then we dump the output to a temp file, which should look something like this:
#
# 0.8.64
# http://forums.dropbox.com/topic.php?id=20472
#
# Latest version number on top, URL to download it on the bottom
# 

lynx -source http://forums.dropbox.com/ |\
fgrep -i 'Experimental Forum Build' |\
head -1 |\
lynx -dump -stdin |\
egrep 'Experimental|http://forums.dropbox.com' |\
sed 's#.*Experimental Forum Build - ##g; s#.*http#http#g' > $TMP


if [ ! -s "$TMP" ]
then

    # if the temp file is 0 bytes we know something went wrong, exit

    echo "ERROR: Empty output file ($TMP) which probably means http://forums.dropbox.com/ is not available
    or they changed the format of the post about the latest beta"

    exit 1

fi

# So far everything we've done should work on any "Unix-like" system. 
# And will continue to work as long as Dropbox keeps the same format for their posts on the forum
# which seems fairly likely at least in the short term
# We could end here. (remove the '> $TMP' above and it will go to 'stdout' and voilĂ  


# But if we're on a Mac that has the Dropbox.app already installed, 
# We can compare the currently installed version to the latest version


# Change this if you don't have Dropbox installed in /Applications/

DROPBOX=/Applications/Dropbox.app

# This is where Dropbox keeps version information
PLIST=$DROPBOX/Contents/Info.plist

if [ ! -f "$PLIST" ]
then

    # IF we didn't find the plist file, Dropbox is probably not installed
    # or this isn't a Mac system, so let's just say what we know 
    # by 'cat' ing the tmp file to stdout and exiting

    cat "$TMP"

    exit 0

fi

# Get the version number of the currently installed version of Dropbox
CURRENT=`fgrep -A1 'CFBundleVersion' "$PLIST" |\
fgrep '<string>' |\
sed 's#.*<string>##g ; s#</string>##g'`

# This will equal the latest beta version
LATEST=`head -1 $TMP`

# Now show installed vs latest
echo "$LATEST (latest)
$CURRENT (installed)"


if [ "$CURRENT" != "$LATEST" ]
then

    # if the current is not the latest, 
    # show the URL to get the latest beta

    URL=`tail -1 "$TMP"`

    # Dump the URL looking for a specific link that ends with "dmg"
    DMG=`lynx -dump "$URL" |\
    egrep "http://dl-web.dropbox.com.*dmg" |\
    tail -1 |\
    awk '{print $NF}'`

    echo "
$URL

$DMG"   

fi

exit 0
# EOF

blog comments powered by Disqus