Setup Dropbox in Ubuntu

February 18, 2017
Ubuntu Dropbox

This is taken from Digitalocean and I am storing it here for future reference.

Download the latest version of Dropbox

curl -Lo dropbox-linux-x86_64.tar.gz https://www.dropbox.com/download?plat=lnx.x86_64

Extract Dropbox

sudo mkdir -p /opt/dropbox
sudo tar xzfv dropbox-linux-x86_64.tar.gz --strip 1 -C /opt/dropbox

Link Dropbox to your account

/opt/dropbox/dropboxd

Create a service

sudo vi /etc/init.d/dropbox
#!/bin/sh
### BEGIN INIT INFO
# Provides: dropbox
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: dropbox service
### END INIT INFO

[ -f /etc/default/dropbox ] && . /etc/default/dropbox
mkdir -p /var/run/dropbox
DAEMON=/opt/dropbox/dropboxd

start() {
    echo "Starting dropbox..."
    for dbuser in $DROPBOX_USERS; do
        HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
        if [ -x $DAEMON ]; then
            echo "Starting dropbox for $dbuser"
            HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -u $dbuser -x $DAEMON -p $HOMEDIR/.dropbox/dropbox.pid
        fi
    done
}

stop() {
    echo "Stopping dropbox..."
    for dbuser in $DROPBOX_USERS; do
        HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
        if [ -x $DAEMON ]; then
            echo "Stopping dropbox for $dbuser"
            start-stop-daemon -o -c $dbuser -K -u $dbuser -p $HOMEDIR/.dropbox/dropbox.pid
        fi
    done
}

status() {
    for dbuser in $DROPBOX_USERS; do
        dbpid=`pgrep -u $dbuser dropbox`
        if [ -z $dbpid ] ; then
            echo "dropboxd for USER $dbuser: not running."
        else
            echo "dropboxd for USER $dbuser: running (pid $dbpid)"
        fi
    done
}

case "$1" in

    start)
        start
        ;;

    stop)
        stop
        ;;

    restart|reload|force-reload)
        stop
        start
        ;;

    status)
        status
        ;;

    *)
        echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
        exit 1

esac

exit 0

Add the users

sudo vi /etc/default/dropbox
DROPBOX_USERS="user1 user2"

Start the service and setup it up to start on boot

sudo chmod +x /etc/init.d/dropbox
sudo update-rc.d dropbox defaults
sudo service dropbox start
cd ~
curl -LO https://www.dropbox.com/download?dl=packages/dropbox.py
chmod +x ~/dropbox.py
ln -s /opt/dropbox ~/.dropbox-dist
~/dropbox.py