#!/bin/bash

# wrap the start of dropbox and download the appropriate package.

ARCH=`arch`
cwd=`pwd`

if [ ! -d $HOME/.dropbox ]; then
	mkdir -p $HOME/.dropbox
fi
if [ ! -d $HOME/.dropbox-dist ]; then
	mkdir -p $HOME/.dropbox-dist
fi
if [ ! -x $HOME/.dropbox-dist/dropbox ]; then
	cd $HOME
	TMP=`mktemp`
	if [ $ARCH -eq "x86_64" ]; then
		PLAT="lnx.x86_64"
	elif [ ${ARCH:2} -eq "86" ]; then
		PLAT="lnx.x86"
	else
		exit
	fi
	wget --output-document=$TMP http://www.dropbox.com/download?plat=$PLAT
	tar xf $TMP
fi
cd $cwd
exec /usr/bin/dropbox.py $@
