install Dropbox on a headless Ubuntu 10.04 LTS server

Hello folks,
in this post I would like to show you how easy it is to set up Dropbox on a Ubuntu server only using a ssh connection.

Ok, where to start. Hmm, first of all here is my setup:
I have a MiniITX mainboard with an Intel Atom CPU, 2GB RAM and 160GB HDD running 24/7 (almost ^_^). This system serves my as NAT Router to separate my network from the LAN in the building I am living. I bought it 3-4 years ago and it was really worth its price and by the way, energy consumption is really low (< 15 Watt). This system runs a Ubuntu 10.04 LTS server version and on this system I set up a Dropbox to have access to my account there too.

These sources were helpfull during my approach:
http://1000umbrellas.com/2010/04/30/how-to-install-dropbox-on-a-headless-ubuntu-10-04-server
http://ubuntuservergui.com/ubuntu-server-guide/install-dropbox-ubuntu-server

and basically this post is a mixture of both of them πŸ˜‰

In this post I wanna share the step that are necessary to setup Dropbox on a machine without a keyboard and monitor attached to it, this conditions are called “headless”. Well, we need access to this machine somehow, so I am using my laptop (Ubuntu Linux also) and ssh to connect to my headless machine (that implies that a ssh service/deamon is running there, but as far as I can remember installing a Ubuntu server automatically installs a ssh service).

First of all, you need a Dropbox account. If you don’t have one, get one for free here https://www.dropbox.com/
If you don’t know about Dropbox, check their ad video on their webpage, it explains in pretty easy way what dropbox is and what it does.

Download and setup

Now open a ssh connection to your headless machine:

ssh user@machine

you are asked for your password and then you are connected.Β  Then you need to download the Dropbox client software. I have a 32bit system so I do:

wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86"
 

Having that you need to extract the archive using tar:

tar -xzvf dropbox.tar.gz

that creates a .dropbox-dist folder in the directory you run the command. I recommend to run that directly in your home directory.

For connecting your installation with your Dropbox account you need the system variable “LANG” to be set. Check it with

printenv LANG // what answers "de_DE.UTF-8" in my case

Connect the installation by starting:

.dropbox-dist/dropboxd

what gives you something like this on your terminal:

This client is not linked to any account...
Please visit https://www.dropbox.com/cli_link?host_id=xxxxxxxxxx to link this machine.

Grab this link and paste it in your webbrowser and follow the steps shown. After the commandline shows you a message that says, that the client was successfully connected you can kill the deamon again (Ctrl-C).

Almost finished …

You have now Dropbox on your machine and connected to your account. BUT you just have killed the deamon that is necessary to sync all your files. Hmm one option is to start the deamon everytime you need it by hand

.dropbox-dist/dropboxd

but believe me, that is not what you want. The other option is to create a small script and place it so in your system the dropbox deamon is always started automatically when your system starts, so basically you create a service πŸ˜‰ Create a file in /etc/init.d/:

sudo vim /etc/init.d/dropbox
 

Here is the content necessary for that script:

#!/bin/sh
# dropbox service
# Replace with linux users you want to run Dropbox clients for
DROPBOX_USERS="put your server username here"

DAEMON=.dropbox-dist/dropbox

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

stop() {
  echo "Stopping dropbox..."
  for dbuser in $DROPBOX_USERS; do
    HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
    if [ -x $HOMEDIR/$DAEMON ]; then
      start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$DAEMON
    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

The only thing you need to adjust is the variable “DROPBOX_USERS” in the fourth line, everything else can stay as it is (you may need to pay attention to the intents of each line, bash is somehow a little restrictive about that. Best way: use “Tab” to intent the lines.)

Now you have to make the script executable by:

sudo chmod +x /etc/init.d/dropbox

and add it to the start up application after reboot:

sudo update-rc.d dropbox defaults

Now you can handle this service as every service on a ubuntu machine:

sudo service dropbox {start|stop|reload|force-reload|restart|status}

If it does not react the first time, you may need a reboot, but then you should get something like:

user@bluepill-server:/etc/init.d$ sudo service dropbox status
[sudo] password for user:
dropboxd for USER user: running (pid 2215)

Done !

Great, you have now dropbox running on your headless machine, congratulations πŸ˜‰ wasn’t that hard wasn’t it?

If you are satisfied with your work you can stop here. Otherwise you can read on for a little extra sugar πŸ˜‰

voluntary exercise …

You may have noticed that you can not see whether your headless installation is really working or not. Ok, you can check with “sudo service dropbox status” but you may want to know how fast the sync is done and so on. Mainly the information you get hovering your mouse over the normal desktop icon of dropbox. There is something quite similar to that: you canΒ utilise a python script offered by dropbox. Get it here and change permissions:

wget -O ~/.dropbox/dropbox.py "http://www.dropbox.com/download?dl=packages/dropbox.py"
chmod 755 ~/.dropbox/dropbox.py

By executing

.dropbox/dropbox.py status

you get information what your installation is currently doing. Stating the script without parameter gives you an overview on the available commands.

A nice feature I’ve seen here is “exclude“, with what it seams possible the exclude files form syncing (haven’t tried that so far, but neat πŸ˜‰ )

Enable “lansync” is also a nice feature if you have several machines in a LAN connected data transfer is much faster than syncing only via the dropbox cloud.

So well I wanna make a stop here, say thanks for reading and your interest. In one of the upcoming post I wanna show you some fancy stuff you can to with this installation. So I hope you check back πŸ˜‰
cheers

Advertisements

4 thoughts on “install Dropbox on a headless Ubuntu 10.04 LTS server

  1. correction: you must download dropbox.py in USER’s directory, NOT dropbox-dist folder.

    ~: wget “http://www.dropbox.com/download?dl=packages/dropbox.py”
    ~: chmod 755 dropbox.py

  2. dropbox is extremely helpful. you helped me to find it and so i can use it with best results. thank you for your help

  3. Nice guide! However, it seems like they changed the name of the daemon to “dropboxd” now, so your init.d script needs to be updated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s